Ticket #40927: 40927.patch
| File 40927.patch, 3.1 KB (added by , 4 years ago) |
|---|
-
includes/plugin.php
1325 1325 1326 1326 if ( null === $position ) { 1327 1327 $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;1331 1328 } 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; 1346 1336 } 1347 $menu[ $position ] = $new_menu;1348 1337 } 1349 1338 1350 1339 $_registered_pages[ $hookname ] = true; … … 1418 1407 } 1419 1408 1420 1409 $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 ) { 1434 1411 $submenu[ $parent_slug ][] = $new_sub_menu; 1435 1412 } else { 1413 $position = (string) (float) $position; 1414 1436 1415 // Append the submenu if the parent item is not present in the submenu, 1437 1416 // or if position is equal or higher than the number of items in the array. 1438 1417 if ( ! isset( $submenu[ $parent_slug ] ) || $position >= count( $submenu[ $parent_slug ] ) ) { 1439 1418 $submenu[ $parent_slug ][] = $new_sub_menu; 1440 1419 } 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; 1456 1421 } 1457 1422 } 1458 1423 // Sort the parent array. 1459 ksort( $submenu[ $parent_slug ]);1424 uksort( $submenu[ $parent_slug ], 'strnatcasecmp' ); 1460 1425 1461 1426 $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug ); 1462 1427 if ( ! empty( $function ) && ! empty( $hookname ) ) {