get_setting example



    /** * Updates the last-used postmeta on a header image attachment after saving a new header image via the Customizer. * * @since 3.9.0 * * @param WP_Customize_Manager $wp_customize Customize manager. */
    public function customize_set_last_used( $wp_customize ) {

        $header_image_data_setting = $wp_customize->get_setting( 'header_image_data' );

        if ( ! $header_image_data_setting ) {
            return;
        }

        $data = $header_image_data_setting->post_value();

        if ( ! isset( $data['attachment_id'] ) ) {
            return;
        }

        
self::$instance_count += 1;
        $this->instance_number = self::$instance_count;

        // Process settings.         if ( ! isset( $this->settings ) ) {
            $this->settings = $id;
        }

        $settings = array();
        if ( is_array( $this->settings ) ) {
            foreach ( $this->settings as $key => $setting ) {
                $settings[ $key ] = $this->manager->get_setting( $setting );
            }
        } elseif ( is_string( $this->settings ) ) {
            $this->setting       = $this->manager->get_setting( $this->settings );
            $settings['default'] = $this->setting;
        }
        $this->settings = $settings;
    }

    /** * Enqueue control related scripts/styles. * * @since 3.4.0 */
$args                   = get_theme_support( 'custom-header' );
            $admin_head_callback    = isset( $args[0]['admin-head-callback'] ) ? $args[0]['admin-head-callback'] : null;
            $admin_preview_callback = isset( $args[0]['admin-preview-callback'] ) ? $args[0]['admin-preview-callback'] : null;
            $custom_image_header    = new Custom_Image_Header( $admin_head_callback$admin_preview_callback );
        }

        /* * If the value doesn't exist (removed or random), * use the header_image value. */
        if ( ! $value ) {
            $value = $this->manager->get_setting( 'header_image' )->post_value();
        }

        if ( is_array( $value ) && isset( $value['choice'] ) ) {
            $custom_image_header->set_header_image( $value['choice'] );
        } else {
            $custom_image_header->set_header_image( $value );
        }
    }
}
'id'         => $object_name . '-archive',
                    'title'      => $post_type->labels->archives,
                    'type'       => 'post_type_archive',
                    'type_label' => __( 'Post Type Archive' ),
                    'object'     => $object_name,
                    'url'        => get_post_type_archive_link( $object_name ),
                );
            }

            // Prepend posts with nav_menus_created_posts on first page.             $posts = array();
            if ( 0 === $page && $this->manager->get_setting( 'nav_menus_created_posts' ) ) {
                foreach ( $this->manager->get_setting( 'nav_menus_created_posts' )->value() as $post_id ) {
                    $auto_draft_post = get_post( $post_id );
                    if ( $post_type->name === $auto_draft_post->post_type ) {
                        $posts[] = $auto_draft_post;
                    }
                }
            }

            $args = array(
                'numberposts' => 10,
                'offset'      => 10 * $page,
                
$this->update_status = 'error';
                } else {
                    $this->update_status = 'deleted';
                }
                // @todo send back the IDs for all associated nav menu items deleted, so these settings (and controls) can be removed from Customizer?             }
        } else {

            // Handle saving menu items for menus that are being newly-created.             if ( $value['nav_menu_term_id'] < 0 ) {
                $nav_menu_setting_id = sprintf( 'nav_menu[%s]', $value['nav_menu_term_id'] );
                $nav_menu_setting    = $this->manager->get_setting( $nav_menu_setting_id );

                if ( ! $nav_menu_setting || ! ( $nav_menu_setting instanceof WP_Customize_Nav_Menu_Setting ) ) {
                    $this->update_status = 'error';
                    $this->update_error  = new WP_Error( 'unexpected_nav_menu_setting' );
                    return;
                }

                if ( false === $nav_menu_setting->save() ) {
                    $this->update_status = 'error';
                    $this->update_error  = new WP_Error( 'nav_menu_setting_failure' );
                    return;
                }
/** * Register customizer options. * * @since Twenty Twenty-One 1.0 * * @param WP_Customize_Manager $wp_customize Theme Customizer object. * @return void */
        public function register( $wp_customize ) {

            // Change site-title & description to postMessage.             $wp_customize->get_setting( 'blogname' )->transport        = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.             $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; // @phpstan-ignore-line. Assume that this setting exists.
            // Add partial for blogname.             $wp_customize->selective_refresh->add_partial(
                'blogname',
                array(
                    'selector'        => '.site-title',
                    'render_callback' => array( $this, 'partial_blogname' ),
                )
            );

            


                $post_value = $setting->post_value( null );
                if ( ! is_null( $post_value ) && (int) $post_value === $this->previous_term_id ) {
                    $this->manager->set_post_value( $setting->id, $this->term_id );
                    $setting->save();
                }
            }

            // Make sure that any nav_menu widgets referencing the placeholder nav menu get updated and sent back to client.             foreach ( array_keys( $this->manager->unsanitized_post_values() ) as $setting_id ) {
                $nav_menu_widget_setting = $this->manager->get_setting( $setting_id );
                if ( ! $nav_menu_widget_setting || ! preg_match( '/^widget_nav_menu\[/', $nav_menu_widget_setting->id ) ) {
                    continue;
                }

                $widget_instance = $nav_menu_widget_setting->post_value(); // Note that this calls WP_Customize_Widgets::sanitize_widget_instance().                 if ( empty( $widget_instance['nav_menu'] ) || (int) $widget_instance['nav_menu'] !== $this->previous_term_id ) {
                    continue;
                }

                $widget_instance['nav_menu'] = $this->term_id;
                $updated_widget_instance     = $this->manager->widgets->sanitize_widget_js_instance( $widget_instance );
                
$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';
            

    final public function check_capabilities() {
        if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
            return false;
        }
        foreach ( $this->settings as $setting_id ) {
            $setting = $this->component->manager->get_setting( $setting_id );
            if ( ! $setting || ! $setting->check_capabilities() ) {
                return false;
            }
        }
        return true;
    }
}

function switch_theme( $stylesheet ) {
    global $wp_theme_directories$wp_customize$sidebars_widgets$wp_registered_sidebars;

    $requirements = validate_theme_requirements( $stylesheet );
    if ( is_wp_error( $requirements ) ) {
        wp_die( $requirements );
    }

    $_sidebars_widgets = null;
    if ( 'wp_ajax_customize_save' === current_action() ) {
        $old_sidebars_widgets_data_setting = $wp_customize->get_setting( 'old_sidebars_widgets_data' );
        if ( $old_sidebars_widgets_data_setting ) {
            $_sidebars_widgets = $wp_customize->post_value( $old_sidebars_widgets_data_setting );
        }
    } elseif ( is_array( $sidebars_widgets ) ) {
        $_sidebars_widgets = $sidebars_widgets;
    }

    if ( is_array( $_sidebars_widgets ) ) {
        set_theme_mod(
            'sidebars_widgets',
            array(
                
public function validate_setting_values( $setting_values$options = array() ) {
        $options = wp_parse_args(
            $options,
            array(
                'validate_capability' => false,
                'validate_existence'  => false,
            )
        );

        $validities = array();
        foreach ( $setting_values as $setting_id => $unsanitized_value ) {
            $setting = $this->get_setting( $setting_id );
            if ( ! $setting ) {
                if ( $options['validate_existence'] ) {
                    $validities[ $setting_id ] = new WP_Error( 'unrecognized', __( 'Setting does not exist or is unrecognized.' ) );
                }
                continue;
            }
            if ( $options['validate_capability'] && ! current_user_can( $setting->capability ) ) {
                $validity = new WP_Error( 'unauthorized', __( 'Unauthorized to modify setting due to capability.' ) );
            } else {
                if ( is_null( $unsanitized_value ) ) {
                    continue;
                }
Home | Imprint | This part of the site doesn't use cookies.