Support » Themes and Templates » Extend the WP_Customize_Image_Control() class to change its $button_labels

  • I tried a lot just to change the 'default' button label of a WP_Customize_Image_Control, including this:

    if (class_exists('WP_Customize_Upload_Control')) {
      class WP_Customize_Custom_Control extends WP_Customize_Image_Control {
        public function __construct( $manager, $id, $args = array() ) {
          parent::__construct( $manager, $id, $args );
    
          $this->button_labels = array(
            'select'       => __( 'Custom Select Image' ),
            'change'       => __( 'Custom Change Image' ),
            'remove'       => __( 'Custom Remove' ),
            'default'      => __( 'Custom Default' ),
            'placeholder'  => __( 'Custom No image selected' ),
            'frame_title'  => __( 'Custom Select Image' ),
            'frame_button' => __( 'Custom Choose Image' ),
          );
        }
      }
    }
    add_action( 'customize_register', 'prefix_customize_register' );
    function prefix_customize_register( $wp_customize ) {
      $wp_customize->register_control_type( 'WP_Customize_Custom_Control' );
    
      // Another customize register here...
    }

    But unfortunately, the assigned values to the top 5 button labels 'select', 'change', 'remove', 'default' and 'placeholder' are not showing. How can they be changed? When I include this new unique public $type:

    if (class_exists('WP_Customize_Upload_Control')) {
      class WP_Customize_Custom_Control extends WP_Customize_Image_Control {
    
        public $type = 'custom';
    
        public function __construct( $manager, $id, $args = array() ) {
          // ...

    The aforementioned button labels will changed but they are now become unclickable. Anyone know how can I fix this?

  • The topic ‘Extend the WP_Customize_Image_Control() class to change its $button_labels’ is closed to new replies.