ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: admin-menu

admin-menu

ํ”Œ๋Ÿฌ๊ทธ์ธ์— ์˜ํ•ด ์‚ฝ์ž… ๋œ ๊ด€๋ฆฌ์ž ๋ฉ”๋‰ด ํŽ˜์ด์ง€๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๋ฐฉ๋ฒ•?

๊ด€๋ฆฌ์ž ์˜์—ญ ๋‚ด์—์„œ ์‚ฌ์šฉ๋˜์ง€ ์•Š์„ ๋งŽ์€ ๊ฒƒ๋“ค์„ ์ •๋ฆฌํ•˜๋Š” ๋‹ค์Œ ์ฝ”๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

add_action( 'admin_menu', 'my_remove_menu_pages' );

function my_remove_menu_pages() {
  remove_menu_page( 'edit.php' );                   //Posts
  remove_menu_page( 'upload.php' );                 //Media
  remove_menu_page( 'edit-comments.php' );          //Comments
  remove_menu_page( 'themes.php' );                 //Appearance
  remove_menu_page( 'users.php' );                  //Users
  remove_menu_page( 'tools.php' );                  //Tools
  remove_menu_page( 'options-general.php' );        //Settings

};

๊ทธ๋Ÿฌ๋‚˜ ํ”Œ๋Ÿฌ๊ทธ์ธ์—์„œ ์‚ฝ์ž… ๋œ ๋‘ ๊ฐœ์˜ ๋ฉ”๋‰ด ํ•ญ๋ชฉ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐ ๋ฉ”๋‰ด ํ•ญ๋ชฉ ์œ„๋กœ ๋งˆ์šฐ์Šค๋ฅผ ๊ฐ€์ ธ ๊ฐ€๋ฉด ๋งํฌ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

/wp-admin/edit.php?post_type=acf
/wp-admin/admin.php?page=wpcf7

์ด ๋ฉ”๋‰ด ํŽ˜์ด์ง€๋ฅผ ์ˆจ๊ธฐ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๊นŒ?



๋‹ต๋ณ€

์˜ฌ๋ฐ”๋ฅธ ํ›„ํฌ (URL / ์Šฌ๋Ÿฌ๊ทธ์™€ ํ•ญ์ƒ ๋™์ผํ•˜์ง€๋Š” ์•Š์Œ)๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•˜๋ฉฐ ๋‚˜์ค‘์— ์‹คํ–‰๋˜๋Š” ํ›„ํฌ (์˜ˆ :)๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ๋ฌธ์ œ๊ฐ€๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค admin_init.

add_action( 'admin_init', 'wpse_136058_remove_menu_pages' );

function wpse_136058_remove_menu_pages() {

    remove_menu_page( 'edit.php?post_type=acf' );
    remove_menu_page( 'wpcf7' );
}

๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋””๋ฒ„๊น… ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

add_action( 'admin_init', 'wpse_136058_debug_admin_menu' );

function wpse_136058_debug_admin_menu() {

    echo '<pre>' . print_r( $GLOBALS[ 'menu' ], TRUE) . '</pre>';
}

Contact Form 7 ํ”Œ๋Ÿฌ๊ทธ์ธ ๋ฉ”๋‰ด ํŽ˜์ด์ง€์— ๋Œ€ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

[27] => Array
        (
            [0] => Formular
            [1] => wpcf7_read_contact_forms
            [2] => wpcf7
            [3] => Contact Form 7
            [4] => menu-top menu-icon-generic toplevel_page_wpcf7 menu-top-last
            [5] => toplevel_page_wpcf7
            [6] => none
        )

ํ‚ค 2๊ฐ€์žˆ๋Š” ๋ฐฐ์—ด ์š”์†Œ ๋Š” ๋‹น์‹ ์ด ์ฐพ๊ณ ์žˆ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค : wpcf7.


๋‹ต๋ณ€

    // PLUGINS THAT ADD AS DASHBOARD SUBMENU
    // IF THIS IS THE URL BELOW - THE PAGE VARIABLE IS WHAT I NEED ( SO WHATEVER COMES AFTER PAGE= )
    // http://example.com/wp-admin/index.php?page=iconize-plugin-update-notifier
    remove_submenu_page( 'index.php', 'iconize-plugin-update-notifier' );

    // OR FOR EXAMPLE WOOCOMMERCE DASHBOARD SUBMENU
    remove_submenu_page( 'index.php', 'wc-about' ); //WOO
    remove_submenu_page( 'index.php', 'wc-credits' ); //WOO
    remove_submenu_page( 'index.php', 'wc-translators' ); //WOO

    // CUSTOM POST TYPE TOP LEVELS
    remove_menu_page( 'edit.php?post_type={$POST_TYPE}' ); //LOOK FOR WHAT COMES AFTER POST TYPE IN THE URL
    remove_menu_page( 'edit.php?post_type=testimonials-widget' ); //TESTIMONIALS WIDGET
    remove_menu_page( 'edit.php?post_type=product' ); //WOOCOMMERCE

    // CUSTOM POST TYPE SUBMENU
     remove_submenu_page( 'edit.php?post_type={$POST_TYPE}', '{$SUBMENU_URL_VARIABLE}' ); //EXAMPLE FORMAT
     // SO IF BELOW IS THE URL
     // http://example.com/wp-admin/edit.php?post_type=testimonials-widget&page=testimonialswidget_settings
     // YOU NEED TO SEE WHATS AFTER PAGE
     remove_submenu_page( 'edit.php?post_type=testimonials-widget', 'testimonialswidget_settings' ); //TESTIMONIALS WIDGET

    // OTHER EXAMPLES
    remove_menu_page( 'revslider' ); // REVSLIDER
    remove_menu_page( 'woocommerce' ); // WOOCOMMERCE
    remove_menu_page( 'order-post-types-shop_order' ); // WOOCOMMERCE
    remove_menu_page( 'order-post-types-shop_coupons' ); // WOOCOMMERCE
    remove_menu_page( 'shortcodes-ultimate' ); // SHORTCODES ULTIMATE
    remove_menu_page( 'wp-admin-microblog/wp-admin-microblog.php' ); // ADMIN MICROBLOG
    remove_menu_page( 'snippets' ); //CODE SNIPPETS
    remove_menu_page( 'gf_edit_forms' ); // GRAVITY FORMS
        remove_submenu_page( 'gf_edit_forms', 'gf_settings' ); // GRAVITY FORMS
        remove_submenu_page( 'gf_edit_forms', 'gf_export' ); // GRAVITY FORMS
        remove_submenu_page( 'gf_edit_forms', 'gf_update' ); // GRAVITY FORMS
        remove_submenu_page( 'gf_edit_forms', 'gf_addons' ); // GRAVITY FORMS
        remove_submenu_page( 'gf_edit_forms', 'gf_help' ); // GRAVITY FORMS

        remove_submenu_page( 'cleverness-to-do-list', 'cleverness-to-do-list-settings' ); //Cleverness TODO

๋‹น์‹ ์€ ๋‹น์‹ ์ด ํ•„์š”๋กœํ•˜๋Š” ๋ชจ๋“  ์ •๋ณด๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ํ•จ๊ป˜์ด ๋ชจ๋“  ๊ฒƒ์„ ๋””๋ฒ„๊น… ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :

if (!function_exists('debug_admin_menus')):
function debug_admin_menus() {
if ( !is_admin())
        return;
    global $submenu, $menu, $pagenow;
    if ( current_user_can('manage_options') ) { // ONLY DO THIS FOR ADMIN
        if( $pagenow == 'index.php' ) {  // PRINTS ON DASHBOARD
            echo '<pre>'; print_r( $menu ); echo '</pre>'; // TOP LEVEL MENUS
            echo '<pre>'; print_r( $submenu ); echo '</pre>'; // SUBMENUS
        }
    }
}
add_action( 'admin_notices', 'debug_admin_menus' );
endif;

ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์›Œ๋“œ ํ”„๋ ˆ์Šค ์ „์—ญ ์œผ๋กœ์ด ๋ชจ๋“  ์ž‘์—…์„ ์ˆ˜ํ–‰ ํ•  ์ˆ˜์žˆ๋Š” ๋ฐฐ์—ด ๊ฐ’์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค (๊ถŒ์žฅํ•˜์ง€๋Š” ์•Š์ง€๋งŒ)

function remove_submenus_all_please() {
if ( !is_admin())
        return;
  global $submenu;
    unset($submenu['index.php'][10]); // Removes Updates
  //Posts menu
 // unset($submenu['edit.php'][5]); // Leads to listing of available posts to edit
 // unset($submenu['edit.php'][10]); // Add new post
 // unset($submenu['edit.php'][15]); // Remove categories
 // unset($submenu['edit.php'][16]); // Removes Post Tags
}
add_action('admin_menu', 'remove_submenus_all_please', 999);

๋˜ํ•œ ํŠน์ • ์‚ฌ์šฉ์ž๋ฅผ ์ œ๊ฑฐํ•˜๋ ค๋ฉด ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€ ๋œ ๊ฒฝ์šฐ๋ฅผ ์ œ์™ธํ•˜๊ณ  ๋™์ผํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์‹ญ์‹œ์˜ค.

function remove_by_caps_admin_menu() {
if ( !is_admin())
        return;
    if ( !current_user_can('manage_options') ) {
        remove_menu_page( 'revslider' ); // REVSLIDER
    } elseif ( !current_user_can('edit_posts') ) {
        remove_menu_page( 'woocommerce' ); // WOO
    } else {
    }
}
add_action('admin_menu', 'remove_by_caps_admin_menu', 999);

์™œ ์šฐ๋ฆฌ์˜ ๊ทœ๋ฒ”์„ ๋ฐํžˆ์ง€ ์•Š๋Š”๊ฐ€? remove_submenu_page๋ฅผ 50 ๋ฒˆ ์“ฐ๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํˆด๋ฐ” ๋…ธ๋“œ์—์„œ๋„ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

if ( !function_exists( 'remove_admin_menupages_in_array' ) ) {
function remove_admin_menupages_in_array() {
    if ( !is_admin())
        return;
          $admin_menus = array(
                                'revslider',
                                'woocommerce',
                                'shortcodes-ultimate',
          );

    foreach ( $admin_menus as $menu_page ) {
        if ( !current_user_can('manage_options') ) {
            remove_menu_page( $menu_page );
        }
    } // foreach
 } // function
add_action('admin_menu', 'remove_admin_menupages_in_array', 9999);
} // exists

๋‹ต๋ณ€

add_action ์šฐ์„  ์ˆœ์œ„ ๋ฅผ ๋” ๋†’์€ ์ˆ˜๋กœ ์„ค์ •ํ•˜๊ณ  ๋‘ ๊ฐœ์˜ ์ƒˆ ๋งํฌ๋ฅผ ๊ตฌ์ฒด์ ์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํƒ€๊ฒŸํŒ…ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

add_action( 'admin_menu', 'my_remove_menu_pages', 999 );

function my_remove_menu_pages() {
  remove_menu_page( 'edit.php' );                   //Posts
  remove_menu_page( 'upload.php' );                 //Media
  remove_menu_page( 'edit-comments.php' );          //Comments
  remove_menu_page( 'themes.php' );                 //Appearance
  remove_menu_page( 'users.php' );                  //Users
  remove_menu_page( 'tools.php' );                  //Tools
  remove_menu_page( 'options-general.php' );        //Settings
  remove_menu_page( 'edit.php?post_type=acf' );
  remove_menu_page( 'wpcf7' );
};

๊ณ ๊ธ‰ ์‚ฌ์šฉ์ž ์ •์˜ ํ•„๋“œ๋Š” ๋ฉ”๋‰ด์—์„œ์ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๋„์›€๋ง ๋ฌธ์„œ๋„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

http://www.advancedcustomfields.com/resources/how-to/how-to-hide-acf-menu-from-clients/

Contact Form 7์—๋Š” ๋ฉ”๋‰ด์˜ ๊ฐ€์‹œ์„ฑ์„ ์ œํ•œํ•˜๋Š” ์ž์ฒด ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

http://contactform7.com/restricting-access-to-the-administration-panel/


๋‹ต๋ณ€

์ตœ์‹  ์ •๋ณด

๋‚ด๊ฐ€ ์ฝ”๋“œ ์กฐ๊ฐ์„ ๋งŒ๋“ค์–ด ๋”์šฑ ๊ฐ•๋ ฅํ•œ ๊ธฐ๋Šฅ์ด ๋ฉ”์ธ ๋ฉ”๋‰ด์™€ ํ•˜์œ„ ๋ฉ”๋‰ด ํ•ญ๋ชฉ์„ ๋ชจ๋‘ ๋‹ค๋ฃฌ๋‹ค.

์›๋ž˜ ๋‹ต๋ณ€

์ œ๊ฑฐํ•˜๋ ค๋Š” ๋ฉ”๋‰ด๋ฅผ ์ง€์ •ํ•˜๋Š” ๋Œ€์‹  ์œ ์ง€ํ•˜๋ ค๋Š” ๋ฉ”๋‰ด๋ฅผ ์ง€์ •ํ•˜์‹ญ์‹œ์˜ค. ๐Ÿ™‚

add_action('admin_init', 'nwcm_admin_init');

function nwcm_admin_init()
{
    // Remove unnecessary menus 
    $menus_to_stay = array(
        // Client manager
        'nwcm',

        // Dashboard
        'index.php',

        // Users
        'users.php'
    );
    foreach ($GLOBALS['menu'] as $key => $value) {
        if (!in_array($value[2], $menus_to_stay)) remove_menu_page($value[2]);
    }

} 

์ด๋Ÿฐ ์‹์œผ๋กœ ์ƒˆ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ถ”๊ฐ€ ํ•  ๋•Œ ํ”Œ๋Ÿฌ๊ทธ์ธ ์ด๋ฆ„์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.


๋‹ต๋ณ€

์˜ฌ๋ฐ”๋ฅธ $ menu_slug๋ฅผ ์ฐพ์•„์•ผํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์ฝ”๋“œ๋Š” ์ €์—๊ฒŒ ํšจ๊ณผ์ ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

add_action( 'admin_init', 'remove_menus' );
function remove_menus(){
  remove_menu_page( 'wpcf7' );
}

๋‹ต๋ณ€

๋ฌผ๋ก  ์ œ๊ฑฐํ•˜๋ ค๋Š” ํ•ญ๋ชฉ ๋งŒ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด์‹ญ์‹œ์˜ค.

/wordpress/wp-content/plugins/your_plugin/your_plugin.php :


add_action('admin_init', 'nwcm_admin_init');

function nwcm_admin_init()
{
// Remove unnecessary menus 
$menus_to_remove = array(
    // menu items you want to remove
    'menu_item_1',
    'menu_item_2',
    .
    .
    'menu_item_n'
);

// To avoid warning message, check whether 'menu' is set AND is an array
if(isset($GLOBALS['menu']) && is_array($GLOBALS['menu'])) {
   foreach ($GLOBALS['menu'] as $key => $value) {
     //Remove the '!' in the 'if' condition.        
     if (in_array($value[2], $menus_to_remove)) remove_menu_page($value[2]);
   }
}

} 

์ด๊ฒƒ์€ numediaweb์˜ ๋ฐฉ๋ฒ•์˜ ๋‹จ์ ์ž…๋‹ˆ๋‹ค. @numediaweb ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ž˜ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

์ถ”์‹  : โ€˜menu_item_1 / nโ€™-> ๋ฉ”๋‰ด ํ•ญ๋ชฉ ์œ„์— ๋งˆ์šฐ์Šค๋ฅผ ๋†“๊ณ  ๋งํฌ์— ํ‘œ์‹œ๋œ ํ•ด๋‹น ๋ฉ”๋‰ด ํ•ญ๋ชฉ์˜ ์ •ํ™•ํ•œ ํŽ˜์ด์ง€๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.


๋‹ต๋ณ€

์ด ์ฝ”๋“œ ์Šค ๋‹ˆํŽซ์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค

function your_custom_name() {
    remove_menu_page('vc-general'); //the slug as seen wp-admin.php?page=vc-general  
}
add_action( 'admin_init', 'your_custom_name' );