Make WordPress Core

Ticket #40927: 40927.patch

File 40927.patch, 3.1 KB (added by Cybr, 4 years ago)

Reverts changeset #52569. Fixes tickets #40927 and #54798.

  • includes/plugin.php

     
    13251325
    13261326        if ( null === $position ) {
    13271327                $menu[] = $new_menu;
    1328         } elseif ( isset( $menu[ "$position" ] ) ) {
    1329                 $position            = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001;
    1330                 $menu[ "$position" ] = $new_menu;
    13311328        } else {
    1332                 if ( ! is_int( $position ) ) {
    1333                         _doing_it_wrong(
    1334                                 __FUNCTION__,
    1335                                 sprintf(
    1336                                         /* translators: %s: add_menu_page() */
    1337                                         __( 'The seventh parameter passed to %s should be an integer representing menu position.' ),
    1338                                         '<code>add_menu_page()</code>'
    1339                                 ),
    1340                                 '6.0.0'
    1341                         );
    1342                         // If the position is not a string (i.e. float), convert it to string.
    1343                         if ( ! is_string( $position ) ) {
    1344                                 $position = (string) $position;
    1345                         }
     1329                $position = (string) (float) $position;
     1330
     1331                if ( isset( $menu[ $position ] ) ) {
     1332                        $position            = $position + substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001;
     1333                        $menu[ $position ] = $new_menu;
     1334                } else {
     1335                        $menu[ $position ] = $new_menu;
    13461336                }
    1347                 $menu[ $position ] = $new_menu;
    13481337        }
    13491338
    13501339        $_registered_pages[ $hookname ] = true;
     
    14181407        }
    14191408
    14201409        $new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title );
    1421         if ( ! is_int( $position ) ) {
    1422                 if ( null !== $position ) {
    1423                         _doing_it_wrong(
    1424                                 __FUNCTION__,
    1425                                 sprintf(
    1426                                         /* translators: %s: add_submenu_page() */
    1427                                         __( 'The seventh parameter passed to %s should be an integer representing menu position.' ),
    1428                                         '<code>add_submenu_page()</code>'
    1429                                 ),
    1430                                 '5.3.0'
    1431                         );
    1432                 }
    1433 
     1410        if ( null === $position ) {
    14341411                $submenu[ $parent_slug ][] = $new_sub_menu;
    14351412        } else {
     1413                $position = (string) (float) $position;
     1414
    14361415                // Append the submenu if the parent item is not present in the submenu,
    14371416                // or if position is equal or higher than the number of items in the array.
    14381417                if ( ! isset( $submenu[ $parent_slug ] ) || $position >= count( $submenu[ $parent_slug ] ) ) {
    14391418                        $submenu[ $parent_slug ][] = $new_sub_menu;
    14401419                } else {
    1441                         // Test for a negative position.
    1442                         $position = max( $position, 0 );
    1443                         if ( 0 === $position ) {
    1444                                 // For negative or `0` positions, prepend the submenu.
    1445                                 array_unshift( $submenu[ $parent_slug ], $new_sub_menu );
    1446                         } else {
    1447                                 // Grab all of the items before the insertion point.
    1448                                 $before_items = array_slice( $submenu[ $parent_slug ], 0, $position, true );
    1449                                 // Grab all of the items after the insertion point.
    1450                                 $after_items = array_slice( $submenu[ $parent_slug ], $position, null, true );
    1451                                 // Add the new item.
    1452                                 $before_items[] = $new_sub_menu;
    1453                                 // Merge the items.
    1454                                 $submenu[ $parent_slug ] = array_merge( $before_items, $after_items );
    1455                         }
     1420                        $submenu[ $parent_slug ][ $position ] = $new_sub_menu;
    14561421                }
    14571422        }
    14581423        // Sort the parent array.
    1459         ksort( $submenu[ $parent_slug ] );
     1424        uksort( $submenu[ $parent_slug ], 'strnatcasecmp' );
    14601425
    14611426        $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
    14621427        if ( ! empty( $function ) && ! empty( $hookname ) ) {