Changeset 53215
- Timestamp:
- 04/19/2022 12:46:24 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/plugin.php
r53181 r53215 1293 1293 * include lowercase alphanumeric, dashes, and underscores characters to be compatible 1294 1294 * with sanitize_key(). 1295 * @param callable $ functionOptional. The function to be called to output the content for this page.1295 * @param callable $callback Optional. The function to be called to output the content for this page. 1296 1296 * @param string $icon_url Optional. The URL to the icon to be used for this menu. 1297 1297 * * Pass a base64-encoded SVG using a data URI, which will be colored to match … … 1303 1303 * @return string The resulting page's hook_suffix. 1304 1304 */ 1305 function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $icon_url = '', $position = null ) {1305 function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '', $position = null ) { 1306 1306 global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages; 1307 1307 … … 1312 1312 $hookname = get_plugin_page_hookname( $menu_slug, '' ); 1313 1313 1314 if ( ! empty( $ function) && ! empty( $hookname ) && current_user_can( $capability ) ) {1315 add_action( $hookname, $ function);1314 if ( ! empty( $callback ) && ! empty( $hookname ) && current_user_can( $capability ) ) { 1315 add_action( $hookname, $callback ); 1316 1316 } 1317 1317 … … 1372 1372 * @global array $_parent_pages 1373 1373 * 1374 * @param string 1375 * 1376 * @param string 1377 * 1378 * @param string 1379 * @param string 1380 * @param string 1381 * 1382 * 1383 * @param callable $functionOptional. The function to be called to output the content for this page.1384 * @param int|float 1374 * @param string $parent_slug The slug name for the parent menu (or the file name of a standard 1375 * WordPress admin page). 1376 * @param string $page_title The text to be displayed in the title tags of the page when the menu 1377 * is selected. 1378 * @param string $menu_title The text to be used for the menu. 1379 * @param string $capability The capability required for this menu to be displayed to the user. 1380 * @param string $menu_slug The slug name to refer to this menu by. Should be unique for this menu 1381 * and only include lowercase alphanumeric, dashes, and underscores characters 1382 * to be compatible with sanitize_key(). 1383 * @param callable $callback Optional. The function to be called to output the content for this page. 1384 * @param int|float $position Optional. The position in the menu order this item should appear. 1385 1385 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1386 1386 */ 1387 function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1387 function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1388 1388 global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv, 1389 1389 $_registered_pages, $_parent_pages; … … 1457 1457 1458 1458 $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug ); 1459 if ( ! empty( $ function) && ! empty( $hookname ) ) {1460 add_action( $hookname, $ function);1459 if ( ! empty( $callback ) && ! empty( $hookname ) ) { 1460 add_action( $hookname, $callback ); 1461 1461 } 1462 1462 … … 1493 1493 * @param string $capability The capability required for this menu to be displayed to the user. 1494 1494 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1495 * @param callable $ functionOptional. The function to be called to output the content for this page.1495 * @param callable $callback Optional. The function to be called to output the content for this page. 1496 1496 * @param int $position Optional. The position in the menu order this item should appear. 1497 1497 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1498 1498 */ 1499 function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1500 return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1499 function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1500 return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1501 1501 } 1502 1502 … … 1517 1517 * @param string $capability The capability required for this menu to be displayed to the user. 1518 1518 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1519 * @param callable $ functionOptional. The function to be called to output the content for this page.1519 * @param callable $callback Optional. The function to be called to output the content for this page. 1520 1520 * @param int $position Optional. The position in the menu order this item should appear. 1521 1521 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1522 1522 */ 1523 function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1524 return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1523 function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1524 return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1525 1525 } 1526 1526 … … 1541 1541 * @param string $capability The capability required for this menu to be displayed to the user. 1542 1542 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1543 * @param callable $ functionOptional. The function to be called to output the content for this page.1543 * @param callable $callback Optional. The function to be called to output the content for this page. 1544 1544 * @param int $position Optional. The position in the menu order this item should appear. 1545 1545 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1546 1546 */ 1547 function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1548 return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1547 function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1548 return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1549 1549 } 1550 1550 … … 1565 1565 * @param string $capability The capability required for this menu to be displayed to the user. 1566 1566 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1567 * @param callable $ functionOptional. The function to be called to output the content for this page.1567 * @param callable $callback Optional. The function to be called to output the content for this page. 1568 1568 * @param int $position Optional. The position in the menu order this item should appear. 1569 1569 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1570 1570 */ 1571 function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1572 return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1571 function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1572 return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1573 1573 } 1574 1574 … … 1589 1589 * @param string $capability The capability required for this menu to be displayed to the user. 1590 1590 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1591 * @param callable $ functionOptional. The function to be called to output the content for this page.1591 * @param callable $callback Optional. The function to be called to output the content for this page. 1592 1592 * @param int $position Optional. The position in the menu order this item should appear. 1593 1593 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1594 1594 */ 1595 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1595 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1596 1596 if ( current_user_can( 'edit_users' ) ) { 1597 1597 $parent = 'users.php'; … … 1599 1599 $parent = 'profile.php'; 1600 1600 } 1601 return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1601 return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1602 1602 } 1603 1603 … … 1618 1618 * @param string $capability The capability required for this menu to be displayed to the user. 1619 1619 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1620 * @param callable $ functionOptional. The function to be called to output the content for this page.1620 * @param callable $callback Optional. The function to be called to output the content for this page. 1621 1621 * @param int $position Optional. The position in the menu order this item should appear. 1622 1622 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1623 1623 */ 1624 function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1625 return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1624 function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1625 return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1626 1626 } 1627 1627 … … 1642 1642 * @param string $capability The capability required for this menu to be displayed to the user. 1643 1643 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1644 * @param callable $ functionOptional. The function to be called to output the content for this page.1644 * @param callable $callback Optional. The function to be called to output the content for this page. 1645 1645 * @param int $position Optional. The position in the menu order this item should appear. 1646 1646 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1647 1647 */ 1648 function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1649 return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1648 function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1649 return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1650 1650 } 1651 1651 … … 1666 1666 * @param string $capability The capability required for this menu to be displayed to the user. 1667 1667 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1668 * @param callable $ functionOptional. The function to be called to output the content for this page.1668 * @param callable $callback Optional. The function to be called to output the content for this page. 1669 1669 * @param int $position Optional. The position in the menu order this item should appear. 1670 1670 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1671 1671 */ 1672 function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1673 return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1672 function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1673 return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1674 1674 } 1675 1675 … … 1690 1690 * @param string $capability The capability required for this menu to be displayed to the user. 1691 1691 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1692 * @param callable $ functionOptional. The function to be called to output the content for this page.1692 * @param callable $callback Optional. The function to be called to output the content for this page. 1693 1693 * @param int $position Optional. The position in the menu order this item should appear. 1694 1694 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1695 1695 */ 1696 function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1697 return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1696 function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1697 return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1698 1698 } 1699 1699 … … 1714 1714 * @param string $capability The capability required for this menu to be displayed to the user. 1715 1715 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1716 * @param callable $ functionOptional. The function to be called to output the content for this page.1716 * @param callable $callback Optional. The function to be called to output the content for this page. 1717 1717 * @param int $position Optional. The position in the menu order this item should appear. 1718 1718 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1719 1719 */ 1720 function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1721 return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1720 function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1721 return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1722 1722 } 1723 1723 … … 1738 1738 * @param string $capability The capability required for this menu to be displayed to the user. 1739 1739 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1740 * @param callable $ functionOptional. The function to be called to output the content for this page.1740 * @param callable $callback Optional. The function to be called to output the content for this page. 1741 1741 * @param int $position Optional. The position in the menu order this item should appear. 1742 1742 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. 1743 1743 */ 1744 function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $ function= '', $position = null ) {1745 return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $ function, $position );1744 function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) { 1745 return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); 1746 1746 } 1747 1747 … … 1818 1818 * 1819 1819 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). 1820 * @param bool $ echo Whether or not to echothe URL. Default true.1820 * @param bool $display Optional. Whether or not to display the URL. Default true. 1821 1821 * @return string The menu page URL. 1822 1822 */ 1823 function menu_page_url( $menu_slug, $ echo= true ) {1823 function menu_page_url( $menu_slug, $display = true ) { 1824 1824 global $_parent_pages; 1825 1825 … … 1838 1838 $url = esc_url( $url ); 1839 1839 1840 if ( $ echo) {1840 if ( $display ) { 1841 1841 echo $url; 1842 1842 } … … 1863 1863 * @global array $_wp_submenu_nopriv 1864 1864 * 1865 * @param string $parent The slug name for the parent menu (or the file name of a standard1866 * WordPress admin page). Default empty string.1865 * @param string $parent_page Optional. The slug name for the parent menu (or the file name 1866 * of a standard WordPress admin page). Default empty string. 1867 1867 * @return string The parent file of the current admin page. 1868 1868 */ 1869 function get_admin_page_parent( $parent = '' ) {1869 function get_admin_page_parent( $parent_page = '' ) { 1870 1870 global $parent_file, $menu, $submenu, $pagenow, $typenow, 1871 1871 $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv; 1872 1872 1873 if ( ! empty( $parent ) && 'admin.php' !== $parent) {1874 if ( isset( $_wp_real_parent_file[ $parent ] ) ) {1875 $parent = $_wp_real_parent_file[ $parent];1876 } 1877 1878 return $parent ;1873 if ( ! empty( $parent_page ) && 'admin.php' !== $parent_page ) { 1874 if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) { 1875 $parent_page = $_wp_real_parent_file[ $parent_page ]; 1876 } 1877 1878 return $parent_page; 1879 1879 } 1880 1880 … … 1912 1912 } 1913 1913 1914 foreach ( array_keys( (array) $submenu ) as $parent ) {1915 foreach ( $submenu[ $parent ] as $submenu_array ) {1916 if ( isset( $_wp_real_parent_file[ $parent ] ) ) {1917 $parent = $_wp_real_parent_file[ $parent];1914 foreach ( array_keys( (array) $submenu ) as $parent_page ) { 1915 foreach ( $submenu[ $parent_page ] as $submenu_array ) { 1916 if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) { 1917 $parent_page = $_wp_real_parent_file[ $parent_page ]; 1918 1918 } 1919 1919 1920 1920 if ( ! empty( $typenow ) && "$pagenow?post_type=$typenow" === $submenu_array[2] ) { 1921 $parent_file = $parent ;1922 return $parent ;1921 $parent_file = $parent_page; 1922 return $parent_page; 1923 1923 } elseif ( empty( $typenow ) && $pagenow === $submenu_array[2] 1924 1924 && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) ) 1925 1925 ) { 1926 $parent_file = $parent ;1927 return $parent ;1926 $parent_file = $parent_page; 1927 return $parent_page; 1928 1928 } elseif ( isset( $plugin_page ) && $plugin_page === $submenu_array[2] ) { 1929 $parent_file = $parent ;1930 return $parent ;1929 $parent_file = $parent_page; 1930 return $parent_page; 1931 1931 } 1932 1932 }
Note: See TracChangeset
for help on using the changeset viewer.