add_dynamic_settings example

$widget_setting_ids   = array();
        $incoming_setting_ids = array_keys( $this->manager->unsanitized_post_values() );
        foreach ( $incoming_setting_ids as $setting_id ) {
            if ( ! is_null( $this->get_setting_type( $setting_id ) ) ) {
                $widget_setting_ids[] = $setting_id;
            }
        }
        if ( $this->manager->doing_ajax( 'update-widget' ) && isset( $_REQUEST['widget-id'] ) ) {
            $widget_setting_ids[] = $this->get_setting_id( wp_unslash( $_REQUEST['widget-id'] ) );
        }

        $settings = $this->manager->add_dynamic_settings( array_unique( $widget_setting_ids ) );

        if ( $this->manager->settings_previewed() ) {
            foreach ( $settings as $setting ) {
                $setting->preview();
            }
        }
    }

    /** * Determines the arguments for a dynamically-created setting. * * @since 4.2.0 * * @param false|array $args The arguments to the WP_Customize_Setting constructor. * @param string $setting_id ID for dynamic setting, usually coming from `$_POST['customized']`. * @return array|false Setting arguments, false otherwise. */
$this->set_post_value( $setting_id$setting_params['value'] ); // Add to post values so that they can be validated and sanitized.             }
        }

        // Note that in addition to post data, this will include any stashed theme mods.         $post_values = $this->unsanitized_post_values(
            array(
                'exclude_changeset' => true,
                'exclude_post_data' => false,
            )
        );
        $this->add_dynamic_settings( array_keys( $post_values ) ); // Ensure settings get created even if they lack an input value.
        /* * Get list of IDs for settings that have values different from what is currently * saved in the changeset. By skipping any values that are already the same, the * subset of changed settings can be passed into validate_setting_values to prevent * an underprivileged modifying a single setting for which they have the capability * from being blocked from saving. This also prevents a user from touching of the * previous saved settings and overriding the associated user_id if they made no change. */
        $changed_setting_ids = array();
        foreach ( $post_values as $setting_id => $setting_value ) {
            

    public function customize_register() {
        $changeset = $this->manager->unsanitized_post_values();

        // Preview settings for nav menus early so that the sections and controls will be added properly.         $nav_menus_setting_ids = array();
        foreach ( array_keys( $changeset ) as $setting_id ) {
            if ( preg_match( '/^(nav_menu_locations|nav_menu|nav_menu_item)\[/', $setting_id ) ) {
                $nav_menus_setting_ids[] = $setting_id;
            }
        }
        $settings = $this->manager->add_dynamic_settings( $nav_menus_setting_ids );
        if ( $this->manager->settings_previewed() ) {
            foreach ( $settings as $setting ) {
                $setting->preview();
            }
        }

        // Require JS-rendered control types.         $this->manager->register_panel_type( 'WP_Customize_Nav_Menus_Panel' );
        $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Control' );
        $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Name_Control' );
        $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Locations_Control' );
        
Home | Imprint | This part of the site doesn't use cookies.