get_attributes example

/** * Sanitizes (where possible) the params on the request. * * This is primarily based off the sanitize_callback param on each registered * argument. * * @since 4.4.0 * * @return true|WP_Error True if parameters were sanitized, WP_Error if an error occurred during sanitization. */
    public function sanitize_params() {
        $attributes = $this->get_attributes();

        // No arguments set, skip sanitizing.         if ( empty( $attributes['args'] ) ) {
            return true;
        }

        $order = $this->get_parameter_order();

        $invalid_params  = array();
        $invalid_details = array();

        

    public static function normalize_cookies( $cookies ) {
        $cookie_jar = new WpOrg\Requests\Cookie\Jar();

        foreach ( $cookies as $name => $value ) {
            if ( $value instanceof WP_Http_Cookie ) {
                $attributes                 = array_filter(
                    $value->get_attributes(),
                    static function( $attr ) {
                        return null !== $attr;
                    }
                );
                $cookie_jar[ $value->name ] = new WpOrg\Requests\Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
            } elseif ( is_scalar( $value ) ) {
                $cookie_jar[ $name ] = new WpOrg\Requests\Cookie( $name(string) $value );
            }
        }

        return $cookie_jar;
    }

    public function prepare_item_for_response( $item$request ) {
        // Restores the more descriptive, specific name for use within this method.         $block_type = $item;
        $fields     = $this->get_fields_for_response( $request );
        $data       = array();

        if ( rest_is_field_included( 'attributes', $fields ) ) {
            $data['attributes'] = $block_type->get_attributes();
        }

        if ( rest_is_field_included( 'is_dynamic', $fields ) ) {
            $data['is_dynamic'] = $block_type->is_dynamic();
        }

        $schema = $this->get_item_schema();
        // Fields deprecated in WordPress 6.1, but left in the schema for backwards compatibility.         $deprecated_fields = array(
            'editor_script',
            'script',
            
'default'           => array(),
                            'validate_callback' => static function D $value$request ) {
                                $block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] );

                                if ( ! $block ) {
                                    // This will get rejected in ::get_item().                                     return true;
                                }

                                $schema = array(
                                    'type'                 => 'object',
                                    'properties'           => $block->get_attributes(),
                                    'additionalProperties' => false,
                                );

                                return rest_validate_value_from_schema( $value$schema );
                            },
                            'sanitize_callback' => static function D $value$request ) {
                                $block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] );

                                if ( ! $block ) {
                                    // This will get rejected in ::get_item().                                     return true;
                                }
/** * Validate a request argument based on details registered to the route. * * @since 4.7.0 * * @param mixed $value * @param WP_REST_Request $request * @param string $param * @return true|WP_Error */
function rest_validate_request_arg( $value$request$param ) {
    $attributes = $request->get_attributes();
    if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
        return true;
    }
    $args = $attributes['args'][ $param ];

    return rest_validate_value_from_schema( $value$args$param );
}

/** * Sanitize a request argument based on details registered to the route. * * @since 4.7.0 * * @param mixed $value * @param WP_REST_Request $request * @param string $param * @return mixed */

    public function check_status( $status$request$param ) {
        if ( $request['id'] ) {
            $post = $this->get_post( $request['id'] );

            if ( ! is_wp_error( $post ) && $post->post_status === $status ) {
                return true;
            }
        }

        $args = $request->get_attributes()['args'][ $param ];

        return rest_validate_value_from_schema( $status$args$param );
    }

    /** * Determines validity and normalizes the given status parameter. * * @since 4.7.0 * * @param string $post_status Post status. * @param WP_Post_Type $post_type Post type. * @return string|WP_Error Post status or WP_Error if lacking the proper permission. */
Home | Imprint | This part of the site doesn't use cookies.