質問

WordPressでは、デフォルトの投稿ステータス:公開、ドラフト、保留中のレビューを取得します。アクティブなテーマのfunction.phpファイルを介してそれらを登録して、さらに投稿タイプを追加することは可能ですか?

また、Publish Meta BoxのLableを編集することは可能ですか?私が提出しているのは本当に出版されていません...

また、カスタム投稿タイプで作成したときにこれらの変更を加えたいだけです。

敬具

スコット

役に立ちましたか?

解決

WP 3.0以降、Register_Post_Status()関数を使用できます() http://hitchhackerguide.com/2011/02/12/register_post_status/ )投稿タイプに新しいステータスを追加します。

WP自体は、register_post_status()を使用して、wp-includes/post.phpでcreate_initial_post_types()関数を使用して、default "published"、 "draft"などを登録します。 http://hitchhackerguide.com/2011/02/11/create_initial_post_types/ ).

これらのリンクのコードを見てください。機能の使用方法を理解できます。

それがあなたが始めるのに役立つことを願っています!

他のヒント

方法を知っていれば、プラグインを書くことができます。このようなドキュメントまたは同様のプラグインを掘り下げる必要があります http://wordpress.org/extend/plugins/edit-flow/ またはこれ http://wordpress.org/extend/plugins/custom-post-type-ui/

「フック、アクション、フィルター」を使用すると、管理インターフェイスを変更できます。こちらをご覧ください http://codex.wordpress.org/plugin_api

これまでのところ、私は1つの簡単なプラグインだけを書きましたが、これを達成するためにあなたが従わなければならない正確な手順がわかりません...

幸運を!

Register_Post_Status関数を使用して、カスタム投稿ステータスを追加できます。 create_initial_post_types()inを参照してください http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php

ただし、これはWordPressバックエンド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);
    }

}

そしてここ 使い方 それ

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

編集: コードのタイプミスを修正しました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top