向编辑者显示WordPress插件菜单(管理员)

时间:2015-10-04 作者:Darpan Kulkarni

我是wordpress网站的管理员,我创建了一个具有编辑角色的用户,我安装了一个插件漂亮的链接(https://wordpress.org/plugins/pretty-link/) 此插件在管理页面上显示其菜单,但不在编辑器页面上显示。

我想在编辑器页面上也显示这个菜单选项,那么怎么做呢?我在其他菜单中使用以下代码:

if ( ! function_exists( \'toplevel_admin_menu_pages\' ) ) {
function toplevel_admin_menu_pages(){
    if ( !current_user_can(\'administrator\') ) {             // If the user is not the administrator remove and add new menus
        remove_menu_page( \'edit.php\' );                     // Posts
        remove_menu_page( \'edit.php?post_type=page\' );      // Pages
        remove_menu_page( \'upload.php\' );                   // Media
        remove_menu_page( \'tools.php\' );                    // Contact From 7
        add_menu_page( \'Home\', \'Home\', \'edit_posts\', \'post.php?post=8&action=edit\', \'\', \'dashicons-admin-home\', 25 );
        add_menu_page( \'Life Insurance\', \'Life Insurance\', \'edit_posts\', \'post.php?post=31&action=edit\', \'\', \'dashicons-id-alt\', 26 );
        add_menu_page( \'Income Protection\', \'Income Protection\', \'edit_posts\', \'post.php?post=40&action=edit\', \'\', \'dashicons-lock\', 27 );
        add_menu_page( \'Superannuation\', \'Superannuation\', \'edit_posts\', \'post.php?post=43&action=edit\', \'\', \'dashicons-search\', 28 );
        // add_menu_page( \'Home Loan\', \'Home Loan\', \'edit_posts\', \'post.php?post=47&action=edit\', \'\', \'dashicons-building\', 29 );
        add_menu_page( \'About us\', \'About Us\', \'edit_posts\', \'post.php?post=50&action=edit\', \'\', \'dashicons-universal-access-alt\', 30 );
        add_menu_page( \'Contact us\', \'Contact Us\', \'edit_posts\', \'post.php?post=55&action=edit\', \'\', \'dashicons-email-alt\', 31 );
        add_menu_page( \'Settings\', \'Settings\', \'edit_posts\', \'post.php?post=16&action=edit\', \'\', \'dashicons-admin-generic\', 32 );
                add_menu_page( \'Pretty Links\', \'Pretty Links\', \'edit_posts\', \'post.php?post=16&action=edit\', \'\', \'dashicons-admin-generic\', 32 );
        }
    }
    add_action( \'admin_menu\', \'toplevel_admin_menu_pages\' );
}

2 个回复
SO网友:Bryan Willis

Check these links below. 这是为您的pretty link插件管理菜单设置权限的地方:

pretty-link/prli-main.php -> line 16 - it\'s set to administrator you want edit_posts

pretty-link/prli-main.php -> line 160 - it\'s set to $current_user->user_level >= 8 you want $current_user->user_level >= 7



What are your options?


OPTION 1 - Change the code

转到此确切链接(示例应为您的网站名称)并更改administratoredit_posts:

http://example.com/wp-admin/plugin-editor.php?file=pretty-link/prli-main.php&a=te&scrollto=265

<转到此确切链接并更改if($current_user->user_level >= 8)if($current_user->user_level >= 7)

http://example.com/wp-admin/plugin-editor.php?file=pretty-link/prli-main.php&a=te&scrollto=2933

<保存更改
OPTION 2 - Override the code

将以下内容添加到functions.php 添加管理菜单。如果您也需要仪表板小部件,而他们没有访问权限,只需对prli_add_dashboard_widgets 功能也一样。

remove_action(\'admin_menu\', \'prli_menu\');
add_action(\'admin_menu\', \'prli_menu_new\', 99999);

function prli_menu_new()
{
  global $prli_options, $prlipro_options;

  $role = \'edit_posts\';
  if(isset($prlipro_options->min_role))
    $role = $prlipro_options->min_role;

  $prli_menu_hook = add_menu_page( __(\'Pretty Link | Manage Pretty Links\', \'pretty-link\'), __(\'Pretty Link\', \'pretty-link\'), $role, \'pretty-link\', \'PrliLinksController::route\', PRLI_IMAGES_URL.\'/pretty-link-small.png\' );
  $prli_add_links_menu_hook = add_submenu_page( \'pretty-link\', __(\'Pretty Link | Add New Link\', \'pretty-link\'), __(\'Add New Link\', \'pretty-link\'), $role, \'add-new-pretty-link\', \'PrliLinksController::new_link\' );
  add_submenu_page(\'pretty-link\', \'Pretty Link | Groups\', \'Groups\', $role, PRLI_PATH.\'/prli-groups.php\');

  if( isset($prli_options->extended_tracking) and $prli_options->extended_tracking != "count" )
    add_submenu_page(\'pretty-link\', \'Pretty Link | Hits\', \'Hits\', $role, PRLI_PATH.\'/prli-clicks.php\');

  add_submenu_page(\'pretty-link\', \'Pretty Link | Tools\', \'Tools\', $role, PRLI_PATH.\'/prli-tools.php\');
  add_submenu_page(\'pretty-link\', \'Pretty Link | Options\', \'Options\', $role, PRLI_PATH.\'/prli-options.php\');

  add_action(\'admin_head-pretty-link/prli-clicks.php\', \'prli_reports_admin_header\');
  add_action(\'admin_print_scripts-\' . $prli_menu_hook, \'PrliLinksController::load_scripts\');
  add_action(\'admin_print_scripts-\' . $prli_add_links_menu_hook, \'PrliLinksController::load_scripts\');
  add_action(\'admin_head-pretty-link/prli-groups.php\', \'prli_groups_admin_header\');
  add_action(\'admin_head-pretty-link/prli-options.php\', \'prli_options_admin_header\');

  add_action(\'admin_print_styles-\' . $prli_menu_hook, \'PrliLinksController::load_styles\');
  add_action(\'admin_print_styles-\' . $prli_add_links_menu_hook, \'PrliLinksController::load_styles\');

  add_action(\'admin_head-\' . $prli_menu_hook, \'PrliLinksController::load_dynamic_scripts\', 100);
}

Option 3: You can also add these on an individual basis if you don\'t need to give them access to everything. For example:

add_action( \'admin_menu\', \'pretty_links_override_action_edit_posts_role\', 99999 );

function pretty_links_override_action_edit_posts_role() {
           $role = \'edit_posts\';
           // remove them first
           remove_menu_page( \'pretty-link\');
           remove_submenu_page(\'pretty-link\', \'add-new-pretty-link\');

           add_menu_page( __(\'Pretty Link | Manage Pretty Links\', \'pretty-link\'), __(\'Pretty Link\', \'pretty-link\'), $role, \'pretty-link\', \'PrliLinksController::route\', PRLI_IMAGES_URL.\'/pretty-link-small.png\' );  
           add_submenu_page( \'pretty-link\', __(\'Pretty Link | Add New Link\', \'pretty-link\'), __(\'Add New Link\', \'pretty-link\'), $role, \'add-new-pretty-link\', \'PrliLinksController::new_link\' );

}

Option 4: A plugin

尝试安装admin menu editoradmin ui customize


Option 5: Premium

付费购买支持此功能的高级版本


Option 6: Hack premium options

硬代码$prlipro_options. 虽然这对我来说最有意义,但在这里添加可能不合适,因为我会和插件作者发生冲突。

SO网友:dswebsme

此插件的免费版本似乎不支持动态角色分配。只有访问级别为8以上的用户才允许管理漂亮的链接。

您可以在整个插件中找到以下代码:

$current_user->user_level >= 8
如果您修改插件并将8改为7,那么您的编辑器应该可以立即访问该插件。根据我在源代码中看到的情况,可能需要更改的位置不到20个,但最重要的是在prli main中。php(第159行附近)。

此外,您可以联系开发人员,要求他们改进插件的角色分配功能,但这可能需要升级到PRO版本。开发人员会给您最好的建议。