【问题标题】:Wordpress User Role AccessibilitiesWordpress 用户角色可访问性
【发布时间】:2020-12-14 01:19:26
【问题描述】:

在wordpress中,如何创建一个只能访问“捐赠”侧边栏功能的新用户角色,如下图所示?请帮忙...View Image

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    是的,是的,可以这样做。 您需要在 WordPress 后台“帐户”->“所有帐户”-> 选择用户并更改其状态。

    那么你必须在你的子主题中添加这些 PHP 指令

    add_action( 'current_screen', 'restrict_screen' );
    
     function restrict_screen() {
        if (current_user_can('give_accountant')) {
                   if( preg_match('/\bindex\.php\b|\bprofile\.php\b|\bwp-admin.?$/', $_SERVER['REQUEST_URI'])) {
                    $current_admin = get_admin_url() .'edit.php?post_type=give_forms';
                    header('Location: ' . $current_admin . '', true, 301);
                    }
            }
     }
    
    add_action('admin_init', 'disable_dashboard');
    function disable_dashboard() {
        if (!is_user_logged_in()) {
            return null;
        }
            
        if (current_user_can('give_accountant')) {
             remove_menu_page( 'index.php' );
             remove_menu_page( 'profile.php' );
        }
    }
    

    【讨论】:

      【解决方案2】:

      对于用户角色功能,您还可以使用插件。 在这里我分享了我喜欢的插件。 https://wordpress.org/plugins/user-role-editor/

      我知道它有点长,但它是一个非常好的插件,如果将来需求发生任何变化,那么该插件将非常有用。

      您可以在此处根据您的要求进行设置。

      【讨论】:

        猜你喜欢
        • 2020-09-07
        • 2021-08-10
        • 2019-03-28
        • 2018-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-18
        • 1970-01-01
        相关资源
        最近更新 更多