Ticket #37526: 37526.5.diff
File 37526.5.diff, 20.7 KB (added by , 9 years ago) |
---|
-
src/wp-admin/admin-header.php
32 32 get_admin_page_title(); 33 33 $title = esc_html( strip_tags( $title ) ); 34 34 35 if ( is_network_admin() ) 36 $admin_title = sprintf( __( 'Network Admin: %s' ), esc_html( get_current_site()->site_name ) ); 37 elseif ( is_user_admin() ) 38 $admin_title = sprintf( __( 'User Dashboard: %s' ), esc_html( get_current_site()->site_name ) ); 39 else 40 $admin_title = get_bloginfo( 'name' ); 35 $admin_title = get_current_administration_panel()->admin_title; 41 36 42 37 if ( $admin_title == $title ) 43 38 $admin_title = sprintf( __( '%1$s — WordPress' ), $title ); … … 226 221 227 222 $current_screen->render_screen_meta(); 228 223 229 if ( is_network_admin() ) { 224 $_panel = get_current_administration_panel(); 225 226 if ( 'site' !== $_panel->name ) { 230 227 /** 231 * Prints network admin screen notices.228 * Prints admin screen notices for a specific Admin. 232 229 * 233 * @since 3.1.0 234 */ 235 do_action( 'network_admin_notices' ); 236 } elseif ( is_user_admin() ) { 237 /** 238 * Prints user admin screen notices. 230 * The dynamic portion of the hook name, `$panel_name`, refers to the Administration Panel name. 239 231 * 240 232 * @since 3.1.0 233 * @since 4.7.0 Hook is now dynamic. 241 234 */ 242 do_action( 'user_admin_notices' );235 do_action( $_panel->name . '_admin_notices' ); 243 236 } else { 244 237 /** 245 238 * Prints admin screen notices. … … 249 242 do_action( 'admin_notices' ); 250 243 } 251 244 245 unset( $_panel ); 246 252 247 /** 253 248 * Prints generic admin screen notices. 254 249 * -
src/wp-admin/admin.php
21 21 if ( ! defined('WP_USER_ADMIN') ) 22 22 define('WP_USER_ADMIN', false); 23 23 24 if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN) {25 define( 'WP_BLOG_ADMIN', true);24 if ( ! defined( 'WP_BLOG_ADMIN' ) ) { 25 define( 'WP_BLOG_ADMIN', true ); 26 26 } 27 27 28 28 if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') ) … … 83 83 84 84 auth_redirect(); 85 85 86 if ( is_multisite() ) { 87 // Register the additional administration panels. 88 $network_name = get_network()->site_name; 89 90 register_administration_panel( 'network', array( 91 'constant_name' => 'WP_NETWORK_ADMIN', 92 'check_callback' => 'is_network_admin', 93 'url_callback' => 'network_admin_url', 94 'menu_file' => ABSPATH . 'wp-admin/network/menu.php', 95 'admin_title' => sprintf( __( 'Network Admin: %s' ), esc_html( $network_name ) ), 96 ) ); 97 98 register_administration_panel( 'user', array( 99 'constant_name' => 'WP_USER_ADMIN', 100 'check_callback' => 'is_user_admin', 101 'url_callback' => 'user_admin_url', 102 'menu_file' => ABSPATH . 'wp-admin/user/menu.php', 103 'admin_title' => sprintf( __( 'User Dashboard: %s' ), esc_html( $network_name ) ), 104 ) ); 105 106 unset( $network_name ); 107 } 108 109 /** 110 * Fires before an admin screen or script is being initialized. 111 * 112 * Note, this does not just run on user-facing admin screens. 113 * It runs on admin-ajax.php and admin-post.php as well. 114 * 115 * @since 4.7.0 116 */ 117 do_action( 'admin_setup' ); 118 86 119 // Schedule trash collection 87 120 if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() ) 88 121 wp_schedule_event(time(), 'daily', 'wp_scheduled_delete'); … … 130 163 else 131 164 $taxnow = ''; 132 165 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 138 require(ABSPATH . 'wp-admin/menu.php'); 166 require( get_current_administration_panel()->menu_file ); 139 167 140 168 if ( current_user_can( 'manage_options' ) ) { 141 169 wp_raise_memory_limit( 'admin' ); -
src/wp-admin/includes/admin.php
49 49 /** WordPress Post Administration API */ 50 50 require_once(ABSPATH . 'wp-admin/includes/post.php'); 51 51 52 /** WordPress Administration Panel API */ 53 require_once(ABSPATH . 'wp-admin/includes/class-wp-administration-panel.php'); 54 require_once(ABSPATH . 'wp-admin/includes/administration-panel.php'); 55 52 56 /** WordPress Administration Screen API */ 53 57 require_once(ABSPATH . 'wp-admin/includes/class-wp-screen.php'); 54 58 require_once(ABSPATH . 'wp-admin/includes/screen.php'); -
src/wp-admin/includes/administration-panel.php
1 <?php 2 /** 3 * WordPress Administration Panel API. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** 10 * Registers an administration panel. 11 * 12 * This function should be used on the 'admin_setup' hook. 13 * 14 * A function to register a custom administration panel from a plugin. WordPress also 15 * uses it to register the 'network' and 'user' administration panels. 16 * 17 * @since 4.7.0 18 * 19 * @param string $name Name of the administration panel. Must not contain dashes. 20 * @param array|string $args { 21 * Array or string of administration panel arguments. 22 * 23 * @type string $constant_name Required. Name of the constant to check for whether we're currently 24 * in that administration panel. 25 * @type callable $check_callback Required. A callback function that can be used to check whether we're 26 * currently in that administration panel. 27 * @type callable $url_callback Required. A callback function to return the URL to the administration 28 * panel. The function must accept two parameters, `$path` and `$scheme` 29 * and return the full URL to the administration panel for that path. 30 * @type string $menu_file Required. The filename of the PHP file to include to setup the menu 31 * for the administration panel. 32 * @type string $admin_title Optional. Title to use in the title tag. 33 * } 34 * @return WP_Administration_Panel|WP_Error The administration panel object on success, an error object otherwise. 35 */ 36 function register_administration_panel( $name, $args ) { 37 return WP_Administration_Panel::register( $name, $args ); 38 } 39 40 /** 41 * Returns the administration panel object for a given name. 42 * 43 * @since 4.7.0 44 * 45 * @param string $name Name of the administration panel. 46 * @return WP_Administration_Panel|null Administration panel object or null if not found. 47 */ 48 function get_administration_panel( $name ) { 49 return WP_Administration_Panel::get( $name ); 50 } 51 52 /** 53 * Returns the current administration panel object. 54 * 55 * @since 4.7.0 56 * 57 * @return WP_Administration_Panel Administration panel object. 58 */ 59 function get_current_administration_panel() { 60 return WP_Administration_Panel::get_current(); 61 } 62 63 /** 64 * Returns all administration panels. 65 * 66 * @since 4.7.0 67 * 68 * @param bool $include_default Optional. Whether to include the default administration panel. Default false. 69 * @return array Array of administration panel objects. 70 */ 71 function get_administration_panels( $include_default = false ) { 72 return WP_Administration_Panel::get_all( $include_default ); 73 } -
src/wp-admin/includes/class-wp-administration-panel.php
Property changes on: src/wp-admin/includes/administration-panel.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
1 <?php 2 /** 3 * Administration Panel API: WP_Administration_Panel class 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 4.7.0 8 */ 9 10 /** 11 * Core class used to implement an administration panel API. 12 * 13 * @since 4.7.0 14 */ 15 final class WP_Administration_Panel { 16 /** 17 * The panel identifier. 18 * 19 * @since 4.7.0 20 * @access public 21 * @var string 22 */ 23 public $name; 24 25 /** 26 * The panel's constant name. 27 * 28 * @since 4.7.0 29 * @access public 30 * @var string 31 */ 32 public $constant_name; 33 34 /** 35 * The panel's check function. 36 * 37 * @since 4.7.0 38 * @access public 39 * @var callable 40 */ 41 public $check_callback; 42 43 /** 44 * The panel's URL function. 45 * 46 * @since 4.7.0 47 * @access public 48 * @var callable 49 */ 50 public $url_callback; 51 52 /** 53 * The panel's menu file path. 54 * 55 * @since 4.7.0 56 * @access public 57 * @var string 58 */ 59 public $menu_file; 60 61 /** 62 * The panel admin title. 63 * 64 * @since 4.7.0 65 * @access public 66 * @var string 67 */ 68 public $admin_title; 69 70 /** 71 * The registered administration panels. 72 * 73 * @since 4.7.0 74 * @access private 75 * @static 76 * @var array 77 */ 78 private static $panels = array(); 79 80 /** 81 * The default administration panel. 82 * 83 * @since 4.7.0 84 * @access private 85 * @static 86 * @var WP_Administration_Panel 87 */ 88 private static $default_panel; 89 90 /** 91 * Registers an administration panel. 92 * 93 * This function should be used on the 'admin_setup' hook. 94 * It is by default used to register the 'network' and 'user' administration panels. 95 * 96 * @since 4.7.0 97 * @access public 98 * @static 99 * 100 * @see register_administration_panel() 101 * 102 * @param string $name Name of the administration panel. Must not contain dashes. 103 * @param array|string $args { 104 * Array or string of administration panel arguments. 105 * 106 * @type string $constant_name Required. Name of the constant to check for whether we're currently 107 * in that administration panel. 108 * @type callable $check_callback Required. A callback function that can be used to check whether we're 109 * currently in that administration panel. 110 * @type callable $url_callback Required. A callback function to return the URL to the administration 111 * panel. The function must accept two parameters, `$path` and `$scheme` 112 * and return the full URL to the administration panel for that path. 113 * @type string $menu_file Required. The filename of the PHP file to include to setup the menu 114 * for the administration panel. 115 * @type string $admin_title Optional. Title to use in the title tag. 116 * } 117 * @return WP_Administration_Panel|WP_Error The administration panel object on success, an error object otherwise. 118 */ 119 public static function register( $name, $args ) { 120 // It is not allowed to override an existing administration panel. 121 if ( self::get_default()->name === $name || isset( self::$panels[ $name ] ) ) { 122 return new WP_Error( 'admin_panel_already_exist', sprintf( __( 'The administration panel %s already exists.' ), $name ) ); 123 } 124 125 $args = wp_parse_args( $args ); 126 127 $required = array( 'constant_name', 'check_callback', 'url_callback', 'menu_file' ); 128 129 foreach ( $required as $key ) { 130 if ( empty( $args[ $key ] ) ) { 131 return new WP_Error( 'empty_panel_argument', sprintf( __( 'The administration panel argument %s must not be empty.' ), $key ) ); 132 } 133 } 134 135 $panel = new self( $name, $args ); 136 137 self::$panels[ $name ] = $panel; 138 139 return $panel; 140 } 141 142 /** 143 * Returns the administration panel object for a given name. 144 * 145 * @since 4.7.0 146 * @access public 147 * @static 148 * 149 * @see get_administration_panel() 150 * 151 * @param string $name Name of the administration panel. 152 * @return WP_Administration_Panel|null Administration panel object or null if not found. 153 */ 154 public static function get( $name ) { 155 if ( self::get_default()->name === $name ) { 156 return self::get_default(); 157 } 158 159 if ( ! isset( self::$panels[ $name ] ) ) { 160 return null; 161 } 162 163 return self::$panels[ $name ]; 164 } 165 166 /** 167 * Returns the current administration panel object. 168 * 169 * @since 4.7.0 170 * @access public 171 * @static 172 * 173 * @see get_current_administration_panel() 174 * 175 * @return WP_Administration_Panel Administration panel object. 176 */ 177 public static function get_current() { 178 foreach ( self::$panels as $panel_name => $panel ) { 179 if ( $panel->is_active() ) { 180 return $panel; 181 } 182 } 183 184 return self::get_default(); 185 } 186 187 /** 188 * Returns all administration panels. 189 * 190 * @since 4.7.0 191 * @access public 192 * @static 193 * 194 * @see get_administration_panels() 195 * 196 * @param bool $include_default Optional. Whether to include the default administration panel. Default false. 197 * @return array Array of administration panel objects. 198 */ 199 public static function get_all( $include_default = false ) { 200 $panels = self::$panels; 201 202 if ( $include_default ) { 203 $panels[ self::$default_panel->name ] = self::$default_panel; 204 } 205 206 return $panels; 207 } 208 209 /** 210 * Returns the default administration panel. 211 * 212 * @since 4.7.0 213 * @access public 214 * @static 215 * 216 * @return WP_Administration_Panel The default administration panel. 217 */ 218 public static function get_default() { 219 if ( ! isset( self::$default_panel ) ) { 220 self::$default_panel = new self( 'site', array( 221 'constant_name' => 'WP_BLOG_ADMIN', 222 'check_callback' => 'is_blog_admin', 223 'url_callback' => 'admin_url', 224 'menu_file' => ABSPATH . 'wp-admin/menu.php', 225 ) ); 226 } 227 228 return self::$default_panel; 229 } 230 231 /** 232 * Constructor. 233 * 234 * @since 4.7.0 235 * @access private 236 * 237 * @param string $name Name of the administration panel. Must not contain dashes. 238 * @param array|string $args Array or string of arguments for registering an administration panel. 239 */ 240 private function __construct( $name, $args ) { 241 $defaults = array( 242 'constant_name' => '', 243 'check_callback' => null, 244 'url_callback' => null, 245 'menu_file' => '', 246 'admin_title' => '', 247 ); 248 249 $args = wp_parse_args( $args, $defaults ); 250 251 if ( empty( $args['admin_title'] ) ) { 252 $args['admin_title'] = get_bloginfo( 'name' ); 253 } 254 255 $this->name = $name; 256 257 foreach ( $args as $key => $value ) { 258 $this->$key = $value; 259 } 260 } 261 262 /** 263 * Checks whether this is the currently active administration panel. 264 * 265 * @since 4.7.0 266 * @access public 267 * 268 * @return bool True if active, false otherwise. 269 */ 270 public function is_active() { 271 return call_user_func( $this->check_callback ); 272 } 273 274 /** 275 * Retrieves the URL to this administration panel. 276 * 277 * @since 3.1.0 278 * 279 * @param string $path Optional. Path relative to the admin URL. Default empty. 280 * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() 281 * and is_ssl(). 'http' or 'https' can be passed to force those schemes. 282 * @return string Admin URL link with optional path appended. 283 */ 284 public function get_url( $path = '', $scheme = 'admin' ) { 285 return call_user_func( $this->url_callback, $path, $scheme ); 286 } 287 } -
src/wp-admin/includes/class-wp-screen.php
Property changes on: src/wp-admin/includes/class-wp-administration-panel.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
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 274 $in_admin = 'site'; 270 $in_admin = get_current_administration_panel()->name; 275 271 } 276 272 277 273 if ( 'index' == $id ) … … 337 333 break; 338 334 } 339 335 340 if ( 'network' == $in_admin) {341 $id .= '-network';342 $base .= '-network';343 } elseif ( 'user' == $in_admin ) {344 $id .= '-user';345 $base .= '-user';336 foreach ( get_administration_panels() as $panel ) { 337 if ( $panel->name == $in_admin ) { 338 $id .= '-' . $panel->name; 339 $base .= '-' . $panel->name; 340 break; 341 } 346 342 } 347 343 348 344 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_name = get_current_administration_panel()->name; 10 if ( 'site' !== $_panel_name ) { 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. 24 * 25 * The hook fires before menus and sub-menus are removed based on user privileges. 17 * The dynamic portion of the hook name, `$panel_name`, refers to the Administration Panel name. 26 18 * 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 ( 'site' !== $_panel_name ) { 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.0 126 * 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. 118 * The dynamic portion of the hook name, `$panel_name`, refers to the Administration Panel name. 134 119 * 135 120 * @since 3.1.0 121 * @since 4.7.0 Hook is now dynamic. 136 122 * 137 123 * @param string $context Empty context. 138 124 */ 139 do_action( 'user_admin_menu', '' );125 do_action( $_panel_name . '_admin_menu', '' ); 140 126 } else { 141 127 142 128 /** … … 149 135 do_action( 'admin_menu', '' ); 150 136 } 151 137 138 unset( $_panel_name ); 139 152 140 /* 153 141 * Remove menus that have no accessible submenus and require privileges 154 142 * that the user does not have. Run re-parent loop again. -
src/wp-admin/network/admin.php
8 8 */ 9 9 10 10 define( 'WP_NETWORK_ADMIN', true ); 11 define( 'WP_BLOG_ADMIN', false ); 11 12 12 13 /** Load WordPress Administration Bootstrap */ 13 14 require_once( dirname( dirname( __FILE__ ) ) . '/admin.php' ); -
src/wp-admin/user/admin.php
7 7 * @since 3.1.0 8 8 */ 9 9 10 define('WP_USER_ADMIN', true); 10 define( 'WP_USER_ADMIN', true ); 11 define( 'WP_BLOG_ADMIN', false ); 11 12 12 13 require_once( dirname(dirname(__FILE__)) . '/admin.php'); 13 14 -
src/wp-includes/link-template.php
3395 3395 * @return string Admin URL link with optional path appended. 3396 3396 */ 3397 3397 function self_admin_url( $path = '', $scheme = 'admin' ) { 3398 if ( is_network_admin() ) 3399 return network_admin_url($path, $scheme); 3400 elseif ( is_user_admin() ) 3401 return user_admin_url($path, $scheme); 3402 else 3403 return admin_url($path, $scheme); 3398 if ( function_exists( 'get_current_administration_panel' ) ) { 3399 $panel = get_current_administration_panel(); 3400 3401 return $panel->get_url( $path, $scheme ); 3402 } 3403 3404 return admin_url( $path, $scheme ); 3404 3405 } 3405 3406 3406 3407 /**