Make WordPress Core

Ticket #40927: 40927.2.patch

File 40927.2.patch, 3.4 KB (added by Cybr, 4 years ago)

Convert array index back to string from float after the duplicate is resolved.

  • 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 += substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001;
     1333                        // Convert back to string because PHP converts floats to ints in array indexes.
     1334                        $position = (string) $position;
    13461335                }
     1336
    13471337                $menu[ $position ] = $new_menu;
    13481338        }
    13491339
     
    14181408        }
    14191409
    14201410        $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 
     1411        if ( null === $position ) {
    14341412                $submenu[ $parent_slug ][] = $new_sub_menu;
    14351413        } else {
    1436                 // Append the submenu if the parent item is not present in the submenu,
    1437                 // or if position is equal or higher than the number of items in the array.
    1438                 if ( ! isset( $submenu[ $parent_slug ] ) || $position >= count( $submenu[ $parent_slug ] ) ) {
    1439                         $submenu[ $parent_slug ][] = $new_sub_menu;
    1440                 } 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                         }
     1414                $position = (string) (float) $position;
     1415
     1416                if ( isset( $menu[ $position ] ) ) {
     1417                        $position += substr( base_convert( md5( $menu_slug . $menu_title ), 16, 10 ), -5 ) * 0.00001;
     1418                        // Convert back to string because PHP converts floats to ints in array indexes.
     1419                        $position = (string) $position;
    14561420                }
     1421
     1422                $submenu[ $parent_slug ][ $position ] = $new_sub_menu;
    14571423        }
    14581424        // Sort the parent array.
    1459         ksort( $submenu[ $parent_slug ] );
     1425        uksort( $submenu[ $parent_slug ], 'strnatcasecmp' );
    14601426
    14611427        $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
    14621428        if ( ! empty( $function ) && ! empty( $hookname ) ) {