WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/04/2017 08:01:12 PM (3 years ago)
Author:
westonruter
Message:

Customize: Allow controls to be created with pre-instantiated Setting object(s), or even with plain Value object(s).

  • Allow passing settings in keyed object (e.g. settings: { default: 'id' } ), or as an array (e.g. settings: [ 'id' ]) with first being default; again, Setting/Value` objects may be supplied instead of IDs.
  • Allow a single setting to be supplied with just a single setting param, either a string or a Setting/Value object.
  • Update changeset_status and scheduled_changeset_date to be added dynamically with JS and simply passing of api.state() instances as setting.
  • Introduce a data-customize-setting-key-link attribute which, unlike data-customize-setting-link, allows passing the setting key (e.g. default) as opposed to the setting ID.
  • Allow WP_Customize_Control::get_link() to return data-customize-setting-key-link when setting is not registered.
  • Eliminate default_value from WP_Customize_Date_Time_Control since now comes from supplied Value.
  • Export status choices as wp.customize.settings.changeset.statusChoices.
  • Export date and time formats as wp.customize.settings.dateFormat and wp.customize.settings.timeFormat respectively.

Props westonruter, sayedwp.
See #39896, #30738, #30741, #42083.
Fixes #37964, #36167.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-control.php

    r41740 r41750  
    431431     *
    432432     * @since 3.4.0
     433     * @since 4.9.0 Return a `data-customize-setting-key-link` attribute if a setting is not registered for the supplied setting key.
    433434     *
    434435     * @param string $setting_key
    435      * @return string Data link parameter, if $setting_key is a valid setting, empty string otherwise.
     436     * @return string Data link parameter, a `data-customize-setting-link` attribute if the `$setting_key` refers to a pre-registered setting,
     437     *                and a `data-customize-setting-key-link` attribute if the setting is not yet registered.
    436438     */
    437439    public function get_link( $setting_key = 'default' ) {
    438         if ( ! isset( $this->settings[ $setting_key ] ) )
    439             return '';
    440 
    441         return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
     440        if ( isset( $this->settings[ $setting_key ] ) && $this->settings[ $setting_key ] instanceof WP_Customize_Setting ) {
     441            return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
     442        } else {
     443            return 'data-customize-setting-key-link="' . esc_attr( $setting_key ) . '"';
     444        }
    442445    }
    443446
Note: See TracChangeset for help on using the changeset viewer.