| @@ -103,9 +103,9 @@ | ||
| 103 | 103 | $hook = add_submenu_page( |
| 104 | 104 | $this->base_slug, |
| 105 | 105 | $title, |
| 106 | 106 | $label, |
| 107 | - code_snippets()->get_cap(), | |
| 107 | + $this->menu_cap(), | |
| 108 | 108 | $slug, |
| 109 | 109 | array( $this, 'render' ) |
| 110 | 110 | ); |
| 111 | 111 | |
| @@ -112,8 +112,21 @@ | ||
| 112 | 112 | add_action( 'load-' . $hook, array( $this, 'load' ) ); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | + * Capability required to access this menu. | |
| 117 | + * | |
| 118 | + * Defaults to the snippet access capability. Subclasses such as the | |
| 119 | + * settings menu override this to require the core admin capability so they | |
| 120 | + * remain accessible only to full administrators. | |
| 121 | + * | |
| 122 | + * @return string | |
| 123 | + */ | |
| 124 | + protected function menu_cap(): string { | |
| 125 | + return code_snippets()->get_cap(); | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 116 | 129 | * Register the admin menu |
| 117 | 130 | */ |
| 118 | 131 | public function register() { |
| 119 | 132 | $this->add_menu( $this->slug, $this->label, $this->title ); |
| @@ -154,9 +167,9 @@ | ||
| 154 | 167 | * Executed when the admin page is loaded |
| 155 | 168 | */ |
| 156 | 169 | public function load() { |
| 157 | 170 | // Make sure the user has permission to be here. |
| 158 | - if ( ! current_user_can( code_snippets()->get_cap() ) ) { | |
| 171 | + if ( ! current_user_can( $this->menu_cap() ) ) { | |
| 159 | 172 | wp_die( esc_html__( 'You are not authorized to access this page.', 'code-snippets' ) ); |
| 160 | 173 | } |
| 161 | 174 | |
| 162 | 175 | // Create the snippet tables if they are missing. |