Pregunta

En Wordpress que consigue el poste estados predeterminados: Publicado, Borrador y pendiente de revisión. ¿Es posible añadir algunos tipos más correos a través de registrarlos a través del archivo function.php del tema activo?

También es posible editar los lables de la Meta Publicar caja? Lo que estoy presentando realmente tampoco Publicaciones ...

También como para agregar sólo quiero realizan estos cambios, cuando en mi tipo de envío personalizado que he hecho.

Saludos cordiales

Scott

¿Fue útil?

Solución

Since WP 3.0, you can use the register_post_status() function ( http://hitchhackerguide.com/2011/02/12/register_post_status/ ) to add new statuses to a post type.

WP itself uses register_post_status() to register the default "published", "draft", etc. statuses on init using the create_initial_post_types() function in wp-includes/post.php ( http://hitchhackerguide.com/2011/02/11/create_initial_post_types/ ).

Look at the code in those links, and you can get an idea of how to use the function.

I hope that helps you get started!

Otros consejos

You could write a plugin if you know how. You have to dig into the documentation or similar plugins like this one http://wordpress.org/extend/plugins/edit-flow/ or this one http://wordpress.org/extend/plugins/custom-post-type-ui/

With "Hooks, Actions and Filters" you can change the admin interface, see here http://codex.wordpress.org/Plugin_API

So far I've write just one simple plugin and I don't know the exact steps you have to follow to accomplish this...

Good luck!

You can add custom post status' using the register_post_status function. Refer to create_initial_post_types() in http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php

Be warned however, that this is not integrated into the Wordpress backend UI.

/**
 * PostStatusExtender
 * 
 * @author Hyyan Abo Fakher<hyyanaf@gmail.com>
 */
class PostStatusExtender
{

    /**
     * Extend 
     * 
     * Extend the current status list for the given post type 
     * 
     * @global \WP_POST $post
     * 
     * @param string $postType the post type name , ex: product
     * @param array $states array of states where key is the id(state id) and value
     *                      is the state array 
     */
    public static function extend($postType, $states)
    {

        foreach ($states as $id => $state) {
            register_post_status($id, $state);
        }

        add_action('admin_footer-post.php', function() use($postType, $states) {

            global $post;
            if (!$post || $post->post_type !== $postType) {
                return false;
            }

            foreach ($states as $id => $state) {

                printf(
                        '<script>'
                        . 'jQuery(document).ready(function($){'
                        . '   $("select#post_status").append("<option value=\"%s\" %s>%s</option>");'
                        . '   $("a.save-post-status").on("click",function(e){'
                        . '      e.preventDefault();'
                        . '      var value = $("select#post_status").val();'
                        . '      $("select#post_status").value = value;'
                        . '      $("select#post_status option").removeAttr("selected", true);'
                        . '      $("select#post_status option[value=\'"+value+"\']").attr("selected", true)'
                        . '    });'
                        . '});'
                        . '</script>'
                        , $id
                        , $post->post_status !== $id ? '' : 'selected=\"selected\"'
                        , $state['label']
                );

                if ($post->post_status === $id) {
                    printf(
                            '<script>'
                            . 'jQuery(document).ready(function($){'
                            . '   $(".misc-pub-section #post-status-display").text("%s");'
                            . '});'
                            . '</script>'
                            , $state['label']
                    );
                }
            }
        });


        add_action('admin_footer-edit.php', function() use($states, $postType) {

            global $post;

            if (!$post || $post->post_type !== $postType) {
                return false;
            }

            foreach ($states as $id => $state) {
                printf(
                        '<script>'
                        . 'jQuery(document).ready(function($){'
                        . " $('select[name=\"_status\"]' ).append( '<option value=\"%s\">%s</option>' );"
                        . '});'
                        . '</script>'
                        , $id
                        , $state['label']
                );
            }
        });

        add_filter('display_post_states', function($states, $post) use($states, $postType) {

            foreach ($states as $id => $state) {
                if ($post->post_type == $postType && $post->post_status === $id) {
                    return array($state['label']);
                } else {
                    if (array_key_exists($id, $states)) {
                        unset($states[$id]);
                    }
                }
            }

            return $states;
        }, 10, 2);
    }

}

And here how to use it

add_action('init', function() {
    PostStatusExtender::extend(self::NAME, array(
        'sold' => array(
            'label' => __('Sold', 'viasit'),
            'public' => true,
            'exclude_from_search' => true,
            'show_in_admin_all_list' => true,
            'show_in_admin_status_list' => true,
            'label_count' => _n_noop('Sold <span class="count">(%s)</span>', 'Sold <span class="count">(%s)</span>'),
        )
    ));
});

Edit: fixed typo in code.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top