set_param example

return $meta_update;
            }
        }

        $attachment    = get_post( $attachment_id );
        $fields_update = $this->update_additional_fields_for_object( $attachment$request );

        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        $request->set_param( 'context', 'edit' );

        /** * Fires after a single attachment is completely created or updated via the REST API. * * @since 5.0.0 * * @param WP_Post $attachment Inserted or updated attachment object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating an attachment, false when updating. */
        do_action( 'rest_after_insert_attachment', $attachment$request, true );

        
return $meta_update;
            }
        }

        $user          = get_user_by( 'id', $user_id );
        $fields_update = $this->update_additional_fields_for_object( $user$request );

        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        $request->set_param( 'context', 'edit' );

        /** * Fires after a user is completely created or updated via the REST API. * * @since 5.0.0 * * @param WP_User $user Inserted or updated user object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a user, false when updating. */
        do_action( 'rest_after_insert_user', $user$request, true );

        
if ( is_wp_error( $meta_update ) ) {
                return $meta_update;
            }
        }

        $fields_update = $this->update_additional_fields_for_object( $term$request );

        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        $request->set_param( 'context', 'edit' );

        /** * Fires after a single term is completely created or updated via the REST API. * * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug. * * Possible hook names include: * * - `rest_after_insert_category` * - `rest_after_insert_post_tag` * * @since 5.0.0 * * @param WP_Term $term Inserted or updated term object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a term, false when updating. */
/** * Sets a parameter on the request. * * @since 4.4.0 * * @param string $offset Parameter name. * @param mixed $value Parameter value. */
    #[ReturnTypeWillChange]     public function offsetSet( $offset$value ) {
        $this->set_param( $offset$value );
    }

    /** * Removes a parameter from the request. * * @since 4.4.0 * * @param string $offset Parameter name. */
    #[ReturnTypeWillChange]     public function offsetUnset( $offset ) {
        
/** * Fires after a single application password is completely created or updated via the REST API. * * @since 5.6.0 * * @param array $item Inserted or updated password item. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating an application password, false when updating. */
        do_action( 'rest_after_insert_application_password', $item$request, true );

        $request->set_param( 'context', 'edit' );
        $response = $this->prepare_item_for_response( $item$request );

        $response->set_status( 201 );
        $response->header( 'Location', $response->get_links()['self'][0]['href'] );

        return $response;
    }

    /** * Checks if a given request has access to update application passwords. * * @since 5.6.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. */

    public function update_item( $request ) {
        $template = get_block_template( $request['id']$this->post_type );
        if ( ! $template ) {
            return new WP_Error( 'rest_template_not_found', __( 'No templates exist with that id.' ), array( 'status' => 404 ) );
        }

        $post_before = get_post( $template->wp_id );

        if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
            wp_delete_post( $template->wp_id, true );
            $request->set_param( 'context', 'edit' );

            $template = get_block_template( $request['id']$this->post_type );
            $response = $this->prepare_item_for_response( $template$request );

            return rest_ensure_response( $response );
        }

        $changes = $this->prepare_item_for_database( $request );

        if ( is_wp_error( $changes ) ) {
            return $changes;
        }
return $meta_update;
            }
        }

        $fields_update = $this->update_additional_fields_for_object( $comment$request );

        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view';
        $request->set_param( 'context', $context );

        /** * Fires completely after a comment is created or updated via the REST API. * * @since 5.0.0 * * @param WP_Comment $comment Inserted or updated comment object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a comment, false * when updating. */
        

    $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 );
        }
return $locations_update;
        }

        $this->handle_auto_add( $term->term_id, $request );

        $fields_update = $this->update_additional_fields_for_object( $term$request );

        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        $request->set_param( 'context', 'view' );

        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */
        do_action( "rest_after_insert_{$this->taxonomy}", $term$request, true );

        $response = $this->prepare_item_for_response( $term$request );
        $response = rest_ensure_response( $response );

        $response->set_status( 201 );
        $response->header( 'Location', rest_url( $this->namespace . '/' . $this->rest_base . '/' . $term->term_id ) );

        return $response;
    }
return $meta_update;
            }
        }

        $nav_menu_item = $this->get_nav_menu_item( $nav_menu_item_id );
        $fields_update = $this->update_additional_fields_for_object( $nav_menu_item$request );

        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        $request->set_param( 'context', 'edit' );

        /** * Fires after a single menu item is completely created or updated via the REST API. * * @since 5.9.0 * * @param object $nav_menu_item Inserted or updated menu item object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a menu item, false when updating. */
        do_action( 'rest_after_insert_nav_menu_item', $nav_menu_item$request, true );

        
return $meta_update;
            }
        }

        $post          = get_post( $post_id );
        $fields_update = $this->update_additional_fields_for_object( $post$request );

        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        $request->set_param( 'context', 'edit' );

        /** * Fires after a single post is completely created or updated via the REST API. * * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. * * Possible hook names include: * * - `rest_after_insert_post` * - `rest_after_insert_page` * - `rest_after_insert_attachment` * * @since 5.0.0 * * @param WP_Post $post Inserted or updated post object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a post, false when updating. */
$autosave_id = wp_update_post( wp_slash( (array) $prepared_post ), true );
        } else {
            // Non-draft posts: create or update the post autosave.             $autosave_id = $this->create_post_autosave( (array) $prepared_post );
        }

        if ( is_wp_error( $autosave_id ) ) {
            return $autosave_id;
        }

        $autosave = get_post( $autosave_id );
        $request->set_param( 'context', 'edit' );

        $response = $this->prepare_item_for_response( $autosave$request );
        $response = rest_ensure_response( $response );

        return $response;
    }

    /** * Get the autosave, if the ID is valid. * * @since 5.0.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_Post|WP_Error Revision post object if ID is valid, WP_Error otherwise. */
Home | Imprint | This part of the site doesn't use cookies.