From 60e1dd409bd467974d8b112ac5eaa50605bd94c1 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 8 Jan 2015 22:15:24 +0000 Subject: [PATCH] Properly declare `$hook_suffix`, `$plugin_page`, `$typenow`, and `$taxnow` as globals in `wp-admin/admin.php`. Fixes #30958. Built from https://develop.svn.wordpress.org/trunk@31105 git-svn-id: http://core.svn.wordpress.org/trunk@31086 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin.php | 41 ++++++++++++++++++++++-------------- wp-admin/includes/plugin.php | 32 ++++++++++++++-------------- wp-admin/menu-header.php | 8 +++---- wp-includes/deprecated.php | 2 +- wp-includes/version.php | 2 +- 5 files changed, 47 insertions(+), 38 deletions(-) diff --git a/wp-admin/admin.php b/wp-admin/admin.php index 77d6d44913..d9335c521e 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -90,22 +90,31 @@ $time_format = get_option('time_format'); wp_enqueue_script( 'common' ); +// $pagenow is set in vars.php +// The remaining variables are imported as globals elsewhere, +// declared as globals here +global $pagenow, $hook_suffix, $plugin_page, $typenow, $taxnow; + +$page_hook = ''; +$hook_suffix = ''; +$plugin_page = ''; +$typenow = ''; +$taxnow = ''; + $editing = false; -if ( isset($_GET['page']) ) { +if ( isset( $_GET['page'] ) ) { $plugin_page = wp_unslash( $_GET['page'] ); - $plugin_page = plugin_basename($plugin_page); + $plugin_page = plugin_basename( $plugin_page ); } -if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) +if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) { $typenow = $_REQUEST['post_type']; -else - $typenow = ''; +} -if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) +if ( isset( $_REQUEST['taxonomy'] ) && taxonomy_exists( $_REQUEST['taxonomy'] ) ) { $taxnow = $_REQUEST['taxonomy']; -else - $taxnow = ''; +} if ( WP_NETWORK_ADMIN ) require(ABSPATH . 'wp-admin/network/menu.php'); @@ -144,11 +153,12 @@ if ( current_user_can( 'manage_options' ) ) { */ do_action( 'admin_init' ); -if ( isset($plugin_page) ) { - if ( !empty($typenow) ) +if ( $plugin_page ) { + if ( $typenow ) { $the_parent = $pagenow . '?post_type=' . $typenow; - else + } else { $the_parent = $pagenow; + } if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) { $page_hook = get_plugin_page_hook($plugin_page, $plugin_page); @@ -166,19 +176,18 @@ if ( isset($plugin_page) ) { unset($the_parent); } -$hook_suffix = ''; -if ( isset( $page_hook ) ) { +if ( $page_hook ) { $hook_suffix = $page_hook; -} elseif ( isset( $plugin_page ) ) { +} elseif ( $plugin_page ) { $hook_suffix = $plugin_page; -} elseif ( isset( $pagenow ) ) { +} elseif ( $pagenow ) { $hook_suffix = $pagenow; } set_current_screen(); // Handle plugin admin pages. -if ( isset($plugin_page) ) { +if ( $plugin_page ) { if ( $page_hook ) { /** * Fires before a particular screen is loaded. diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index c0d44ff6fc..3c2cf0007b 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -1508,7 +1508,7 @@ function get_admin_page_parent( $parent = '' ) { return $parent; } - if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { + if ( $pagenow == 'admin.php' && $plugin_page ) { foreach ( (array)$menu as $parent_menu ) { if ( $parent_menu[2] == $plugin_page ) { $parent_file = $plugin_page; @@ -1525,7 +1525,7 @@ function get_admin_page_parent( $parent = '' ) { } } - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { + if ( $plugin_page && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { $parent_file = $pagenow; if ( isset( $_wp_real_parent_file[$parent_file] ) ) $parent_file = $_wp_real_parent_file[$parent_file]; @@ -1536,13 +1536,13 @@ function get_admin_page_parent( $parent = '' ) { foreach ( $submenu[$parent] as $submenu_array ) { if ( isset( $_wp_real_parent_file[$parent] ) ) $parent = $_wp_real_parent_file[$parent]; - if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) { + if ( $typenow && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) { $parent_file = $parent; return $parent; - } elseif ( $submenu_array[2] == $pagenow && empty($typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) { + } elseif ( $submenu_array[2] == $pagenow && ! $typenow && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) { $parent_file = $parent; return $parent; - } elseif ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) { + } elseif ( $plugin_page && ($plugin_page == $submenu_array[2] ) ) { $parent_file = $parent; return $parent; } @@ -1575,7 +1575,7 @@ function get_admin_page_title() { if ( $menu_array[2] == $pagenow ) { $title = $menu_array[3]; return $menu_array[3]; - } elseif ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { + } elseif ( $plugin_page && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { $title = $menu_array[3]; return $menu_array[3]; } @@ -1587,14 +1587,14 @@ function get_admin_page_title() { } else { foreach ( array_keys( $submenu ) as $parent ) { foreach ( $submenu[$parent] as $submenu_array ) { - if ( isset( $plugin_page ) && + if ( $plugin_page && ( $plugin_page == $submenu_array[2] ) && ( ( $parent == $pagenow ) || ( $parent == $plugin_page ) || ( $plugin_page == $hook ) || ( $pagenow == 'admin.php' && $parent1 != $submenu_array[2] ) || - ( !empty($typenow) && $parent == $pagenow . '?post_type=' . $typenow) + ( $typenow && $parent == $pagenow . '?post_type=' . $typenow) ) ) { $title = $submenu_array[3]; @@ -1615,7 +1615,7 @@ function get_admin_page_title() { } if ( empty ( $title ) ) { foreach ( $menu as $menu_array ) { - if ( isset( $plugin_page ) && + if ( $plugin_page && ( $plugin_page == $menu_array[2] ) && ( $pagenow == 'admin.php' ) && ( $parent1 == $menu_array[2] ) ) @@ -1670,10 +1670,10 @@ function user_can_access_admin_page() { $parent = get_admin_page_parent(); - if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) + if ( ! $plugin_page && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) return false; - if ( isset( $plugin_page ) ) { + if ( $plugin_page ) { if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) return false; @@ -1688,25 +1688,25 @@ function user_can_access_admin_page() { return false; if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) return false; - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) + if ( $plugin_page && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) return false; - if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) + if ( $plugin_page && isset( $_wp_menu_nopriv[$plugin_page] ) ) return false; foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) return false; - if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) + if ( $plugin_page && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) return false; } return true; } - if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) + if ( $plugin_page && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) return false; if ( isset( $submenu[$parent] ) ) { foreach ( $submenu[$parent] as $submenu_array ) { - if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { + if ( $plugin_page && ( $submenu_array[2] == $plugin_page ) ) { if ( current_user_can( $submenu_array[1] )) return true; else diff --git a/wp-admin/menu-header.php b/wp-admin/menu-header.php index c599fd1be8..1279056dc4 100644 --- a/wp-admin/menu-header.php +++ b/wp-admin/menu-header.php @@ -66,7 +66,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { $submenu_items = $submenu[$item[2]]; } - if ( ( $parent_file && $item[2] == $parent_file ) || ( empty($typenow) && $self == $item[2] ) ) { + if ( ( $parent_file && $item[2] == $parent_file ) || ( ! $typenow && $self == $item[2] ) ) { $class[] = ! empty( $submenu_items ) ? 'wp-has-current-submenu wp-menu-open' : 'current'; } else { $class[] = 'wp-not-current-submenu'; @@ -167,7 +167,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { $menu_file = substr( $menu_file, 0, $pos ); // Handle current for post_type=post|page|foo pages, which won't match $self. - $self_type = ! empty( $typenow ) ? $self . '?post_type=' . $typenow : 'nothing'; + $self_type = $typenow ? $self . '?post_type=' . $typenow : 'nothing'; if ( isset( $submenu_file ) ) { if ( $submenu_file == $sub_item[2] ) @@ -175,8 +175,8 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { // If plugin_page is set the parent must either match the current page or not physically exist. // This allows plugin pages with the same hook to exist under different parents. } elseif ( - ( ! isset( $plugin_page ) && $self == $sub_item[2] ) || - ( isset( $plugin_page ) && $plugin_page == $sub_item[2] && ( $item[2] == $self_type || $item[2] == $self || file_exists($menu_file) === false ) ) + ( ! $plugin_page && $self == $sub_item[2] ) || + ( $plugin_page && $plugin_page == $sub_item[2] && ( $item[2] == $self_type || $item[2] == $self || file_exists($menu_file) === false ) ) ) { $class[] = 'current'; } diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index c3d2e04e05..f97e13ca5f 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -2576,7 +2576,7 @@ function is_plugin_page() { global $plugin_page; - if ( isset($plugin_page) ) + if ( $plugin_page ) return true; return false; diff --git a/wp-includes/version.php b/wp-includes/version.php index d5f35882c1..5d4cd0cb70 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31104'; +$wp_version = '4.2-alpha-31105'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.