Support » Developing with WordPress » Updating $wp_customize choices after initial setup

  • Trying to approach what I want to do in my theme from a different angle. I’m setting up a customizer control as follows:

    $wp_customize->add_setting(
       'header_font_weight',
       array(
          'transport' => 'refresh',
          'default' => 400,
          'sanitize_callback' => 'throwback_sanitize_number_absint',
          )
    );
    $wp_customize->add_control(
       'header_font_weight',
       array(
          'type' => 'select',
          'label' => __( 'Weight', 'throwback' ),
          'section' => 'font_settings',
          'choices' => $titles_sizes,
          )
    );

    In another control, I’m calling a sanitize function which I would then like to update the choices on the above control on the fly. I found some sample code I based the below off of that sounded like it might work, but doesn’t.

    function throwback_sanitize_font_body ( $theFont ) {
    // Sanitize code
    add_action('customize_register', 'throwback_body_weights');
    }
    
    function throwback_body_weights ($wp_customize) {
       $body_sizes[400] = 400;
       $wp_customize->get_control('body_font_weight') ->choices = $body_sizes;
    }

    Basically here, I want the sanitize function to do a customize_register action and update the choices for the select control, in my above code, it would simply have a single choice of ‘400’ in the select menu. But when this all runs (the sanitize script otherwise works fine), my control still has the default choices still listed.

    I’m thinking that perhaps I need to manually call the render_content function or something similar to have this updated, but I’m not seeing a way to do this. Assuming the above should work at all…

  • You must be logged in to reply to this topic.