get_button_labels(); $this->button_labels = apply_filters( 'customizer_background_button_labels', $button_labels, $id ); // Set field labels $field_labels = $this->get_field_labels(); $this->field_labels = apply_filters( 'customizer_background_field_labels', $field_labels, $id ); // Set background choices $background_choices = $this->get_background_choices(); $this->background_choices = apply_filters( 'customizer_background_choices', $background_choices, $id ); } /** * Enqueue scripts/styles. * * @since 1.0.0 * @access public * @return void */ public function enqueue() { parent::enqueue(); // Custom scripts wp_enqueue_script( 'customizer-background-image-controls', get_template_directory_uri() . '/customizer/background/js/customize-controls.js', array( 'jquery'), '1.0.0', true ); } /** * Add custom parameters to pass to the JS via JSON. * * @since 1.0.0 * @access public * @return void */ public function to_json() { parent::to_json(); $background_choices = $this->background_choices; $field_labels = $this->field_labels; // Loop through each of the settings and set up the data for it. foreach ( $this->settings as $setting_key => $setting_id ) { $this->json[ $setting_key ] = array( 'link' => $this->get_link( $setting_key ), 'value' => $this->value( $setting_key ), 'label' => isset( $field_labels[ $setting_key ] ) ? $field_labels[ $setting_key ] : '' ); if ( 'image_url' === $setting_key ) { if ( $this->value( $setting_key ) ) { // Get the attachment model for the existing file. $attachment_id = attachment_url_to_postid( $this->value( $setting_key ) ); if ( $attachment_id ) { $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id ); } } } elseif ( 'repeat' === $setting_key ) { $this->json[ $setting_key ]['choices'] = $background_choices['repeat']; } elseif ( 'size' === $setting_key ) { $this->json[ $setting_key ]['choices'] = $background_choices['size']; } elseif ( 'position' === $setting_key ) { $this->json[ $setting_key ]['choices'] = $background_choices['position']; } elseif ( 'attach' === $setting_key ) { $this->json[ $setting_key ]['choices'] = $background_choices['attach']; } } } /** * Render a JS template for the content of the media control. * * @since 1.0.0 */ public function content_template() { parent::content_template(); ?>
<# if ( data.attachment && data.repeat && data.repeat.choices ) { #>
  • <# if ( data.repeat.label ) { #> {{ data.repeat.label }} <# } #>
  • <# } #> <# if ( data.attachment && data.size && data.size.choices ) { #>
  • <# if ( data.size.label ) { #> {{ data.size.label }} <# } #>
  • <# } #> <# if ( data.attachment && data.position && data.position.choices ) { #>
  • <# if ( data.position.label ) { #> {{ data.position.label }} <# } #>
  • <# } #> <# if ( data.attachment && data.attach && data.attach.choices ) { #>
  • <# if ( data.attach.label ) { #> {{ data.attach.label }} <# } #>
  • <# } #>
    __( 'Select Image', 'royal-shop' ), 'change' => __( 'Change Image', 'royal-shop' ), 'remove' => __( 'Remove', 'royal-shop' ), 'default' => __( 'Default', 'royal-shop' ), 'placeholder' => __( 'No image selected', 'royal-shop' ), 'frame_title' => __( 'Select Image', 'royal-shop' ), 'frame_button' => __( 'Choose Image', 'royal-shop' ), ); return $button_labels; } /** * Returns field labels. * * @since 1.0.0 */ public static function get_field_labels() { $field_labels = array( 'repeat' => __( 'Background Repeat', 'royal-shop' ), 'size' => __( 'Background Size', 'royal-shop' ), 'position' => __( 'Background Position', 'royal-shop' ), 'attach' => __( 'Background Attachment', 'royal-shop' ) ); return $field_labels; } /** * Returns the background choices. * * @since 1.0.0 * @return array */ public static function get_background_choices() { $choices = array( 'repeat' => array( 'no-repeat' => __( 'No Repeat', 'royal-shop' ), 'repeat' => __( 'Tile', 'royal-shop' ), 'repeat-x' => __( 'Tile Horizontally', 'royal-shop' ), 'repeat-y' => __( 'Tile Vertically', 'royal-shop' ) ), 'size' => array( 'auto' => __( 'Default', 'royal-shop' ), 'cover' => __( 'Cover', 'royal-shop' ), 'contain' => __( 'Contain', 'royal-shop' ) ), 'position' => array( 'left top' => __( 'Left Top', 'royal-shop' ), 'left center' => __( 'Left Center', 'royal-shop' ), 'left bottom' => __( 'Left Bottom', 'royal-shop' ), 'right top' => __( 'Right Top', 'royal-shop' ), 'right center' => __( 'Right Center', 'royal-shop' ), 'right bottom' => __( 'Right Bottom', 'royal-shop' ), 'center top' => __( 'Center Top', 'royal-shop' ), 'center center' => __( 'Center Center', 'royal-shop' ), 'center bottom' => __( 'Center Bottom', 'royal-shop' ) ), 'attach' => array( 'fixed' => __( 'Fixed', 'royal-shop' ), 'scroll' => __( 'Scroll', 'royal-shop' ) ) ); return $choices; } }