Skip to main content

Khi bàn giao website cho khách hàng, bạn chắc sẽ muốn ẩn bớt các menu trong trang admin của khách. Có nhiều plugins hỗ trợ việc này cơ mà cài nhiều đâm nặng site.

Dưới đây là đoạn snippets giúp ẩn từng menu trong admin theo ý bạn.

<?php
/**
* Hide Admin Menu Items from the admin menu for everyone but admin-user
*/
function remove_admin_menus()
{
    // provide a list of usernames who can edit custom field definitions here
    $admins = array( 
        'put admin user name here', 
    );
    // get the current user
    $current_user = wp_get_current_user();
    // match and remove if needed
    if( !in_array( $current_user->user_login, $admins ) )
    {
        remove_menu_page('edit.php?post_type=acf');     //Advanced Custom Fields  
        remove_menu_page( 'edit.php' );                 //Posts
        remove_menu_page( 'edit-comments.php' );       //Comments
        remove_menu_page( 'themes.php' );              //Appearance
        remove_menu_page( 'tools.php' );               //Tools
        remove_menu_page( 'options-general.php' );     //Settings
        remove_menu_page( 'plugins.php' );             //Plugins
        remove_menu_page('wpseo_dashboard');
        remove_menu_page( 'index.php' );               //Dashboard
        remove_menu_page( 'users.php' );               //Users

        // Remove some submenu
        remove_submenu_page('ninja-forms', 'nf-system-status');
        remove_submenu_page('ninja-forms', 'nf-settings');
        remove_submenu_page('ninja-forms', 'nf-import-export');
        remove_submenu_page('ninja-forms', 'ninja-forms#apps');
        remove_submenu_page('ninja-forms', 'nf-submissions');
    }
}
add_action( 'admin_menu', 'remove_admin_menus', 999 );
//* Additional Function To Remove Genesis Menu link
//remove_theme_support( 'genesis-admin-menu' ); 

Bạn nhớ thêm 1 tài khoản superadmin vào mảng $admins nhé!

Nguồn: Bryant Web Design

------Brings to you with ♥️ by vietnamtutor.com
Việt Nam Tutor

Xin chào, tôi là Anthony Nguyễn, một lập trình viên Full Stack với nhiều năm kinh nghiệm trong ngành công nghệ thông tin. Tôi tận dụng kiến thức và kỹ năng của mình để tạo ra các giải pháp công nghệ đột phá và đáp ứng những bài toán thách thức, phức tạp.Tôi luôn sẵn sàng để kết nối và học hỏi từ cộng đồng, cũng như chia sẻ những kiến thức và thông tin hữu ích. Với tôi, việc xây dựng kiến thức là như xây dựng một tòa nhà - cần có sự kiên nhẫn, kiến thức vững chắc, và sự cống hiến để tạo nên sự thành công.Nếu bạn có câu hỏi, ý kiến, hoặc muốn kết nối với tôi để thảo luận về công nghệ, đừng ngần ngại liên hệ tôi. Rất mong được nhận gạch đá từ các bạn!

Leave a Reply