Ticket #37526: 37526.2.diff
File 37526.2.diff, 13.0 KB (added by , 9 years ago) |
---|
-
src/wp-admin/admin-header.php
33 33 get_admin_page_title(); 34 34 $title = esc_html( strip_tags( $title ) ); 35 35 36 if ( is_network_admin() ) 37 $admin_title = sprintf( __( 'Network Admin: %s' ), esc_html( get_current_site()->site_name ) ); 38 elseif ( is_user_admin() ) 39 $admin_title = sprintf( __( 'User Dashboard: %s' ), esc_html( get_current_site()->site_name ) ); 40 else 36 $_panel = get_administration_panel( '', true ); 37 if ( $_panel && ! empty( $_panel->admin_title ) ) { 38 $admin_title = $_panel->admin_title; 39 } else { 41 40 $admin_title = get_bloginfo( 'name' ); 41 } 42 42 43 43 if ( $admin_title == $title ) 44 44 $admin_title = sprintf( __( '%1$s — WordPress' ), $title ); … … 227 227 228 228 $current_screen->render_screen_meta(); 229 229 230 if ( is_network_admin()) {230 if ( $_panel ) { 231 231 /** 232 * Prints network admin screen notices.232 * Prints admin screen notices for a specific Admin. 233 233 * 234 * @since 3.1.0 235 */ 236 do_action( 'network_admin_notices' ); 237 } elseif ( is_user_admin() ) { 238 /** 239 * Prints user admin screen notices. 234 * The dynamic portion of the hook name, `$panel_name`, refers to the Administration Panel name. 240 235 * 241 236 * @since 3.1.0 237 * @since 4.7.0 Hook is now dynamic. 242 238 */ 243 do_action( 'user_admin_notices' );239 do_action( $_panel->name . '_admin_notices' ); 244 240 } else { 245 241 /** 246 242 * Prints admin screen notices. … … 250 246 do_action( 'admin_notices' ); 251 247 } 252 248 249 unset( $_panel ); 250 253 251 /** 254 252 * Prints generic admin screen notices. 255 253 * -
src/wp-admin/admin.php
83 83 84 84 auth_redirect(); 85 85 86 // Register the additional administration panels. 87 $site_name = function_exists( 'get_current_site' ) ? get_current_site()->site_name : get_bloginfo( 'name' ); 88 89 register_administration_panel( 'network', array( 90 'constant_name' => 'WP_NETWORK_ADMIN', 91 'check_callback' => 'is_network_admin', 92 'url_callback' => 'network_admin_url', 93 'menu_file' => ABSPATH . 'wp-admin/network/menu.php', 94 'admin_title' => sprintf( __( 'Network Admin: %s' ), esc_html( $site_name ) ), 95 ) ); 96 97 register_administration_panel( 'user', array( 98 'constant_name' => 'WP_USER_ADMIN', 99 'check_callback' => 'is_user_admin', 100 'url_callback' => 'user_admin_url', 101 'menu_file' => ABSPATH . 'wp-admin/user/menu.php', 102 'admin_title' => sprintf( __( 'User Dashboard: %s' ), esc_html( $site_name ) ), 103 ) ); 104 105 unset( $site_name ); 106 107 /** 108 * Fires before an admin screen or script is being initialized. 109 * 110 * Note, this does not just run on user-facing admin screens. 111 * It runs on admin-ajax.php and admin-post.php as well. 112 * 113 * @since 4.7.0 114 */ 115 do_action( 'admin_setup' ); 116 86 117 // Schedule trash collection 87 118 if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() ) 88 119 wp_schedule_event(time(), 'daily', 'wp_scheduled_delete'); … … 130 161 else 131 162 $taxnow = ''; 132 163 133 if ( WP_NETWORK_ADMIN ) 134 require(ABSPATH . 'wp-admin/network/menu.php'); 135 elseif ( WP_USER_ADMIN ) 136 require(ABSPATH . 'wp-admin/user/menu.php'); 137 else 164 $_panel = get_administration_panel(); 165 if ( $_panel ) { 166 require( $_panel->menu_file ); 167 } else { 138 168 require(ABSPATH . 'wp-admin/menu.php'); 169 } 170 unset( $_panel ); 139 171 140 172 if ( current_user_can( 'manage_options' ) ) { 141 173 wp_raise_memory_limit( 'admin' ); -
src/wp-admin/includes/class-wp-screen.php
243 243 } 244 244 245 245 if ( ! $post_type && $hook_name ) { 246 if ( '-network' == substr( $id, -8 ) ) { 247 $id = substr( $id, 0, -8 ); 248 $in_admin = 'network'; 249 } elseif ( '-user' == substr( $id, -5 ) ) { 250 $id = substr( $id, 0, -5 ); 251 $in_admin = 'user'; 246 foreach ( get_administration_panels() as $panel ) { 247 $length = -1 - strlen( $panel->name ); 248 if ( '-' . $panel->name == substr( $id, $length ) ) { 249 $id = substr( $id, 0, $length ); 250 $in_admin = $panel->name; 251 break; 252 } 252 253 } 253 254 254 255 $id = sanitize_key( $id ); … … 266 267 if ( ! $in_admin ) 267 268 $in_admin = 'site'; 268 269 } else { 269 if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) 270 $in_admin = 'network'; 271 elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) 272 $in_admin = 'user'; 273 else 270 $panel = get_administration_panel(); 271 if ( $panel ) { 272 $in_admin = $panel->name; 273 } else { 274 274 $in_admin = 'site'; 275 } 275 276 } 276 277 277 278 if ( 'index' == $id ) … … 337 338 break; 338 339 } 339 340 340 if ( 'network' == $in_admin) {341 $id .= '-network';342 $base .= '-network';343 } elseif ( 'user' == $in_admin ) {344 $id .= '-user';345 $base .= '-user';341 foreach ( get_administration_panels() as $panel ) { 342 if ( $panel->name == $in_admin ) { 343 $id .= '-' . $panel->name; 344 $base .= '-' . $panel->name; 345 break; 346 } 346 347 } 347 348 348 349 if ( isset( self::$_registry[ $id ] ) ) { -
src/wp-admin/includes/menu.php
6 6 * @subpackage Administration 7 7 */ 8 8 9 if ( is_network_admin() ) { 9 $_panel = get_administration_panel( '', true ); 10 if ( $_panel ) { 10 11 11 12 /** 12 * Fires before the administration menu loads in the NetworkAdmin.13 * Fires before the administration menu loads in a specific Admin. 13 14 * 14 15 * The hook fires before menus and sub-menus are removed based on user privileges. 15 16 * 16 * @private 17 * @since 3.1.0 18 */ 19 do_action( '_network_admin_menu' ); 20 } elseif ( is_user_admin() ) { 21 22 /** 23 * Fires before the administration menu loads in the User Admin. 17 * The dynamic portion of the hook name, `$panel_name`, refers to the Administration Panel name. 24 18 * 25 * The hook fires before menus and sub-menus are removed based on user privileges.26 *27 19 * @private 28 20 * @since 3.1.0 21 * @since 4.7.0 Hook is now dynamic. 29 22 */ 30 do_action( '_ user_admin_menu' );23 do_action( '_' . $_panel->name . '_admin_menu' ); 31 24 } else { 32 25 33 26 /** … … 117 110 } 118 111 unset($id, $data, $subs, $first_sub, $old_parent, $new_parent); 119 112 120 if ( is_network_admin()) {113 if ( $_panel ) { 121 114 122 115 /** 123 * Fires before the administration menu loads in the NetworkAdmin.116 * Fires before the administration menu loads in a specific Admin. 124 117 * 125 * @since 3.1.0118 * The dynamic portion of the hook name, `$panel_name`, refers to the Administration Panel name. 126 119 * 127 * @param string $context Empty context. 128 */ 129 do_action( 'network_admin_menu', '' ); 130 } elseif ( is_user_admin() ) { 131 132 /** 133 * Fires before the administration menu loads in the User Admin. 134 * 120 * @private 135 121 * @since 3.1.0 122 * @since 4.7.0 Hook is now dynamic. 136 123 * 137 124 * @param string $context Empty context. 138 125 */ 139 do_action( 'user_admin_menu', '' );126 do_action( $_panel->name . '_admin_menu', '' ); 140 127 } else { 141 128 142 129 /** … … 149 136 do_action( 'admin_menu', '' ); 150 137 } 151 138 139 unset( $_panel ); 140 152 141 /* 153 142 * Remove menus that have no accessible submenus and require privileges 154 143 * that the user does not have. Run re-parent loop again. -
src/wp-admin/includes/misc.php
936 936 </script> 937 937 <?php 938 938 } 939 940 /** 941 * Register an administration panel. Use this function on admin_setup. 942 * 943 * A function to register a custom administration panel from a plugin. WordPress also 944 * uses it to register the 'network' and 'user' administration panels. 945 * 946 * @since 4.7.0 947 * @global array $_wp_administration_panels Contains the administration panels. 948 * 949 * @param string $post_status Name of the administration panel. Must not contain dashes. 950 * @param array|string $args { 951 * Array or string of administration panel arguments. 952 * 953 * @type string $constant_name Required. Name of the constant to check for whether we're currently 954 * in that administration panel. 955 * @type callable $check_callback Required. A callback function that can be used to check whether we're 956 * currently in that administration panel. 957 * @type callable $url_callback Required. A callback function to return the URL to the administration 958 * panel. The function must accept two parameters, `$path` and `$scheme` 959 * and return the full URL to the administration panel for that path. 960 * @type string $menu_file Required. The filename of the PHP file to include to setup the menu 961 * for the administration panel. 962 * @type string $admin_title Optional. Title to use in the title tag. 963 * } 964 * @return object|WP_Error The administration panel object on success, an error object otherwise. 965 */ 966 function register_administration_panel( $name, $args ) { 967 global $_wp_administration_panels; 968 969 if ( ! isset( $_wp_administration_panels ) ) { 970 $_wp_administration_panels = array(); 971 } 972 973 // 'site' represents the default administration panel, so it is not explicitly registered, but still forbidden. 974 if ( 'site' === $name ) { 975 return new WP_Error( 'admin_panel_already_exist', sprintf( __( 'The administration panel %s already exists.' ), 'site' ) ); 976 } 977 978 // It is not allowed to override an existing administration panel. 979 if ( isset( $_wp_administration_panels[ $name ] ) ) { 980 return new WP_Error( 'admin_panel_already_exist', sprintf( __( 'The administration panel %s already exists.' ), $name ) ); 981 } 982 983 $defaults = array( 984 'constant_name' => '', 985 'check_callback' => null, 986 'url_callback' => null, 987 'menu_file' => '', 988 'admin_title' => '', 989 ); 990 991 $args = wp_parse_args( $args, $defaults ); 992 993 $required = array( 'constant_name', 'check_callback', 'url_callback', 'menu_file' ); 994 995 foreach ( $required as $key ) { 996 if ( empty( $args[ $key ] ) ) { 997 return new WP_Error( 'empty_panel_argument', sprintf( __( 'The administration panel argument %s must not be empty.' ), $key ) ); 998 } 999 } 1000 1001 $args['name'] = $name; 1002 1003 $panel = (object) $args; 1004 1005 $_wp_administration_panels[ $name ] = $panel; 1006 1007 return $panel; 1008 } 1009 1010 /** 1011 * Returns the administration panels. 1012 * 1013 * @since 4.7.0 1014 * @global array $_wp_administration_panels Contains the administration panels. 1015 * 1016 * @return array Array of administration panel objects. 1017 */ 1018 function get_administration_panels() { 1019 global $_wp_administration_panels; 1020 1021 if ( ! isset( $_wp_administration_panels ) ) { 1022 return array(); 1023 } 1024 1025 return $_wp_administration_panels; 1026 } 1027 1028 /** 1029 * Returns an administration panel object. 1030 * 1031 * If $name is not provided, it returns the current administration panel. 1032 * 1033 * @since 4.7.0 1034 * @global array $_wp_administration_panels Contains the administration panels. 1035 * 1036 * @param string $name Optional. Name of the administration panel. Defaults to the current 1037 * administration panel. 1038 * @param bool $detect_via_callback Optional. Whether to detect the current panel via the callback function 1039 * instead of checking for the constant. Only used if $name is not provided. 1040 * Default false. 1041 * @return object|null Administration panel object or null if not found. 1042 */ 1043 function get_administration_panel( $name = '', $detect_via_callback = false ) { 1044 global $_wp_administration_panels; 1045 1046 if ( ! isset( $_wp_administration_panels ) ) { 1047 return null; 1048 } 1049 1050 if ( empty( $name ) ) { 1051 foreach ( $_wp_administration_panels as $panel_name => $panel ) { 1052 if ( $detect_via_callback && call_user_func( $panel->check_callback ) ) { 1053 return $panel; 1054 } elseif ( ! $detect_via_callback && defined( $panel->constant_name ) && constant( $panel->constant_name ) ) { 1055 return $panel; 1056 } 1057 } 1058 return null; 1059 } 1060 1061 if ( ! isset( $_wp_administration_panels[ $name ] ) ) { 1062 return null; 1063 } 1064 1065 return $_wp_administration_panels[ $name ]; 1066 } -
src/wp-includes/link-template.php
3401 3401 * @return string Admin URL link with optional path appended. 3402 3402 */ 3403 3403 function self_admin_url( $path = '', $scheme = 'admin' ) { 3404 if ( is_network_admin() ) 3405 return network_admin_url($path, $scheme); 3406 elseif ( is_user_admin() ) 3407 return user_admin_url($path, $scheme); 3408 else 3409 return admin_url($path, $scheme); 3404 if ( function_exists( 'get_administration_panel' ) ) { 3405 $panel = get_administration_panel( '', true ); 3406 if ( $panel ) { 3407 return call_user_func( $panel->url_callback, $path, $scheme ); 3408 } 3409 } 3410 3411 return admin_url( $path, $scheme ); 3410 3412 } 3411 3413 3412 3414 /**