PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | php/Admin/Menus/Admin_Menu.php +15 -2 3.10.24.0.0-beta.2 View file →
@@ -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.