get_param example


    public function create_item_permissions_check( $request ) {
        $id = $request->get_param( 'id' );

        if ( empty( $id ) ) {
            return new WP_Error(
                'rest_post_invalid_id',
                __( 'Invalid item ID.' ),
                array( 'status' => 404 )
            );
        }

        return $this->parent_controller->update_item_permissions_check( $request );
    }

    
/** * Set the API key, if possible. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */
    public static function set_key( $request ) {
        if ( defined( 'WPCOM_API_KEY' ) ) {
            return rest_ensure_response( new WP_Error( 'hardcoded_key', __( 'This site\'s API key is hardcoded and cannot be changed via the API.', 'akismet' ), array( 'status'=> 409 ) ) );
        }

        $new_api_key = $request->get_param( 'key' );

        if ( ! self::key_is_valid( $new_api_key ) ) {
            return rest_ensure_response( new WP_Error( 'invalid_key', __( 'The value provided is not a valid and registered API key.', 'akismet' ), array( 'status' => 400 ) ) );
        }

        update_option( 'wordpress_api_key', $new_api_key );

        return self::get_key();
    }

    /** * Unset the API key, if possible. * * @param WP_REST_Request $request * @return WP_Error|WP_REST_Response */


    /** * Gets the search handler to handle the current request. * * @since 5.0.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Search_Handler|WP_Error Search handler for the request type, or WP_Error object on failure. */
    protected function get_search_handler( $request ) {
        $type = $request->get_param( self::PROP_TYPE );

        if ( ! $type || ! isset( $this->search_handlers[ $type ] ) ) {
            return new WP_Error(
                'rest_search_invalid_type',
                __( 'Invalid type parameter.' ),
                array( 'status' => 400 )
            );
        }

        return $this->search_handlers[ $type ];
    }
}
if ( null === $registered || ! $registered->is_dynamic() ) {
            return new WP_Error(
                'block_invalid',
                __( 'Invalid block.' ),
                array(
                    'status' => 404,
                )
            );
        }

        $attributes = $request->get_param( 'attributes' );

        // Create an array representation simulating the output of parse_blocks.         $block = array(
            'blockName'    => $request['name'],
            'attrs'        => $attributes,
            'innerHTML'    => '',
            'innerContent' => array(),
        );

        // Render using render_block to ensure all relevant filters are used.         $data = array(
            
        $json_error = $this->parse_json_params();
        if ( is_wp_error( $json_error ) ) {
            return $json_error;
        }

        $attributes = $this->get_attributes();
        $required   = array();

        $args = empty( $attributes['args'] ) ? array() : $attributes['args'];

        foreach ( $args as $key => $arg ) {
            $param = $this->get_param( $key );
            if ( isset( $arg['required'] ) && true === $arg['required'] && null === $param ) {
                $required[] = $key;
            }
        }

        if ( ! empty( $required ) ) {
            return new WP_Error(
                'rest_missing_callback_param',
                /* translators: %s: List of required parameters. */
                sprintf( __( 'Missing parameter(s): %s' )implode( ', ', $required ) ),
                array(
                    
Home | Imprint | This part of the site doesn't use cookies.