Domanda

In Wordpress si ottiene gli stati post-default: Pubblicato, Progetto e attesa di revisione. E 'possibile aggiungere alcuni tipi di più post via registrarli tramite il file function.php del tema attivo?

Inoltre è possibile modificare le etichette della Pubblica Meta Box? Quello che sto presentando davvero isnt Editoria ...

Inoltre, come per aggiungere voglio solo queste le modifiche apportate, quando nel mio tipo messaggio personalizzato che ho fatto.

Cordiali saluti

Scott

È stato utile?

Soluzione

Dal WP 3.0, è possibile utilizzare la funzione register_post_status () ( http: // hitchhackerguide. com / 2011/02/12 / register_post_status / ) per aggiungere nuovi stati a un tipo palo.

WP stesso utilizza register_post_status () per registrare il default "pubblicato", "bozza", ecc stati sulla init utilizzando i create_initial_post_types () in wp-includes / post.php ( http://hitchhackerguide.com/2011/02/11/create_initial_post_types/ ).

guardare il codice di tali collegamenti, e si può avere un'idea di come utilizzare la funzione.

Mi auguro che aiuta a iniziare!

Altri suggerimenti

Si potrebbe scrivere un plugin se si sa come. Bisogna scavare documentazione o simili plugin come questo http://wordpress.org/extend / plugins / edit-flow / o questa http: // wordpress.org/extend/plugins/custom-post-type-ui/

Con "Ganci, Azioni e filtri" è possibile modificare l'interfaccia di amministrazione, vedi qui http: //codex.wordpress .org / Plugin_API

Finora ho solo una scrittura semplice plugin e non so esattamente i passi che si devono seguire per raggiungere questo obiettivo ...

In bocca al lupo!

È possibile aggiungere lo stato personalizzato messaggio utilizzando la funzione register_post_status. Fare riferimento a create_initial_post_types () in http: // nucleo .trac.wordpress.org / browser / tags / 3.2.1 / wp-includes / post.php

Essere avvertito tuttavia, che questo non è integrata nel back-end Wordpress interfaccia utente.

/**
 * 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);
    }

}

E qui come utilizzare è

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>'),
        )
    ));
});

Modifica:. errore di battitura fisso in codice

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top