新規追加ボタンの非表示
新規追加ボタンは、admin_enqueue_scriptsフックポイントで、CSSを出力して非表示にする方法で実装します。
function hide_post_new_button( $hook ) {
if ( $hook === 'edit.php' || $hook === 'post.php' ){
echo '';
}
}
add_action( 'admin_enqueue_scripts', 'hide_post_new_button' );編集・クイック編集・ゴミ箱へ移動・表示の項目を非表示
続いて、投稿情報(行)のカスタマイズ。これはpost_row_actionsというフィルターフックで、編集・クイック編集・ゴミ箱へ移動・表示の各項目を引数で取得できるので非表示にしたい要素をunset()で配列から削除します。そしてそれをreturnします。
function hide_row_post( $actions, $post ) {
unset( $actions['edit'] ); // 編集
unset( $actions['inline hide-if-no-js'] ); // クイック編集
unset( $actions['trash'] ); // ゴミ箱へ移動
unset( $actions['view'] ); // 表示
return $actions;
}
add_filter( 'post_row_actions', 'hide_row_post', 10, 2 );できた!\(^o^)/
第二引数の$postで、WP_Postのインスタンが取得できるので、特定のIDやユーザーなどの時に非表示なんていうのもできるな。便利。
参考サイト
- Developer Resources: admin_enqueue_scripts
- https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/
- Developer Resources: post_row_actions
- https://developer.wordpress.org/reference/hooks/post_row_actions/


