Quantcast
Channel: Word Press – zamuu::BLOG
Viewing all articles
Browse latest Browse all 34

WordPress管理画面 ロールによって『公開』ボタンを制御

$
0
0

WordPress管理画面の『公開』『更新』ボタンを制御する方法を記載します。、例として『1度公開した記事については、『更新』ボタンを表示しない』場合です。


/*----------------------------------------------------*/
/* 【管理画面】編集者・寄稿者は公開ページ「更新」ボタン非表示
/*----------------------------------------------------*/
add_action('admin_print_styles', 'admin_preview_css_custom');
function admin_preview_css_custom() {
global $post;

$ID = $post->ID;

if(empty($ID))return ; // update post
   $post = get_post($ID); // 現POST情報

// 「公開中」した記事には「更新」ボタンを表示させない
   if($post->post_status == 'publish'){
     echo '<style>input#publish {display: none;}</style>';
   }
 }

admin_print_styles のアクションフィルタは管理画面のStyle設置時のフィルターのようです。これで1度公開した記事は更新できなくなります。。。管理者以外に適用する場合は、管理者かどうか判断して適用してください。


global $current_user; // 現在のユーザ

$is_admin = in_array('administrator', $current_user->roles);

関連記事


Viewing all articles
Browse latest Browse all 34

Trending Articles