Make WordPress Core

Opened 3 months ago

Closed 3 weeks ago

Last modified 7 days ago

#60895 closed enhancement (fixed)

Add batch support to users REST API WP_REST_Users_Controller

Reported by: alexminza's profile alexminza Owned by: timothyblynjacobs's profile TimothyBlynJacobs
Milestone: 6.6 Priority: normal
Severity: normal Version: trunk
Component: REST API Keywords: has-patch
Focuses: Cc:

Description

Following the development discussions in #53063 and #50244 for some reason batch support was not added to users.

We were working on importing a large number of users as part of a migration project to WordPress / WooCommerce to discover that WP REST API does not support batching for Users in WP_REST_Users_Controller since allow_batch is not explicitly set to true in register_rest_route.

Is there a particular reason batching was not enabled for users?
Would it make sense to add this similarly to WP_REST_Posts_Controller?

https://core.trac.wordpress.org/changeset/52068/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Change History (10)

This ticket was mentioned in PR #6364 on WordPress/wordpress-develop by @alexminza.


3 months ago
#1

  • Keywords has-patch added

Following the development discussions in #53063 and #50244 for some reason batch support was not added to users.

We were working on importing a large number of users as part of a migration project to WordPress / WooCommerce to discover that WP REST API does not support batching for Users in WP_REST_Users_Controller since allow_batch is not explicitly set to true in register_rest_route.

This PR adds batch support for users in WP_REST_Users_Controller.

Trac ticket: https://core.trac.wordpress.org/ticket/60895
Reference: https://core.trac.wordpress.org/ticket/53063

#2 @alexminza
3 months ago

This PR https://github.com/WordPress/wordpress-develop/pull/6364 enables batch users operations like for example creating multiple users in a single batch request:

curl --location 'http://localhost:8080/wp-json/batch/v1' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ##REDACTED##' \
--data-raw '{
    "requests": [
        {
            "method": "POST",
            "path": "/wp/v2/users",
            "body": {
                "username": "testuser1",
                "email": "testuser1@localhost.local",
                "password": "##REDACTED##"
            }
        },
        {
            "method": "POST",
            "path": "/wp/v2/users",
            "body": {
                "username": "testuser2",
                "email": "testuser2@localhost.local",
                "password": "##REDACTED##"
            }
        }
    ]
}'

@alexminza commented on PR #6364:


2 months ago
#3

@TimothyBJacobs you added the main support for batching https://core.trac.wordpress.org/ticket/53063 - what do you think about this change?

#4 @alexminza
2 months ago

@TimothyBlynJacobs you added the main support for batching #53063 - what do you think about this change?

Version 0, edited 2 months ago by alexminza (next)

#5 @TimothyBlynJacobs
2 months ago

  • Milestone changed from Awaiting Review to 6.6
  • Owner set to TimothyBlynJacobs
  • Status changed from new to assigned

Thanks for the patch! I’ve marked this for inclusion in 6.6.

#6 @oglekler
5 weeks ago

@TimothyBlynJacobs can you proceed with this patch? There are fallen Unit tests, but possibly they just need to be restarted. We have 2 weeks until Beta 1.

This ticket was mentioned in Slack in #core by nhrrob. View the logs.


3 weeks ago

#8 @TimothyBlynJacobs
3 weeks ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58283:

REST API: Add batch support to the Users API.

Developers can now include /wp/v2/users routes when making a batch API request.

Props alexminza, timothyblynjacobs, mukesh27.
Fixes #60895.

@TimothyBlynJacobs commented on PR #6364:


3 weeks ago
#9

Merged in r58283.

#10 @desrosj
7 days ago

In 58408:

Coding Standards: Apply changes after running composer format.

This applies several formatting related changes made while running composer format.

Follow up to [55720], [58171], [58271], [58282], [58283], [58292], [58299], [58303], [58332].
See #51857, #60719, #60895, #61021, #61118, #61228, #61276, #61324.

Note: See TracTickets for help on using tickets.