responsive = $responsive; // WordPress should automatically set public properties from $args, but ensure it's set // Check if WordPress set it, otherwise use our stored value or defaults if ( ! empty( $this->alignments ) ) { // WordPress set it, use that } elseif ( ! empty( $alignments ) ) { // Use the value from args $this->alignments = $alignments; } else { // Use defaults - only 3 options: start, center, end $this->alignments = array( 'flex-start' => array( 'label' => __( 'Start', 'accepta' ), ), 'center' => array( 'label' => __( 'Center', 'accepta' ), ), 'flex-end' => array( 'label' => __( 'End', 'accepta' ), ), ); } } /** * Export alignments to JSON for JavaScript */ public function to_json() { parent::to_json(); $this->json['alignments'] = $this->alignments; } /** * Enqueue control related scripts/styles */ public function enqueue() { wp_enqueue_script( 'accepta-alignment-control', get_template_directory_uri() . '/inc/customizer-controls/js/alignment-control.js', array( 'jquery', 'customize-base' ), wp_get_theme()->get( 'Version' ), true ); wp_enqueue_style( 'accepta-alignment-control', get_template_directory_uri() . '/inc/customizer-controls/css/alignment-control.css', array(), wp_get_theme()->get( 'Version' ) ); } /** * Render the control's content */ public function render_content() { $input_id = '_customize-input-' . $this->id; $description_id = '_customize-description-' . $this->id; $describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '"' : ''; // Parse value - if responsive, expect JSON with desktop/tablet/mobile keys $raw_value = $this->value(); $value = array(); if ( $this->responsive ) { // Try to parse as JSON if ( ! empty( $raw_value ) ) { $decoded = json_decode( $raw_value, true ); if ( is_array( $decoded ) ) { $value = $decoded; } } // Set defaults if empty if ( empty( $value ) ) { $value = array( 'desktop' => 'center', 'tablet' => 'center', 'mobile' => 'center', ); } } else { // Non-responsive: single value $value = ! empty( $raw_value ) ? $raw_value : 'center'; } // Ensure alignments are set (fallback to defaults if empty) if ( empty( $this->alignments ) && ! empty( $this->json['alignments'] ) ) { $this->alignments = $this->json['alignments']; } if ( empty( $this->alignments ) ) { // Default: only 3 options $this->alignments = array( 'flex-start' => array( 'label' => __( 'Start', 'accepta' ) ), 'center' => array( 'label' => __( 'Center', 'accepta' ) ), 'flex-end' => array( 'label' => __( 'End', 'accepta' ) ), ); } $breakpoints = $this->responsive ? array( 'desktop', 'tablet', 'mobile' ) : array( 'desktop' ); ?>