WordPress.org

Make WordPress Core

Ticket #14060: 14060.4.diff

File 14060.4.diff, 2.4 KB (added by Nikschavan, 2 years ago)

Refreshed the patch with current trunk

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

    diff --git src/wp-admin/includes/menu.php src/wp-admin/includes/menu.php
    index 1c6f545f48..cafd99d780 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.9.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 0bc928d742..3566d29e41 100644
    function get_plugin_page_hookname( $plugin_page, $parent_page ) { 
    16881688        return $page_type . '_page_' . $plugin_name;
    16891689}
    16901690
     1691/**
     1692 * @since 4.9.0
     1693 *
     1694 * @global $admin_page_parent
     1695 * @global string $plugin_page
     1696 * @global array $_registered_pages
     1697 */
     1698function admin_page_exists() {
     1699        global $admin_page_parent, $plugin_page, $_registered_pages;
     1700
     1701        if ( ! isset( $admin_page_parent ) ) {
     1702                $admin_page_parent = get_admin_page_parent();
     1703        }
     1704
     1705        if ( isset( $plugin_page ) ) {
     1706                $hookname = get_plugin_page_hookname( $plugin_page, $admin_page_parent );
     1707
     1708                if ( ! isset($_registered_pages[$hookname]) ) {
     1709                        return false;
     1710                }
     1711        }
     1712
     1713        return true;
     1714}
     1715
    16911716/**
    16921717 *
    16931718 * @global string $pagenow
    function get_plugin_page_hookname( $plugin_page, $parent_page ) { 
    17001725 */
    17011726function user_can_access_admin_page() {
    17021727        global $pagenow, $menu, $submenu, $_wp_menu_nopriv, $_wp_submenu_nopriv,
    1703                 $plugin_page, $_registered_pages;
     1728                $plugin_page, $_registered_pages, $admin_page_parent; ;
    17041729
    1705         $parent = get_admin_page_parent();
     1730        $parent = isset( $admin_page_parent ) ? $admin_page_parent : get_admin_page_parent();
    17061731
    17071732        if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )
    17081733                return false;
    function user_can_access_admin_page() { 
    17131738
    17141739                $hookname = get_plugin_page_hookname($plugin_page, $parent);
    17151740
    1716                 if ( !isset($_registered_pages[$hookname]) )
     1741                if ( ! admin_page_exists() ) {
    17171742                        return false;
     1743                }
    17181744        }
    17191745
    17201746        if ( empty( $parent) ) {