add_setting example

$new_setting_ids = array();

        /* * Register a setting for all widgets, including those which are active, * inactive, and orphaned since a widget may get suppressed from a sidebar * via a plugin (like Widget Visibility). */
        foreach ( array_keys( $wp_registered_widgets ) as $widget_id ) {
            $setting_id   = $this->get_setting_id( $widget_id );
            $setting_args = $this->get_setting_args( $setting_id );
            if ( ! $this->manager->get_setting( $setting_id ) ) {
                $this->manager->add_setting( $setting_id$setting_args );
            }
            $new_setting_ids[] = $setting_id;
        }

        /* * Add a setting which will be supplied for the theme's sidebars_widgets * theme_mod when the theme is switched. */
        if ( ! $this->manager->is_theme_active() ) {
            $setting_id   = 'old_sidebars_widgets_data';
            $setting_args = $this->get_setting_args(
                
// Add partial for blogdescription.             $wp_customize->selective_refresh->add_partial(
                'blogdescription',
                array(
                    'selector'        => '.site-description',
                    'render_callback' => array( $this, 'partial_blogdescription' ),
                )
            );

            // Add "display_title_and_tagline" setting for displaying the site-title & tagline.             $wp_customize->add_setting(
                'display_title_and_tagline',
                array(
                    'capability'        => 'edit_theme_options',
                    'default'           => true,
                    'sanitize_callback' => array( __CLASS__, 'sanitize_checkbox' ),
                )
            );

            // Add control for the "display_title_and_tagline" setting.             $wp_customize->add_control(
                'display_title_and_tagline',
                


        foreach ( $locations as $location => $description ) {
            $setting_id = "nav_menu_locations[{$location}]";

            $setting = $this->manager->get_setting( $setting_id );
            if ( $setting ) {
                $setting->transport = 'postMessage';
                remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
                add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
            } else {
                $this->manager->add_setting(
                    $setting_id,
                    array(
                        'sanitize_callback' => array( $this, 'intval_base10' ),
                        'theme_supports'    => 'menus',
                        'type'              => 'theme_mod',
                        'transport'         => 'postMessage',
                        'default'           => 0,
                    )
                );
            }

            

    public function customizer_controls( $wp_customize ) {

        $colors_section = $wp_customize->get_section( 'colors' );
        if ( is_object( $colors_section ) ) {
            $colors_section->title = __( 'Colors & Dark Mode', 'twentytwentyone' );
        }

        // Custom notice control.         require_once get_theme_file_path( 'classes/class-twenty-twenty-one-customize-notice-control.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
        $wp_customize->add_setting(
            'respect_user_color_preference_notice',
            array(
                'capability'        => 'edit_theme_options',
                'default'           => '',
                'sanitize_callback' => '__return_empty_string',
            )
        );

        $wp_customize->add_control(
            new Twenty_Twenty_One_Customize_Notice_Control(
                $wp_customize,
                

            $setting_class = apply_filters( 'customize_dynamic_setting_class', $setting_class$setting_id$setting_args );

            $setting = new $setting_class( $this$setting_id$setting_args );

            $this->add_setting( $setting );
            $new_settings[] = $setting;
        }
        return $new_settings;
    }

    /** * Retrieves a customize setting. * * @since 3.4.0 * * @param string $id Customize Setting ID. * @return WP_Customize_Setting|void The setting, if set. */
Home | Imprint | This part of the site doesn't use cookies.