Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/27/2024 09:11:27 PM (15 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/class-buddypress.php

    r13953 r14026  
    657657                require $this->plugin_dir . sprintf( 'bp-core/deprecated/%s.php', number_format( $deprecated_functions_version, 1 ) );
    658658            }
    659         }
     659        }
    660660
    661661        // Load wp-cli module if PHP 5.6+.
     
    674674     * @since 2.5.0
    675675     *
    676      * @param string $class Classes to be autoloaded.
    677      * @return string Path of a class.
    678      */
    679     public function autoload( $class ) {
    680         $class_parts = explode( '_', strtolower( $class ) );
     676     * @param string $class_name Classes to be autoloaded.
     677     */
     678    public function autoload( $class_name ) {
     679        $class_parts = explode( '_', strtolower( $class_name ) );
    681680
    682681        if ( 'bp' !== $class_parts[0] ) {
     
    699698        // These classes don't have a name that matches their component.
    700699        $irregular_map = array(
    701             'BP_Akismet'                                 => 'activity',
    702             'BP_REST_Activity_Endpoint'                  => 'activity',
    703 
    704             'BP_REST_Blogs_Endpoint'                     => 'blogs',
    705             'BP_REST_Attachments_Blog_Avatar_Endpoint'   => 'blogs',
    706 
    707             'BP_Admin'                                   => 'core',
    708             'BP_Attachment_Avatar'                       => 'core',
    709             'BP_Attachment_Cover_Image'                  => 'core',
    710             'BP_Attachment'                              => 'core',
    711             'BP_Button'                                  => 'core',
    712             'BP_Block'                                   => 'core',
    713             'BP_Component'                               => 'core',
    714             'BP_Customizer_Control_Range'                => 'core',
    715             'BP_Date_Query'                              => 'core',
    716             'BP_Email_Delivery'                          => 'core',
    717             'BP_Email_Address'                           => 'core',
    718             'BP_Email_Recipient'                         => 'core',
    719             'BP_Email_Sender'                            => 'core',
    720             'BP_Email_Participant'                       => 'core',
    721             'BP_Email'                                   => 'core',
    722             'BP_Embed'                                   => 'core',
    723             'BP_Media_Extractor'                         => 'core',
    724             'BP_Members_Suggestions'                     => 'core',
    725             'BP_PHPMailer'                               => 'core',
    726             'BP_Recursive_Query'                         => 'core',
    727             'BP_Suggestions'                             => 'core',
    728             'BP_Theme_Compat'                            => 'core',
    729             'BP_User_Query'                              => 'core',
    730             'BP_Walker_Category_Checklist'               => 'core',
    731             'BP_Walker_Nav_Menu'                         => 'core',
    732             'BP_Invitation_Manager'                      => 'core',
    733             'BP_Invitation'                              => 'core',
    734             'BP_REST_Components_Endpoint'                => 'core',
    735             'BP_REST_Attachments'                        => 'core',
    736             'BP_Admin_Types'                             => 'core',
    737             'BP_Optout'                                  => 'core',
    738             'BP_Optouts_List_Table'                      => 'core',
    739 
    740             'BP_REST_Friends_Endpoint'                   => 'friends',
    741 
    742             'BP_Group_Extension'                         => 'groups',
    743             'BP_Group_Member_Query'                      => 'groups',
    744             'BP_REST_Groups_Endpoint'                    => 'groups',
    745             'BP_REST_Group_Membership_Endpoint'          => 'groups',
    746             'BP_REST_Group_Invites_Endpoint'             => 'groups',
    747             'BP_REST_Group_Membership_Request_Endpoint'  => 'groups',
    748             'BP_REST_Attachments_Group_Avatar_Endpoint'  => 'groups',
    749             'BP_REST_Attachments_Group_Cover_Endpoint'   => 'groups',
    750 
    751             'BP_Core_Members_Template'                   => 'members',
    752             'BP_Registration_Theme_Compat'               => 'members',
    753             'BP_Signup'                                  => 'members',
    754             'BP_REST_Members_Endpoint'                   => 'members',
    755             'BP_REST_Attachments_Member_Avatar_Endpoint' => 'members',
    756             'BP_REST_Attachments_Member_Cover_Endpoint'  => 'members',
    757             'BP_REST_Signup_Endpoint'                    => 'members',
    758             'BP_Members_Invitation_Manager'              => 'members',
    759             'BP_Members_Invitations_Template'            => 'members',
    760             'BP_Members_Invitations_Component'           => 'members',
    761 
    762             'BP_REST_Messages_Endpoint'                  => 'messages',
    763             'BP_REST_Sitewide_Notices_Endpoint'          => 'messages',
    764 
    765             'BP_REST_Notifications_Endpoint'             => 'notifications',
    766 
    767             'BP_REST_XProfile_Fields_Endpoint'           => 'xprofile',
    768             'BP_REST_XProfile_Field_Groups_Endpoint'     => 'xprofile',
    769             'BP_REST_XProfile_Data_Endpoint'             => 'xprofile',
     700            'BP_Akismet'                       => 'activity',
     701            'BP_Admin'                         => 'core',
     702            'BP_Attachment_Avatar'             => 'core',
     703            'BP_Attachment_Cover_Image'        => 'core',
     704            'BP_Attachment'                    => 'core',
     705            'BP_Button'                        => 'core',
     706            'BP_Block'                         => 'core',
     707            'BP_Component'                     => 'core',
     708            'BP_Customizer_Control_Range'      => 'core',
     709            'BP_Date_Query'                    => 'core',
     710            'BP_Email_Delivery'                => 'core',
     711            'BP_Email_Address'                 => 'core',
     712            'BP_Email_Recipient'               => 'core',
     713            'BP_Email_Sender'                  => 'core',
     714            'BP_Email_Participant'             => 'core',
     715            'BP_Email'                         => 'core',
     716            'BP_Embed'                         => 'core',
     717            'BP_Media_Extractor'               => 'core',
     718            'BP_Members_Suggestions'           => 'core',
     719            'BP_PHPMailer'                     => 'core',
     720            'BP_Recursive_Query'               => 'core',
     721            'BP_Suggestions'                   => 'core',
     722            'BP_Theme_Compat'                  => 'core',
     723            'BP_User_Query'                    => 'core',
     724            'BP_Walker_Category_Checklist'     => 'core',
     725            'BP_Walker_Nav_Menu'               => 'core',
     726            'BP_Invitation_Manager'            => 'core',
     727            'BP_Invitation'                    => 'core',
     728            'BP_REST_Attachments'              => 'core',
     729            'BP_Admin_Types'                   => 'core',
     730            'BP_Optout'                        => 'core',
     731            'BP_Optouts_List_Table'            => 'core',
     732            'BP_Group_Extension'               => 'groups',
     733            'BP_Group_Member_Query'            => 'groups',
     734            'BP_Core_Members_Template'         => 'members',
     735            'BP_Registration_Theme_Compat'     => 'members',
     736            'BP_Signup'                        => 'members',
     737            'BP_Members_Invitation_Manager'    => 'members',
     738            'BP_Members_Invitations_Template'  => 'members',
     739            'BP_Members_Invitations_Component' => 'members',
    770740        );
    771741
     
    773743
    774744        // First check to see if the class is one without a properly namespaced name.
    775         if ( isset( $irregular_map[ $class ] ) ) {
    776             $component = $irregular_map[ $class ];
    777 
    778         // Next chunk is usually the component name.
     745        if ( isset( $irregular_map[ $class_name ] ) ) {
     746            $component = $irregular_map[ $class_name ];
     747
     748            // Next chunk is usually the component name.
    779749        } elseif ( in_array( $class_parts[1], $components, true ) ) {
    780750            $component = $class_parts[1];
     
    786756
    787757        // Sanitize class name.
    788         $class = strtolower( str_replace( '_', '-', $class ) );
     758        $class = strtolower( str_replace( '_', '-', $class_name ) );
    789759
    790760        if ( 'bp-rest-attachments' === $class ) {
    791             $path = dirname( __FILE__ ) . "/bp-{$component}/classes/trait-attachments.php";
     761            $path = __DIR__ . "/bp-{$component}/classes/trait-attachments.php";
    792762        } else {
    793             $path = dirname( __FILE__ ) . "/bp-{$component}/classes/class-{$class}.php";
     763            $path = __DIR__ . "/bp-{$component}/classes/class-{$class}.php";
    794764        }
    795765
     
    878848            $this->db_version_raw = (int) $versions['1.6-single'];
    879849
    880         // If no 1.6-single exists, use the max of the others.
     850            // If no 1.6-single exists, use the max of the others.
    881851        } else {
    882852            $versions['1.2']        = get_site_option( 'bp-core-db-version' );
Note: See TracChangeset for help on using the changeset viewer.