update_additional_fields_for_object example

$schema = $this->get_item_schema();

        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
            $meta_update = $this->meta->update_value( $request['meta']$nav_menu_item_id );

            if ( is_wp_error( $meta_update ) ) {
                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. */


        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
            $meta_update = $this->meta->update_value( $request['meta']$user_id );

            if ( is_wp_error( $meta_update ) ) {
                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. */
$schema = $this->get_item_schema();

        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
            $meta_update = $this->meta->update_value( $request['meta']$comment_id );

            if ( is_wp_error( $meta_update ) ) {
                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. */


        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
            $meta_update = $this->meta->update_value( $request['meta']$attachment_id );

            if ( is_wp_error( $meta_update ) ) {
                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_insert_{$this->taxonomy}", $term$request, true );

        $schema = $this->get_item_schema();
        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
            $meta_update = $this->meta->update_value( $request['meta']$term->term_id );

            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. */
$status = $this->get_plugin_status( $request['plugin'] );

        if ( $request['status'] && $status !== $request['status'] ) {
            $handled = $this->handle_plugin_status( $request['plugin']$request['status']$status );

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

        $this->update_additional_fields_for_object( $data$request );

        $request['context'] = 'edit';

        return $this->prepare_item_for_response( $data$request );
    }

    /** * Checks if a given request has access to delete a specific plugin. * * @since 5.5.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise. */

        }

        $locations_update = $this->handle_locations( $term->term_id, $request );

        if ( is_wp_error( $locations_update ) ) {
            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 );
        


        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
            $meta_update = $this->meta->update_value( $request['meta']$post_id );

            if ( is_wp_error( $meta_update ) ) {
                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. */
if ( is_wp_error( $result ) ) {
            if ( 'db_update_error' === $result->get_error_code() ) {
                $result->add_data( array( 'status' => 500 ) );
            } else {
                $result->add_data( array( 'status' => 400 ) );
            }
            return $result;
        }

        $template      = get_block_template( $request['id']$this->post_type );
        $fields_update = $this->update_additional_fields_for_object( $template$request );
        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

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

        $post = get_post( $template->wp_id );
        /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
        do_action( "rest_after_insert_{$this->post_type}", $post$request, false );

        wp_after_insert_post( $post$update$post_before );

        
$created = WP_Application_Passwords::create_new_application_password( $user->ID, wp_slash( (array) $prepared ) );

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

        $password = $created[0];
        $item     = WP_Application_Passwords::get_user_application_password( $user->ID, $created[1]['uuid'] );

        $item['new_password'] = WP_Application_Passwords::chunk_password( $password );
        $fields_update        = $this->update_additional_fields_for_object( $item$request );

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

        /** * 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. */
$changes = $this->prepare_item_for_database( $request );
        if ( is_wp_error( $changes ) ) {
            return $changes;
        }

        $result = wp_update_post( wp_slash( (array) $changes ), true, false );
        if ( is_wp_error( $result ) ) {
            return $result;
        }

        $post          = get_post( $request['id'] );
        $fields_update = $this->update_additional_fields_for_object( $post$request );
        if ( is_wp_error( $fields_update ) ) {
            return $fields_update;
        }

        wp_after_insert_post( $post, true, $post_before );

        $response = $this->prepare_item_for_response( $post$request );

        return rest_ensure_response( $response );
    }

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