Skip to content

Instantly share code, notes, and snippets.

@horike37
Last active August 29, 2015 13:57
Show Gist options
  • Save horike37/9885058 to your computer and use it in GitHub Desktop.
Save horike37/9885058 to your computer and use it in GitHub Desktop.
WordPressで管理画面に独自に追加したページに表示オプションを追加する
<?php
add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu() {
global $my_plugin_page;
$my_plugin_page = add_options_page('My Plugin Options', 'My Plugin', 'Administrator', __FILE__, 'my_plugin_options');
add_action("load-$my_plugin_page", my_screen_options);
}
function my_screen_options() {
global $my_plugin_page;
$screen = get_current_screen();
if(!is_object($screen) || $screen->id != $my_plugin_page)
return;
$args = array(
'label' => __('Per Page'),
'default' => 20,
'option' => 'my_plugin_per_page'
);
add_screen_option( 'per_page', $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment