get_params example


    public function get_proxy_item( $request ) {
        global $wp_embed$wp_scripts;

        $args = $request->get_params();

        // Serve oEmbed data from cache if set.         unset( $args['_wpnonce'] );
        $cache_key = 'oembed_' . md5( serialize( $args ) );
        $data      = get_transient( $cache_key );
        if ( ! empty( $data ) ) {
            return $data;
        }

        $url = $request['url'];
        unset( $args['url'] );

        
require ABSPATH . WPINC . '/version.php';

        $valid_query_args = array(
            'offset'   => true,
            'order'    => true,
            'orderby'  => true,
            'page'     => true,
            'per_page' => true,
            'search'   => true,
            'slug'     => true,
        );
        $query_args       = array_intersect_key( $request->get_params()$valid_query_args );

        $query_args['locale']             = get_user_locale();
        $query_args['wp-version']         = $wp_version; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- it's defined in `version.php` above.         $query_args['pattern-categories'] = isset( $request['category'] ) ? $request['category'] : false;
        $query_args['pattern-keywords']   = isset( $request['keyword'] ) ? $request['keyword'] : false;

        $query_args = array_filter( $query_args );

        $transient_key = $this->get_transient_key( $query_args );

        /* * Use network-wide transient to improve performance. The locale is the only site * configuration that affects the response, and it's included in the transient key. */
/** * Updates settings for the settings object. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return array|WP_Error Array on success, or error object on failure. */
    public function update_item( $request ) {
        $options = $this->get_registered_options();

        $params = $request->get_params();

        foreach ( $options as $name => $args ) {
            if ( ! array_key_exists( $name$params ) ) {
                continue;
            }

            /** * Filters whether to preempt a setting value update via the REST API. * * Allows hijacking the setting update logic and overriding the built-in behavior by * returning true. * * @since 4.7.0 * * @param bool $result Whether to override the default behavior for updating the * value of a setting. * @param string $name Setting name (as shown in REST API responses). * @param mixed $value Updated setting value. * @param array $args Arguments passed to register_setting() for this setting. */


        if ( ! empty( $request['roles'] ) ) {
            if ( ! current_user_can( 'promote_user', $user->ID ) ) {
                return new WP_Error(
                    'rest_cannot_edit_roles',
                    __( 'Sorry, you are not allowed to edit roles of this user.' ),
                    array( 'status' => rest_authorization_required_code() )
                );
            }

            $request_params = array_keys( $request->get_params() );
            sort( $request_params );
            /* * If only 'id' and 'roles' are specified (we are only trying to * edit roles), then only the 'promote_user' cap is required. */
            if ( array( 'id', 'roles' ) === $request_params ) {
                return true;
            }
        }

        if ( ! current_user_can( 'edit_user', $user->ID ) ) {
            

function _oembed_rest_pre_serve_request( $served$result$request$server ) {
    $params = $request->get_params();

    if ( '/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method() ) {
        return $served;
    }

    if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) {
        return $served;
    }

    // Embed links inside the request.     $data = $server->response_to_data( $result, false );

    
Home | Imprint | This part of the site doesn't use cookies.