Pages added to admin menu are restricted for anyone except of admins
-
I had to add a page to the admin part via
add_management_page( 'Vertr?ge anzeigen', 'Vertr?ge anzeigen', 'edit_posts', 'show_contracts', 'gr_show_contracts' );
This page should be accessible for editors. Unfortunately it is only visible for admin. If an editor tries to access that page, he get’s an error message “Cannot load show_contracts”.
Reason: Plugin Restrict Content by Role hardcodes allowed capabilities in line 43 of class module class.AdminAccess.php:
if( is_admin() && ! current_user_can( 'manage_options' ) ) { … }
Changing the capabilities above to “edit_post” solves the problem.
But: this should be done in the child theme and this does not work.
I tried the following in my functions.php:
function gr_admin_access() { if (class_exists( 'mkdo\restrict_content_by_role\AdminAccess' )) { get_template_part('gr-admin-access'); $gr_admin_access = new GR_AdminAccess; } } add_action('init', 'gr_admin_access');
and in gr-admin-access.php:
<?php use mkdo\restrict_content_by_role\AdminAccess; class GR_AdminAccess extends AdminAccess { public function run() { remove_action( 'admin_init', array( '\mkdo\restrict_content_by_role\AdminAccess', 'get_excluded_posts' ) ); add_action( 'admin_init', array( $this, 'get_excluded_posts' ) ); } /** * Check if user has access */ public function get_excluded_posts() { if( is_admin() && ! current_user_can( 'edit_posts' ) ) { ... } ... }
The new class is invoked, but I still get the error “Cannot load …” whereas if I change that line in the original class, it works.
What am I doing wrong? Any help would me very much appreciated.
- The topic ‘Pages added to admin menu are restricted for anyone except of admins’ is closed to new replies.