Ticket #37885: 37885.2.diff
File 37885.2.diff, 4.6 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/plugin.php
diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index 0f6efe3..66d2a56 100644
a b function user_can_access_admin_page() { 1765 1765 /* Whitelist functions */ 1766 1766 1767 1767 /** 1768 * Register a setting and its sanitization callback1768 * Register a setting and its data 1769 1769 * 1770 1770 * @since 2.7.0 1771 1771 * 1772 1772 * @global array $new_whitelist_options 1773 * @global array $wp_registered_settings 1773 1774 * 1774 1775 * @param string $option_group A settings group name. Should correspond to a whitelisted option key name. 1775 1776 * Default whitelisted option key names include "general," "discussion," and "reading," among others. 1776 1777 * @param string $option_name The name of an option to sanitize and save. 1777 * @param callable $sanitize_callback A callback function that sanitizes the option's value. 1778 * @param array $args { 1779 * Data used to describe the setting when registered. 1780 * 1781 * @type string $type The type of data associated with this setting. 1782 * @type string $description A description of the data attached to this setting. 1783 * @type callable $sanitize_callback A callback function that sanitizes the option's value. 1784 * @type bool $show_in_rest Whether data associated with this setting should be included in the REST API. 1785 * } 1786 * @return bool True if the setting was successfully registered in the global array, false if not. 1778 1787 */ 1779 function register_setting( $option_group, $option_name, $sanitize_callback = '' ) { 1780 global $new_whitelist_options; 1788 function register_setting( $option_group, $option_name, $args = array() ) { 1789 global $new_whitelist_options, $wp_registered_settings; 1790 1791 $defaults = array( 1792 'type' => 'string', 1793 'group' => $option_group, 1794 'description' => '', 1795 'sanitize_callback' => null, 1796 'show_in_rest' => false, 1797 ); 1798 1799 // Back-compat: old sanitize callback is added. 1800 if ( is_callable( $args ) ) { 1801 $args = array( 1802 'sanitize_callback' => $args, 1803 ); 1804 } 1805 1806 /** 1807 * Filters the registration arguments when registering a setting. 1808 * 1809 * @since 4.7.0 1810 * 1811 * @param array $args Array of setting registration arguments. 1812 * @param array $defaults Array of default arguments. 1813 * @param string $option_group Setting group. 1814 * @param string $option_name Setting name. 1815 */ 1816 $args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name ); 1817 1818 $args = wp_parse_args( $args, $defaults ); 1819 1820 if ( ! is_array( $wp_registered_settings ) ) { 1821 $wp_registered_settings = array(); 1822 } 1781 1823 1782 1824 if ( 'misc' == $option_group ) { 1783 1825 _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); … … function register_setting( $option_group, $option_name, $sanitize_callback = '' 1790 1832 } 1791 1833 1792 1834 $new_whitelist_options[ $option_group ][] = $option_name; 1793 if ( $sanitize_callback != '' ) 1794 add_filter( "sanitize_option_{$option_name}", $sanitize_callback ); 1835 if ( '' !== $args['sanitize_callback'] ) { 1836 add_filter( "sanitize_option_{$option_name}", $args['sanitize_callback'] ); 1837 } 1838 1839 $wp_registered_settings[ $option_name ] = $args; 1795 1840 } 1796 1841 1797 1842 /** … … function register_setting( $option_group, $option_name, $sanitize_callback = '' 1806 1851 * @param callable $sanitize_callback 1807 1852 */ 1808 1853 function unregister_setting( $option_group, $option_name, $sanitize_callback = '' ) { 1809 global $new_whitelist_options ;1854 global $new_whitelist_options, $wp_registered_settings; 1810 1855 1811 1856 if ( 'misc' == $option_group ) { 1812 1857 _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); … … function unregister_setting( $option_group, $option_name, $sanitize_callback = ' 1819 1864 } 1820 1865 1821 1866 $pos = array_search( $option_name, (array) $new_whitelist_options[ $option_group ] ); 1822 if ( $pos !== false ) 1867 if ( $pos !== false ) { 1823 1868 unset( $new_whitelist_options[ $option_group ][ $pos ] ); 1824 if ( $sanitize_callback != '' ) 1869 } 1870 if ( '' !== $sanitize_callback ) { 1825 1871 remove_filter( "sanitize_option_{$option_name}", $sanitize_callback ); 1872 } 1873 1874 if ( isset( $wp_registered_settings[ $option_name ] ) ) { 1875 unset( $wp_registered_settings[ $option_name ] ); 1876 } 1877 } 1878 1879 /** 1880 * Retrieves an array of registered settings. 1881 * 1882 * @since 4.7.0 1883 * 1884 * @return array List of registered settings, keyed by option name. 1885 */ 1886 function get_registered_settings() { 1887 global $wp_registered_settings; 1888 1889 if ( ! is_array( $wp_registered_settings ) ) { 1890 return array(); 1891 } 1892 1893 return $wp_registered_settings; 1826 1894 } 1827 1895 1828 1896 /**