-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BP REST API - V2 #337
BP REST API - V2 #337
Conversation
if ( ! $blogs_template && isset( $args['blog_id'] ) && $args['blog_id'] ) { | ||
$has_current_blog = isset( $blogs_template ) && isset( $blogs_template->blog->blog_id ); | ||
|
||
if ( false === $has_current_blog && isset( $args['blog_id'] ) && $args['blog_id'] ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should respect if the blog_id
is passed, regardless if there is a blog in the current loop. But, I assume this logic is here for a reason, so let's keep it.
But technically, it's not possible to pass another, different blog_id
into bp_get_blog_avatar
inside a blog loop because of this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you, maybe we can fix it later in another ticket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @espellcaste
Thanks a lot for your work on this.
- I was very surprised by the inclusion of V1 into class names: what is the purpose of
bp_rest_version()
then? - Shouldn't
wp-json/buddypress/v1
results in loading classes for the version 1 of the BP REST API,wp-json/buddypress/v2
results in loading classes for the version 2 of the BP REST API, and so on? - What happens to plugins using directly current BP REST API classes? If you change their prefix in favor of
BP_REST_V1
, I'm afraid we would end up with fatal errors. - According to this comment about the WP API feature as a plugin, we should keep
BP_REST_
class prefix for v1.
I strongly advise you to keep class names the way they currently are: do not use BP_REST_V1
prefixes. We need to preserve Plugin backwards compatibility.
This is almost ready. |
This pull request is for code review. There is some outstanding questions for some behaviors. I'd recommend, for now, to only look at the code/implementation and offer suggestions before diving into testing mode. Just so that by the time we go to QA it, we'll be at a more solid state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your work on this. First I'm sorry I'm hesitating a lot about the best way to deprecate v1.
As I said in one of my review comments and considering the one you made on the Notices PR, I believe we should make sure to inform developers if:
- they are using directory v1 classes without having the BP REST plugin active =>
_deprecated_class()
see the comment I made aboutclass-buddypress.php
- they are including v1 files inside BuddyPress =>
_deprecated_file()
see the comment I made aboutbp-activity/classes/class-bp-rest-activity-endpoint.php
This means renaming all v2 files and classes so that they match the autoloader regular map. Eg: class BP_Activity_REST_Controller
=> class-bp-activity-rest-controller.php` (like you previously did I believe - sorry for changing my mind!!). As I've tested it, you'll find below the diff I added to my local test of your PR below (if it can save you some time).
337.unfinished.patch
The Manage Group Members UI using the REST API works as expected after the change. The buddypress/v1
deprecated notice works as expected 👏 .
On a site note, once REST API v2 will be SVN committed, we'll need to update all BP Blocks to use the new rest version as buddypress/v1
is hardcoded into these.
) | ||
); | ||
} | ||
add_action( 'bp_init', 'bp_rest_api_register_request_script' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to our discussion about it, we shouldn't register this script anymore
add_action( 'bp_init', 'bp_rest_api_register_request_script' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! I was going to apply this change in a second pr, separate ticket.
/** | ||
* Register the jQuery.ajax wrapper for BP REST API requests. | ||
* | ||
* @since 5.0.0 | ||
* @deprecated 10.0.0 | ||
*/ | ||
function bp_rest_api_register_request_script() { | ||
if ( ! bp_rest_api_is_available() ) { | ||
return; | ||
} | ||
|
||
wp_register_script( | ||
'bp-api-request', | ||
sprintf( '%1$sbp-core/js/bp-api-request%2$s.js', buddypress()->plugin_url, bp_core_get_minified_asset_suffix() ), | ||
array( 'jquery', 'wp-api-request' ), | ||
bp_get_version(), | ||
true | ||
); | ||
|
||
wp_localize_script( | ||
'bp-api-request', | ||
'bpApiSettings', | ||
array( | ||
'unexpectedError' => __( 'An unexpected error occurred. Please try again.', 'buddypress' ), | ||
'deprecatedWarning' => __( 'The bp.apiRequest function is deprecated since BuddyPress 10.0.0, please use wp.apiRequest instead.', 'buddypress' ), | ||
) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part should be moved into:
src/bp-core/deprecated/10.0.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to apply this change in a second pr, separate ticket.
if ( ! $blogs_template && isset( $args['blog_id'] ) && $args['blog_id'] ) { | ||
$has_current_blog = isset( $blogs_template ) && isset( $blogs_template->blog->blog_id ); | ||
|
||
if ( false === $has_current_blog && isset( $args['blog_id'] ) && $args['blog_id'] ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you, maybe we can fix it later in another ticket?
function bp_rest_api_v1_dispatch_error( $result, $server, $request ) { | ||
|
||
// Bail early if the BP REST plugin is active. | ||
if ( bp_rest_is_plugin_active() ) { | ||
return $result; | ||
} | ||
|
||
$route = $request->get_route(); | ||
|
||
if ( empty( $route ) || ! str_contains( $route, 'buddypress/v1' ) ) { | ||
return $result; | ||
} | ||
|
||
return new WP_Error( | ||
'rest_no_route', | ||
__( 'The V1 of the BuddyPress REST API is no longer supported, use the V2 instead.', 'buddypress' ), | ||
array( 'status' => 404 ) | ||
); | ||
} | ||
add_filter( 'rest_pre_dispatch', 'bp_rest_api_v1_dispatch_error', 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work here 💪 ! I confirm it behaves as expected.
@imath Three clarifying questions: Looking at this comment related to the I do see some places where folks are using it outside of the constructor, but it doesn't seem to be the location it was designed to be used. Some of the new classes names are a bit off, like
I'm really curious if you know of a plugin that's actually loading one of our controller files manually into their own plugin. That would be very odd, it's as if we would load the file for the A quick search came up empty but I assume you might know of an example. And just to be clear, I'm not against this change. I'm mostly curious, would be flabbergasted, if someone would be doing that at all for this type of class/endpoint/controller. |
Co-authored-by: imath <[email protected]>
Hi @renatonascalves about the 3 clarifying questions:
|
|
Awesome, maybe we still need to inform about deprecated class usage from BuddyPress when the BP REST plugin is not active? |
This is not necessary because without the BP REST plugin, a site can't use the V1 endpoints at all. They can only use the V2 endpoints. And if the need to use V1, they need to install the BP REST plugin. Here is the PR in the BP REST plugin: buddypress/BP-REST#512 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @renatonascalves congrats for the achieved works! Amazing job.
I've added a minor suggestion about translators inline comment. Maybe we should rename PHPUnit REST testcases / files to follow the controller
switch, eg: BP_Test_REST_Group_Endpoint
=> BP_Test_Group_REST_Controller
& test-endpoint.php
=> test-controller.php
?
Feel free to SVN Commit!
NB: As you're adding a lot of files, don't forget to svn stat
and eventually svn add
new files before committing.
💚 💪
@imath Awesome! I'll apply the latest suggestions. I actually forgot to rename the phpunit test files related to the endpoints to controller. Good catch! |
We are officially deprecating the V1 of the BP REST API. And bundling the new, default, V2 of the BP REST API inside BuddyPress core. Previously, the V1 was developed as a plugin in a separate repo (https://github.com/buddypress/BP-REST). - One of the main differences between the V1 and V2 is how objects are returned. Single items are no longer returned as an `array`; - We have a new `BP_Test_REST_Controller_Testcase` for testing the new API endpoints; - We changed the names of our controllers to follow our autoloader rules; - Removed the BP-REST plugin from `wp-env` and from our release script; - And we added notices for the deprecated V1 API (endpoints and files). Props imath & I. ;) Fixes #8200 See #9145 Closes buddypress/buddypress#337 git-svn-id: http://buddypress.svn.wordpress.org/trunk@14026 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
Trac ticket: https://buddypress.trac.wordpress.org/ticket/9145
This Pull Request is for code review only. Please keep all other discussion in the BuddyPress Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the WordPress Core Handbook for more details.