Make WordPress Core

Ticket #37885: 37885.diff

File 37885.diff, 4.3 KB (added by joehoyle, 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..87a61a4 100644
    a b function user_can_access_admin_page() { 
    17651765/* Whitelist functions */
    17661766
    17671767/**
    1768  * Register a setting and its sanitization callback
     1768 * Register a setting and its data
    17691769 *
    17701770 * @since 2.7.0
    17711771 *
    17721772 * @global array $new_whitelist_options
     1773 * @global array $wp_registered_settings
    17731774 *
    17741775 * @param string $option_group A settings group name. Should correspond to a whitelisted option key name.
    17751776 *      Default whitelisted option key names include "general," "discussion," and "reading," among others.
    17761777 * @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.
    17781787 */
    1779 function register_setting( $option_group, $option_name, $sanitize_callback = '' ) {
    1780         global $new_whitelist_options;
     1788function 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        }
    17811823
    17821824        if ( 'misc' == $option_group ) {
    17831825                _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 = '' 
    17901832        }
    17911833
    17921834        $new_whitelist_options[ $option_group ][] = $option_name;
    1793         if ( $sanitize_callback != '' )
     1835        if ( '' !== $sanitize_callback ) {
    17941836                add_filter( "sanitize_option_{$option_name}", $sanitize_callback );
     1837        }
     1838
     1839        $wp_registered_settings[ $option_name ] = $args;
    17951840}
    17961841
    17971842/**
    function register_setting( $option_group, $option_name, $sanitize_callback = '' 
    18061851 * @param callable $sanitize_callback
    18071852 */
    18081853function unregister_setting( $option_group, $option_name, $sanitize_callback = '' ) {
    1809         global $new_whitelist_options;
     1854        global $new_whitelist_options, $wp_registered_settings;
    18101855
    18111856        if ( 'misc' == $option_group ) {
    18121857                _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 = ' 
    18231868                unset( $new_whitelist_options[ $option_group ][ $pos ] );
    18241869        if ( $sanitize_callback != '' )
    18251870                remove_filter( "sanitize_option_{$option_name}", $sanitize_callback );
     1871
     1872        if ( isset( $wp_registered_settings[ $option_name ] ) ) {
     1873                unset( $wp_registered_settings[ $option_name ] );
     1874        }
     1875}
     1876
     1877/**
     1878 * Retrieves a list of registered meta keys for an object type.
     1879 *
     1880 * @since 4.7.0
     1881 *
     1882 * @return array List of registered meta keys.
     1883 */
     1884function get_registered_settings() {
     1885        global $wp_registered_settings;
     1886
     1887        if ( ! is_array( $wp_registered_settings ) ) {
     1888                return array();
     1889        }
     1890
     1891        return $wp_registered_settings;
    18261892}
    18271893
    18281894/**