| 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; |
| 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; |