WordPressを読む 93-3 /blog/wp-admin/includes/plugin.php 3
/blog/wp-admin/includes/plugin.php 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | // // Menu // /** * Add a top level menu page * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * @param string $icon_url The url to the icon to be used for this menu. * * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme. * This should begin with 'data:image/svg+xml;base64,'. * * Pass the name of a Dashicons helper class to use a font icon, e.g. 'dashicons-chart-pie'. * * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS. * @param int $position The position in the menu order this one should appear * * @return string The resulting page's hook_suffix */ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) { global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages; $menu_slug = plugin_basename( $menu_slug ); $admin_page_hooks[$menu_slug] = sanitize_title( $menu_title ); $hookname = get_plugin_page_hookname( $menu_slug, '' ); if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) ) add_action( $hookname, $function ); if ( empty($icon_url) ) { $icon_url = 'dashicons-admin-generic'; $icon_class = 'menu-icon-generic '; } else { $icon_url = set_url_scheme( $icon_url ); $icon_class = ''; } $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $icon_class . $hookname, $hookname, $icon_url ); if ( null === $position ) $menu[] = $new_menu; else $menu[$position] = $new_menu; $_registered_pages[$hookname] = true; // No parent as top level $_parent_pages[$menu_slug] = false; return $hookname; } /** * Add a top level menu page in the 'objects' section * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * @param string $icon_url The url to the icon to be used for this menu * * @return string The resulting page's hook_suffix */ function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { global $_wp_last_object_menu; $_wp_last_object_menu++; return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_object_menu); } /** * Add a top level menu page in the 'utility' section * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * @param string $icon_url The url to the icon to be used for this menu * * @return string The resulting page's hook_suffix */ function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { global $_wp_last_utility_menu; $_wp_last_utility_menu++; return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_utility_menu); } /** * Add a sub menu page * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $parent_slug The slug name for the parent menu (or the file name of a standard WordPress admin page) * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { global $submenu; global $menu; global $_wp_real_parent_file; global $_wp_submenu_nopriv; global $_registered_pages; global $_parent_pages; $menu_slug = plugin_basename( $menu_slug ); $parent_slug = plugin_basename( $parent_slug); if ( isset( $_wp_real_parent_file[$parent_slug] ) ) $parent_slug = $_wp_real_parent_file[$parent_slug]; if ( !current_user_can( $capability ) ) { $_wp_submenu_nopriv[$parent_slug][$menu_slug] = true; return false; } /* * If the parent doesn't already have a submenu, add a link to the parent * as the first item in the submenu. If the submenu file is the same as the * parent file someone is trying to link back to the parent manually. In * this case, don't automatically add a link back to avoid duplication. */ if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) { foreach ( (array)$menu as $parent_menu ) { if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) $submenu[$parent_slug][] = array_slice( $parent_menu, 0, 4 ); } } $submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title ); $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug); if (!empty ( $function ) && !empty ( $hookname )) add_action( $hookname, $function ); $_registered_pages[$hookname] = true; /* * Backward-compatibility for plugins using add_management page. * See wp-admin/admin.php for redirect from edit.php to tools.php */ if ( 'tools.php' == $parent_slug ) $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true; // No parent as top level. $_parent_pages[$menu_slug] = $parent_slug; return $hookname; } /** * Add sub menu page to the tools main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the options main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the themes main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the plugins main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the Users/Profile main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { if ( current_user_can('edit_users') ) $parent = 'users.php'; else $parent = 'profile.php'; return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the Dashboard main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the posts main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the media main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the links main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the pages main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the comments main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Remove a top level admin menu * * @since 3.1.0 * * @param string $menu_slug The slug of the menu * @return array|bool The removed menu on success, False if not found */ function remove_menu_page( $menu_slug ) { global $menu; foreach ( $menu as $i => $item ) { if ( $menu_slug == $item[2] ) { unset( $menu[$i] ); return $item; } } return false; } /** * Remove an admin submenu * * @since 3.1.0 * * @param string $menu_slug The slug for the parent menu * @param string $submenu_slug The slug of the submenu * @return array|bool The removed submenu on success, False if not found */ function remove_submenu_page( $menu_slug, $submenu_slug ) { global $submenu; if ( !isset( $submenu[$menu_slug] ) ) return false; foreach ( $submenu[$menu_slug] as $i => $item ) { if ( $submenu_slug == $item[2] ) { unset( $submenu[$menu_slug][$i] ); return $item; } } return false; } /** * Get the url to access a particular menu page based on the slug it was registered with. * * If the slug hasn't been registered properly no url will be returned * * @since 3.0.0 * * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param bool $echo Whether or not to echo the url - default is true * @return string the url */ function menu_page_url($menu_slug, $echo = true) { global $_parent_pages; if ( isset( $_parent_pages[$menu_slug] ) ) { $parent_slug = $_parent_pages[$menu_slug]; if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) { $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) ); } else { $url = admin_url( 'admin.php?page=' . $menu_slug ); } } else { $url = ''; } $url = esc_url($url); if ( $echo ) echo $url; return $url; } |