Make WordPress Core


Ignore:
Timestamp:
10/04/2017 08:01:12 PM (9 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-manager.php

    r41749 r41750  
    36433643                        <button type="button" class="button-link button-link-delete"><?php _e( 'Discard changes' ); ?></button>
    36443644                </script>
     3645                <script type="text/html" id="tmpl-customize-selected-changeset-status-control">
     3646                        <# var inputId = _.uniqueId( 'customize-selected-changeset-status-control-input-' ); #>
     3647                        <# var descriptionId = _.uniqueId( 'customize-selected-changeset-status-control-description-' ); #>
     3648                        <# if ( data.label ) { #>
     3649                                <label for="{{ inputId }}" class="customize-control-title">{{ data.label }}</label>
     3650                        <# } #>
     3651                        <# if ( data.description ) { #>
     3652                                <span id="{{ descriptionId }}" class="description customize-control-description">{{{ data.description }}}</span>
     3653                        <# } #>
     3654                        <# _.each( data.choices, function( choice ) { #>
     3655                                <# var choiceId = inputId + '-' + choice.status; #>
     3656                                <span class="customize-inside-control-row">
     3657                                        <input id="{{ choiceId }}" type="radio" value="{{ choice.status }}" name="{{ inputId }}" data-customize-setting-key-link="default">
     3658                                        <label for="{{ choiceId }}">{{ choice.label }}</label>
     3659                                </span>
     3660                        <# } ); #>
     3661                </script>
    36453662                <?php
    36463663        }
     
    40254042                }
    40264043
     4044                $current_user_can_publish = current_user_can( get_post_type_object( 'customize_changeset' )->cap->publish_posts );
     4045
     4046                // @todo Include all of the status labels here from script-loader.php, and then allow it to be filtered.
     4047                $status_choices = array();
     4048                if ( $current_user_can_publish ) {
     4049                        $status_choices[] = array(
     4050                                'status' => 'publish',
     4051                                'label' => __( 'Publish' ),
     4052                        );
     4053                }
     4054                $status_choices[] = array(
     4055                        'status' => 'draft',
     4056                        'label' => __( 'Save Draft' ),
     4057                );
     4058                if ( $current_user_can_publish ) {
     4059                        $status_choices[] = array(
     4060                                'status' => 'future',
     4061                                'label' => __( 'Schedule' ),
     4062                        );
     4063                }
     4064
    40274065                // Prepare Customizer settings to pass to JavaScript.
    40284066                $changeset_post = null;
    40294067                if ( $changeset_post_id ) {
    40304068                        $changeset_post = get_post( $changeset_post_id );
     4069                }
     4070
     4071                if ( $this->changeset_post_id() && 'future' === get_post_status( $this->changeset_post_id() ) ) {
     4072                        $initial_date = get_the_time( 'Y-m-d H:i:s', $this->changeset_post_id() );
     4073                } else {
     4074                        $initial_date = current_time( 'mysql', false );
    40314075                }
    40324076
     
    40394083                                'latestAutoDraftUuid' => $autosave_autodraft_post ? $autosave_autodraft_post->post_name : null,
    40404084                                'status' => $changeset_post ? $changeset_post->post_status : '',
    4041                                 'currentUserCanPublish' => current_user_can( get_post_type_object( 'customize_changeset' )->cap->publish_posts ),
    4042                                 'publishDate' => $changeset_post ? $changeset_post->post_date : '', // @todo Only if future status? Rename to just date?
     4085                                'currentUserCanPublish' => $current_user_can_publish,
     4086                                'publishDate' => $initial_date,
     4087                                'statusChoices' => $status_choices,
    40434088                        ),
    40444089                        'initialServerDate' => current_time( 'mysql', false ),
     4090                        'dateFormat' => get_option( 'date_format' ),
     4091                        'timeFormat' => get_option( 'time_format' ),
    40454092                        'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
    40464093                        'initialClientTimestamp' => -1, // To be set with JS below.
     
    42064253                /* Publish Settings */
    42074254
     4255                // Note the controls for this section are added via JS.
    42084256                $this->add_section( 'publish_settings', array(
    42094257                        'title' => __( 'Publish Settings' ),
     
    42134261                        'active_callback' => array( $this, 'is_theme_active' ),
    42144262                ) );
    4215 
    4216                 /* Publish Settings Controls */
    4217                 $status_choices = array(
    4218                         'publish' => __( 'Publish' ),
    4219                         'draft' => __( 'Save Draft' ),
    4220                         'future' => __( 'Schedule' ),
    4221                 );
    4222 
    4223                 if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->publish_posts ) ) {
    4224                         unset( $status_choices['publish'] );
    4225                 }
    4226 
    4227                 $this->add_control( 'changeset_status', array(
    4228                         'section' => 'publish_settings',
    4229                         'priority' => 10,
    4230                         'settings' => array(),
    4231                         'type' => 'radio',
    4232                         'label' => __( 'Action' ),
    4233                         'choices' => $status_choices,
    4234                         'capability' => 'customize',
    4235                 ) );
    4236 
    4237                 if ( $this->changeset_post_id() && 'future' === get_post_status( $this->changeset_post_id() ) ) {
    4238                         $initial_date = get_the_time( 'Y-m-d H:i:s', $this->changeset_post_id() );
    4239                 } else {
    4240                         $initial_date = current_time( 'mysql', false );
    4241                 }
    4242 
    4243                 $this->add_control( new WP_Customize_Date_Time_Control( $this, 'changeset_scheduled_date', array(
    4244                         'section' => 'publish_settings',
    4245                         'priority' => 20,
    4246                         'settings' => array(),
    4247                         'type' => 'date_time',
    4248                         'min_year' => date( 'Y' ),
    4249                         'allow_past_date' => false,
    4250                         'include_time' => true,
    4251                         'twelve_hour_format' => false !== stripos( get_option( 'time_format' ), 'a' ),
    4252                         'description' => __( 'Schedule your customization changes to publish ("go live") at a future date.' ),
    4253                         'capability' => 'customize',
    4254                         'default_value' => $initial_date,
    4255                 ) ) );
    42564263
    42574264                /* Themes (controls are loaded via ajax) */
Note: See TracChangeset for help on using the changeset viewer.