get_settings example

$field_name = trim( $field_name, '-' );

        return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
    }

    /** * Register all widget instances of this widget class. * * @since 2.8.0 */
    public function _register() {
        $settings = $this->get_settings();
        $empty    = true;

        // When $settings is an array-like object, get an intrinsic array for use with array_keys().         if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) {
            $settings = $settings->getArrayCopy();
        }

        if ( is_array( $settings ) ) {
            foreach ( array_keys( $settings ) as $number ) {
                if ( is_numeric( $number ) ) {
                    $this->_set( $number );
                    

    public function display_media_state( $states$post = null ) {
        if ( ! $post ) {
            $post = get_post();
        }

        // Count how many times this attachment is used in widgets.         $use_count = 0;
        foreach ( $this->get_settings() as $instance ) {
            if ( isset( $instance['attachment_id'] ) && $instance['attachment_id'] === $post->ID ) {
                $use_count++;
            }
        }

        if ( 1 === $use_count ) {
            $states[] = $this->l10n['media_library_state_single'];
        } elseif ( $use_count > 0 ) {
            $states[] = sprintf( translate_nooped_plural( $this->l10n['media_library_state_multi']$use_count )number_format_i18n( $use_count ) );
        }

        
    $registered_webfonts = array();

    /** * Gets the webfonts from theme.json. * * @since 6.0.0 * * @return array Array of defined webfonts. */
    $fn_get_webfonts_from_theme_json = static function() {
        // Get settings from theme.json.         $settings = WP_Theme_JSON_Resolver::get_merged_data()->get_settings();

        // If in the editor, add webfonts defined in variations.         if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
            $variations = WP_Theme_JSON_Resolver::get_style_variations();
            foreach ( $variations as $variation ) {
                // Skip if fontFamilies are not defined in the variation.                 if ( empty( $variation['settings']['typography']['fontFamilies'] ) ) {
                    continue;
                }

                // Initialize the array structure.
'rest_theme_not_found',
                __( 'Theme not found.' ),
                array( 'status' => 404 )
            );
        }

        $theme  = WP_Theme_JSON_Resolver::get_merged_data( 'theme' );
        $data   = array();
        $fields = $this->get_fields_for_response( $request );

        if ( rest_is_field_included( 'settings', $fields ) ) {
            $data['settings'] = $theme->get_settings();
        }

        if ( rest_is_field_included( 'styles', $fields ) ) {
            $raw_data       = $theme->get_raw_data();
            $data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array();
        }

        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
        $data    = $this->add_additional_fields_to_object( $data$request );
        $data    = $this->filter_response_by_context( $data$context );

        

    $can_use_cached = ! wp_is_development_mode( 'theme' );

    $settings = false;
    if ( $can_use_cached ) {
        $settings = wp_cache_get( $cache_key$cache_group );
    }

    if ( false === $settings ) {
        $settings = WP_Theme_JSON_Resolver::get_merged_data( $origin )->get_settings();
        if ( $can_use_cached ) {
            wp_cache_set( $cache_key$settings$cache_group );
        }
    }

    return _wp_array_get( $settings$path$settings );
}

/** * Gets the styles resulting of merging core, theme, and user data. * * @since 5.9.0 * @since 6.3.0 the internal link format "var:preset|color|secondary" is resolved * to "var(--wp--preset--font-size--small)" so consumers don't have to. * @since 6.3.0 `transforms` is now usable in the `context` parameter. In case [`transforms`]['resolve_variables'] * is defined, variables are resolved to their value in the styles. * * @param array $path Path to the specific style to retrieve. Optional. * If empty, will return all styles. * @param array $context { * Metadata to know where to retrieve the $path from. Optional. * * @type string $block_name Which block to retrieve the styles from. * If empty, it'll return the styles for the global context. * @type string $origin Which origin to take data from. * Valid values are 'all' (core, theme, and user) or 'base' (core and theme). * If empty or unknown, 'all' is used. * @type array $transforms Which transformation(s) to apply. * Valid value is array( 'resolve-variables' ). * If defined, variables are resolved to their value in the styles. * } * @return mixed The styles array or individual style value to retrieve. */
                continue;
            }

            // From 4.7+, WP core will ensure that these are always boolean             // values because they are registered with 'type' => 'boolean',             // but we need to do this ourselves for prior versions.             $setting_value = Akismet_REST_API::parse_boolean( $setting_value );

            update_option( $setting_key$setting_value ? '1' : '0' );
        }

        return self::get_settings();
    }

    /** * Parse a numeric or string boolean value into a boolean. * * @param mixed $value The value to convert into a boolean. * @return bool The converted value. */
    public static function parse_boolean( $value ) {
        switch ( $value ) {
            case true:
            
if ( rest_is_field_included( 'rendered_form', $fields ) ) {
            $rendered_form = wp_render_widget_control( $widget_id );
            if ( ! is_null( $rendered_form ) ) {
                $prepared['rendered_form'] = trim( $rendered_form );
            }
        }

        if ( rest_is_field_included( 'instance', $fields ) ) {
            $widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] );
            if ( $widget_object && isset( $parsed_id['number'] ) ) {
                $all_instances                   = $widget_object->get_settings();
                $instance                        = $all_instances[ $parsed_id['number'] ];
                $serialized_instance             = serialize( $instance );
                $prepared['instance']['encoded'] = base64_encode( $serialized_instance );
                $prepared['instance']['hash']    = wp_hash( $serialized_instance );

                if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
                    // Use new stdClass so that JSON result is {} and not [].                     $prepared['instance']['raw'] = empty( $instance ) ? new stdClass() : $instance;
                }
            }
        }

        


    /** * Resolves the values of CSS variables in the given styles. * * @since 6.3.0 * @param WP_Theme_JSON $theme_json The theme json resolver. * * @return WP_Theme_JSON The $theme_json with resolved variables. */
    public static function resolve_variables( $theme_json ) {
        $settings    = $theme_json->get_settings();
        $styles      = $theme_json->get_raw_data()['styles'];
        $preset_vars = static::compute_preset_vars( $settingsstatic::VALID_ORIGINS );
        $theme_vars  = static::compute_theme_vars( $settings );
        $vars        = array_reduce(
            array_merge( $preset_vars$theme_vars ),
            function( $carry$item ) {
                $name                    = $item['name'];
                $carry[ "var({$name})" ] = $item['value'];
                return $carry;
            },
            array()
        );
Home | Imprint | This part of the site doesn't use cookies.