Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/27/2024 09:11:27 PM (23 months ago)
Author:
espellcaste
Message:

Include the V2 of the BP REST API in BuddyPress core.

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 https://github.com/buddypress/buddypress/pull/337

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r13689 r14026  
    338338
    339339                // Check the parsed query is consistent with the Group’s registered screens.
    340                 add_action( 'bp_parse_query',  array( $this, 'check_parsed_query' ), 999, 0 );
     340                add_action( 'bp_parse_query', array( $this, 'check_parsed_query' ), 999, 0 );
    341341        }
    342342
     
    448448                 * @param array $value Array of valid group statuses.
    449449                 */
    450                 $this->valid_status = apply_filters( 'groups_valid_status', array(
    451                         'public',
    452                         'private',
    453                         'hidden'
    454                 ) );
     450                $this->valid_status = apply_filters(
     451                        'groups_valid_status',
     452                        array(
     453                                'public',
     454                                'private',
     455                                'hidden',
     456                        )
     457                );
    455458
    456459                // Auto join group when non group member performs group activity.
     
    483486                        'table_name'           => $bp->table_prefix . 'bp_groups',
    484487                        'table_name_members'   => $bp->table_prefix . 'bp_groups_members',
    485                         'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'
     488                        'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta',
    486489                );
    487490
     
    493496                // Fetch the default directory title.
    494497                $default_directory_titles = bp_core_get_directory_page_default_titles();
    495                 $default_directory_title  = $default_directory_titles[$this->id];
     498                $default_directory_title  = $default_directory_titles[ $this->id ];
    496499
    497500                // All globals for groups component.
     
    610613                 * action variables.
    611614                 */
    612                 if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
     615                if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) ) {
    613616                        unset( $bp->canonical_stack['action'] );
    614617                }
     
    635638                        'screen_function'     => 'groups_screen_my_groups',
    636639                        'default_subnav_slug' => 'my-groups',
    637                         'item_css_id'         => $this->id
     640                        'item_css_id'         => $this->id,
    638641                );
    639642
     
    645648                        'screen_function' => 'groups_screen_my_groups',
    646649                        'position'        => 10,
    647                         'item_css_id'     => 'groups-my-groups'
     650                        'item_css_id'     => 'groups-my-groups',
    648651                );
    649652
     
    709712                                        'screen_function'     => 'groups_screen_group_home',
    710713                                        'default_subnav_slug' => $this->default_extension,
    711                                         'item_css_id'         => $this->id
     714                                        'item_css_id'         => $this->id,
    712715                                ),
    713716                                'groups'
     
    824827
    825828                                /** This action is documented in bp-groups/bp-groups-loader.php */
    826                                 do_action( 'groups_setup_nav');
     829                                do_action( 'groups_setup_nav' );
    827830                        }
    828831                }
     
    852855                        if ( bp_is_active( 'groups', 'invitations' ) ) {
    853856                                // Pending group invites.
    854                                 $count   = groups_get_invite_count_for_user();
     857                                $count = groups_get_invite_count_for_user();
    855858                                if ( $count ) {
    856859                                        $title = sprintf(
     
    907910                                                )
    908911                                        ),
    909                                         'position' => 90
     912                                        'position' => 90,
    910913                                );
    911914                        }
     
    925928                        $bp = buddypress();
    926929
    927                         if ( bp_is_my_profile() && !bp_is_single_item() ) {
     930                        if ( bp_is_my_profile() && ! bp_is_single_item() ) {
    928931                                $bp->bp_options_title = _x( 'Memberships', 'My Groups page <title>', 'buddypress' );
    929932
    930                         } elseif ( !bp_is_my_profile() && !bp_is_single_item() ) {
    931                                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    932                                         'item_id' => bp_displayed_user_id(),
    933                                         'type'    => 'thumb',
    934                                         'alt'     => sprintf(
     933                        } elseif ( ! bp_is_my_profile() && ! bp_is_single_item() ) {
     934                                $bp->bp_options_avatar = bp_core_fetch_avatar(
     935                                        array(
     936                                                'item_id' => bp_displayed_user_id(),
     937                                                'type'    => 'thumb',
     938                                                'alt'     => sprintf(
    935939                                                /* translators: %s: member name */
    936                                                 __( 'Profile picture of %s', 'buddypress' ),
    937                                                 bp_get_displayed_user_fullname()
    938                                         ),
    939                                 ) );
    940                                 $bp->bp_options_title = bp_get_displayed_user_fullname();
    941 
    942                         // We are viewing a single group, so set up the
    943                         // group navigation menu using the $this->current_group global.
     940                                                        __( 'Profile picture of %s', 'buddypress' ),
     941                                                        bp_get_displayed_user_fullname()
     942                                                ),
     943                                        )
     944                                );
     945                                $bp->bp_options_title  = bp_get_displayed_user_fullname();
     946
     947                                // We are viewing a single group, so set up the
     948                                // group navigation menu using the $this->current_group global.
    944949                        } elseif ( bp_is_single_item() ) {
    945950                                $bp->bp_options_title  = $this->current_group->name;
    946                                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    947                                         'item_id'    => $this->current_group->id,
    948                                         'object'     => 'group',
    949                                         'type'       => 'thumb',
    950                                         'avatar_dir' => 'group-avatars',
    951                                         'alt'        => __( 'Group Profile Photo', 'buddypress' )
    952                                 ) );
     951                                $bp->bp_options_avatar = bp_core_fetch_avatar(
     952                                        array(
     953                                                'item_id'    => $this->current_group->id,
     954                                                'object'     => 'group',
     955                                                'type'       => 'thumb',
     956                                                'avatar_dir' => 'group-avatars',
     957                                                'alt'        => __( 'Group Profile Photo', 'buddypress' ),
     958                                        )
     959                                );
    953960
    954961                                if ( empty( $bp->bp_options_avatar ) ) {
     
    10281035
    10291036                $rewrite_rules = array(
    1030                         'directory_type'      => array(
     1037                        'directory_type'               => array(
    10311038                                'regex' => $this->root_slug . '/' . bp_get_groups_group_type_base() . '/([^/]+)/?$',
    10321039                                'order' => 50,
    10331040                                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_type'] . '=$matches[1]',
    10341041                        ),
    1035                         'create_single_item' => array(
     1042                        'create_single_item'           => array(
    10361043                                'regex' => $this->root_slug . '/' . $create_slug . '/?$',
    10371044                                'order' => 40,
     
    10401047                        'create_single_item_variables' => array(
    10411048                                'regex' => $this->root_slug . '/' . $create_slug . '/(.+?)/?$',
    1042                                 'order' =>30,
     1049                                'order' => 30,
    10431050                                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['create_single_item'] . '=1&' . $this->rewrite_ids['create_single_item_variables'] . '=$matches[1]',
    10441051                        ),
     
    12391246        public function rest_api_init( $controllers = array() ) {
    12401247                $controllers = array(
    1241                         'BP_REST_Groups_Endpoint',
    1242                         'BP_REST_Group_Membership_Endpoint',
    1243                         'BP_REST_Group_Invites_Endpoint',
    1244                         'BP_REST_Group_Membership_Request_Endpoint',
    1245                         'BP_REST_Attachments_Group_Avatar_Endpoint',
     1248                        'BP_Groups_REST_Controller',
     1249                        'BP_Groups_Avatar_REST_Controller',
     1250                        'BP_Groups_Membership_REST_Controller',
     1251                        'BP_Groups_Membership_Request_REST_Controller',
     1252                        'BP_Groups_Invites_REST_Controller',
    12461253                );
    12471254
    12481255                // Support to Group Cover.
    12491256                if ( bp_is_active( 'groups', 'cover_image' ) ) {
    1250                         $controllers[] = 'BP_REST_Attachments_Group_Cover_Endpoint';
     1257                        $controllers[] = 'BP_Groups_Cover_REST_Controller';
    12511258                }
    12521259
     
    12661273                parent::blocks_init(
    12671274                        array(
    1268                                 'bp/group' => array(
     1275                                'bp/group'          => array(
    12691276                                        'metadata'        => trailingslashit( buddypress()->plugin_dir ) . 'bp-groups/blocks/group',
    12701277                                        'render_callback' => 'bp_groups_render_group_block',
    12711278                                ),
    1272                                 'bp/groups' => array(
     1279                                'bp/groups'         => array(
    12731280                                        'metadata'        => trailingslashit( buddypress()->plugin_dir ) . 'bp-groups/blocks/groups',
    12741281                                        'render_callback' => 'bp_groups_render_groups_block',
Note: See TracChangeset for help on using the changeset viewer.