get_data example

return new WP_Error(
                'rest_cannot_delete',
                __( 'The post cannot be deleted.' ),
                array( 'status' => 500 )
            );
        }

        $response = new WP_REST_Response();
        $response->set_data(
            array(
                'deleted'  => true,
                'previous' => $previous->get_data(),
            )
        );
        return $response;
    }

    /** * Determines the allowed query_vars for a get_items() response and prepares * them for WP_Query. * * @since 5.0.0 * * @param array $prepared_args Optional. Prepared WP_Query arguments. Default empty array. * @param WP_REST_Request $request Optional. Full details about the request. * @return array Items query arguments. */
$zip->addFromString(
            'parts/' . $template_part->slug . '.html',
            $template_part->content
        );
    }

    // Load theme.json into the zip file.     $tree = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) );
    // Merge with user data.     $tree->merge( WP_Theme_JSON_Resolver::get_user_data() );

    $theme_json_raw = $tree->get_data();
    // If a version is defined, add a schema.     if ( $theme_json_raw['version'] ) {
        $theme_json_version = 'wp/' . substr( $wp_version, 0, 3 );
        $schema             = array( '$schema' => 'https://schemas.wp.org/' . $theme_json_version . '/theme.json' );
        $theme_json_raw     = array_merge( $schema$theme_json_raw );
    }

    // Convert to a string.     $theme_json_encoded = wp_json_encode( $theme_json_raw, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );

    // Replace 4 spaces with a tab.
        foreach ($encodings as $encoding)
        {
            // Change the encoding to UTF-8 (as we always use UTF-8 internally)             if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
            {
                // Create new parser                 $parser = $this->registry->create('Parser');

                // If it's parsed fine                 if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url))
                {
                    $this->data = $parser->get_data();
                    if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
                    {
                        $this->error = "A feed could not be found at `$this->feed_url`. This does not appear to be a valid RSS or Atom feed.";
                        $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
                        return false;
                    }

                    if (isset($headers))
                    {
                        $this->data['headers'] = $headers;
                    }
                    
return new WP_Error(
                'rest_cannot_delete',
                __( 'The term cannot be deleted.' ),
                array( 'status' => 500 )
            );
        }

        $response = new WP_REST_Response();
        $response->set_data(
            array(
                'deleted'  => true,
                'previous' => $previous->get_data(),
            )
        );

        /** * Fires after a single term is deleted via the REST API. * * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug. * * Possible hook names include: * * - `rest_delete_category` * - `rest_delete_post_tag` * * @since 4.7.0 * * @param WP_Term $term The deleted term. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */

    $should_load_remote = apply_filters( 'should_load_remote_block_patterns', true );

    if ( $supports_core_patterns && $should_load_remote ) {
        $request         = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
        $core_keyword_id = 11; // 11 is the ID for "core".         $request->set_param( 'keyword', $core_keyword_id );
        $response = rest_do_request( $request );
        if ( $response->is_error() ) {
            return;
        }
        $patterns = $response->get_data();

        foreach ( $patterns as $pattern ) {
            $pattern['source']  = 'pattern-directory/core';
            $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
            $pattern_name       = 'core/' . sanitize_title( $normalized_pattern['title'] );
            register_block_pattern( $pattern_name$normalized_pattern );
        }
    }
}

/** * Register `Featured` (category) patterns from wordpress.org/patterns. * * @since 5.9.0 * @since 6.2.0 Normalized the pattern from the API (snake_case) to the * format expected by `register_block_pattern()` (camelCase). * @since 6.3.0 Add 'pattern-directory/featured' to the pattern's 'source'. */
return $supports_input;
}

/** * Prints default Plupload arguments. * * @since 3.4.0 */
function wp_plupload_default_settings() {
    $wp_scripts = wp_scripts();

    $data = $wp_scripts->get_data( 'wp-plupload', 'data' );
    if ( $data && str_contains( $data, '_wpPluploadSettings' ) ) {
        return;
    }

    $max_upload_size    = wp_max_upload_size();
    $allowed_extensions = array_keys( get_allowed_mime_types() );
    $extensions         = array();
    foreach ( $allowed_extensions as $extension ) {
        $extensions = array_merge( $extensionsexplode( '|', $extension ) );
    }

    
$deleted  = delete_plugins( array( $request['plugin'] ) );

        if ( is_wp_error( $deleted ) ) {
            $deleted->add_data( array( 'status' => 500 ) );

            return $deleted;
        }

        return new WP_REST_Response(
            array(
                'deleted'  => true,
                'previous' => $prepared->get_data(),
            )
        );
    }

    /** * Prepares the plugin for the REST response. * * @since 5.5.0 * * @param array $item Unmarked up and untranslated plugin data from {@see get_plugin_data()}. * @param WP_REST_Request $request Request object. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */

    public function prepare_item_for_response( $term$request ) {
        $nav_menu = wp_get_nav_menu_object( $term );
        $response = parent::prepare_item_for_response( $nav_menu$request );

        $fields = $this->get_fields_for_response( $request );
        $data   = $response->get_data();

        if ( rest_is_field_included( 'locations', $fields ) ) {
            $data['locations'] = $this->get_menu_locations( $nav_menu->term_id );
        }

        if ( rest_is_field_included( 'auto_add', $fields ) ) {
            $data['auto_add'] = $this->get_menu_auto_add( $nav_menu->term_id );
        }

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

        // If we're forcing, then delete permanently.         if ( $force ) {
            $previous = $this->prepare_item_for_response( $template$request );
            $result   = wp_delete_post( $id, true );
            $response = new WP_REST_Response();
            $response->set_data(
                array(
                    'deleted'  => true,
                    'previous' => $previous->get_data(),
                )
            );
        } else {
            // Otherwise, only trash if we haven't already.             if ( 'trash' === $template->status ) {
                return new WP_Error(
                    'rest_template_already_trashed',
                    __( 'The template has already been deleted.' ),
                    array( 'status' => 410 )
                );
            }

            
'isCrossDomain' => $cross_domain,
        'browser'       => $browser,
        'l10n'          => array(
            'saveAlert'       => __( 'The changes you made will be lost if you navigate away from this page.' ),
            'mainIframeTitle' => __( 'Customizer' ),
        ),
    );

    $script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';';

    $wp_scripts = wp_scripts();
    $data       = $wp_scripts->get_data( 'customize-loader', 'data' );
    if ( $data ) {
        $script = "$data\n$script";
    }

    $wp_scripts->add_data( 'customize-loader', 'data', $script );
}

/** * Returns a URL to load the Customizer. * * @since 3.4.0 * * @param string $stylesheet Optional. Theme to customize. Defaults to active theme. * The theme's stylesheet will be urlencoded if necessary. * @return string */
if ( $response instanceof WP_REST_Response ) {
        return $response;
    }

    /* * While WP_HTTP_Response is the base class of WP_REST_Response, it doesn't provide * all the required methods used in WP_REST_Server::dispatch(). */
    if ( $response instanceof WP_HTTP_Response ) {
        return new WP_REST_Response(
            $response->get_data(),
            $response->get_status(),
            $response->get_headers()
        );
    }

    return new WP_REST_Response( $response );
}

/** * Handles _deprecated_function() errors. * * @since 4.4.0 * * @param string $function_name The function that was called. * @param string $replacement The function that should have been called. * @param string $version Version. */

    public function as_error() {
        if ( ! $this->is_error() ) {
            return null;
        }

        $error = new WP_Error();

        if ( is_array( $this->get_data() ) ) {
            $data = $this->get_data();
            $error->add( $data['code']$data['message']$data['data'] );

            if ( ! empty( $data['additional_errors'] ) ) {
                foreach ( $data['additional_errors'] as $err ) {
                    $error->add( $err['code']$err['message']$err['data'] );
                }
            }
        } else {
            $error->add( $this->get_status(), '', array( 'status' => $this->get_status() ) );
        }

        
$config = static::read_json_file( __DIR__ . '/theme.json' );
        $config = static::translate( $config );

        /** * Filters the default data provided by WordPress for global styles & settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */
        $theme_json   = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) );
        $config       = $theme_json->get_data();
        static::$core = new WP_Theme_JSON( $config, 'default' );

        return static::$core;
    }

    /** * Checks whether the registered blocks were already processed for this origin. * * @since 6.1.0 * * @param string $origin Data source for which to cache the blocks. * Valid values are 'core', 'blocks', 'theme', and 'user'. * @return bool True on success, false otherwise. */

    public function response_to_data( $response$embed ) {
        $data  = $response->get_data();
        $links = self::get_compact_response_links( $response );

        if ( ! empty( $links ) ) {
            // Convert links to part of the data.             $data['_links'] = $links;
        }

        if ( $embed ) {
            $this->embed_cache = array();
            // Determine if this is a numeric array.             if ( wp_is_numeric_array( $data ) ) {
                
/** * Converts the object to a WP_Http response array. * * @since 4.6.0 * * @return array WP_Http response array, per WP_Http::request(). */
    public function to_array() {
        return array(
            'headers'  => $this->get_headers(),
            'body'     => $this->get_data(),
            'response' => array(
                'code'    => $this->get_status(),
                'message' => get_status_header_desc( $this->get_status() ),
            ),
            'cookies'  => $this->get_cookies(),
            'filename' => $this->filename,
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.