WordPress.org

Make WordPress Core

Ticket #14060: 14060.3.diff

File 14060.3.diff, 2.3 KB (added by Nikschavan, 3 years ago)

Refreshed the patch

  • src/wp-admin/includes/menu.php

    diff --git src/wp-admin/includes/menu.php src/wp-admin/includes/menu.php
    index 7480402..7ea6c84 100644
    if ( !empty( $menu ) && 'wp-menu-separator' == $menu[ $last_menu_key ][ 4 ] ) 
    330330        unset( $menu[ $last_menu_key ] );
    331331unset( $last_menu_key );
    332332
    333 if ( !user_can_access_admin_page() ) {
     333if ( ! admin_page_exists() ) {
     334
     335        /**
     336         * Fires when access to an admin page does not exist.
     337         *
     338         * @since 4.6.0
     339         */
     340        do_action( 'admin_page_not_found' );
     341
     342        wp_die( __( 'The requested page does not exist.' ), 403 );
     343} elseif ( ! user_can_access_admin_page() ) {
    334344
    335345        /**
    336346         * Fires when access to an admin page is denied.
  • src/wp-admin/includes/plugin.php

    diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php
    index b6fe335..a501c62 100644
    function get_plugin_page_hookname( $plugin_page, $parent_page ) { 
    16741674}
    16751675
    16761676/**
     1677 * @since 4.6.0
     1678 *
     1679 * @global $admin_page_parent
     1680 * @global string $plugin_page
     1681 * @global array $_registered_pages
     1682 */
     1683function admin_page_exists() {
     1684        global $admin_page_parent, $plugin_page, $_registered_pages;
     1685
     1686        if ( ! isset( $admin_page_parent ) ) {
     1687                $admin_page_parent = get_admin_page_parent();
     1688        }
     1689
     1690        if ( isset( $plugin_page ) ) {
     1691                $hookname = get_plugin_page_hookname( $plugin_page, $admin_page_parent );
     1692
     1693                if ( ! isset($_registered_pages[$hookname]) ) {
     1694                        return false;
     1695                }
     1696        }
     1697
     1698        return true;
     1699}
     1700
     1701/**
    16771702 *
    16781703 * @global string $pagenow
    16791704 * @global array $menu
    function get_plugin_page_hookname( $plugin_page, $parent_page ) { 
    16851710 */
    16861711function user_can_access_admin_page() {
    16871712        global $pagenow, $menu, $submenu, $_wp_menu_nopriv, $_wp_submenu_nopriv,
    1688                 $plugin_page, $_registered_pages;
     1713                $plugin_page, $_registered_pages, $admin_page_parent; ;
    16891714
    1690         $parent = get_admin_page_parent();
     1715        $parent = isset( $admin_page_parent ) ? $admin_page_parent : get_admin_page_parent();
    16911716
    16921717        if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )
    16931718                return false;
    function user_can_access_admin_page() { 
    16981723
    16991724                $hookname = get_plugin_page_hookname($plugin_page, $parent);
    17001725
    1701                 if ( !isset($_registered_pages[$hookname]) )
     1726                if ( !admin_page_exists() ) {
    17021727                        return false;
     1728                }
    17031729        }
    17041730
    17051731        if ( empty( $parent) ) {