diff --git a/bp-rest.php b/bp-rest.php index 6081d777..1674d05b 100644 --- a/bp-rest.php +++ b/bp-rest.php @@ -50,118 +50,118 @@ function bp_rest() { return; } - require_once dirname( __FILE__ ) . '/includes/bp-components/classes/class-bp-rest-components-endpoint.php'; + require_once __DIR__ . '/includes/bp-components/classes/class-bp-rest-components-endpoint.php'; $controller = new BP_REST_Components_Endpoint(); $controller->register_routes(); if ( bp_is_active( 'members' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-members/classes/class-bp-rest-members-endpoint.php'; + require_once __DIR__ . '/includes/bp-members/classes/class-bp-rest-members-endpoint.php'; $controller = new BP_REST_Members_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-attachments/classes/trait-attachments.php'; + require_once __DIR__ . '/includes/bp-attachments/classes/trait-attachments.php'; // Support Member's Avatar. - require_once dirname( __FILE__ ) . '/includes/bp-members/classes/class-bp-rest-attachments-member-avatar-endpoint.php'; + require_once __DIR__ . '/includes/bp-members/classes/class-bp-rest-attachments-member-avatar-endpoint.php'; $controller = new BP_REST_Attachments_Member_Avatar_Endpoint(); $controller->register_routes(); // Support Member's Cover. if ( bp_is_active( 'members', 'cover_image' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-members/classes/class-bp-rest-attachments-member-cover-endpoint.php'; + require_once __DIR__ . '/includes/bp-members/classes/class-bp-rest-attachments-member-cover-endpoint.php'; $controller = new BP_REST_Attachments_Member_Cover_Endpoint(); $controller->register_routes(); } if ( bp_get_signup_allowed() ) { - require_once dirname( __FILE__ ) . '/includes/bp-members/classes/class-bp-rest-signup-endpoint.php'; + require_once __DIR__ . '/includes/bp-members/classes/class-bp-rest-signup-endpoint.php'; $controller = new BP_REST_Signup_Endpoint(); $controller->register_routes(); } } if ( bp_is_active( 'activity' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-activity/classes/class-bp-rest-activity-endpoint.php'; + require_once __DIR__ . '/includes/bp-activity/classes/class-bp-rest-activity-endpoint.php'; $controller = new BP_REST_Activity_Endpoint(); $controller->register_routes(); } if ( is_multisite() && bp_is_active( 'blogs' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-blogs/classes/class-bp-rest-blogs-endpoint.php'; + require_once __DIR__ . '/includes/bp-blogs/classes/class-bp-rest-blogs-endpoint.php'; $controller = new BP_REST_Blogs_Endpoint(); $controller->register_routes(); // Support to Blog Avatar. if ( bp_is_active( 'blogs', 'site-icon' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-attachments/classes/trait-attachments.php'; - require_once dirname( __FILE__ ) . '/includes/bp-blogs/classes/class-bp-rest-attachments-blog-avatar-endpoint.php'; + require_once __DIR__ . '/includes/bp-attachments/classes/trait-attachments.php'; + require_once __DIR__ . '/includes/bp-blogs/classes/class-bp-rest-attachments-blog-avatar-endpoint.php'; $controller = new BP_REST_Attachments_Blog_Avatar_Endpoint(); $controller->register_routes(); } } if ( bp_is_active( 'xprofile' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php'; + require_once __DIR__ . '/includes/bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php'; $controller = new BP_REST_XProfile_Fields_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-xprofile/classes/class-bp-rest-xprofile-field-groups-endpoint.php'; + require_once __DIR__ . '/includes/bp-xprofile/classes/class-bp-rest-xprofile-field-groups-endpoint.php'; $controller = new BP_REST_XProfile_Field_Groups_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-xprofile/classes/class-bp-rest-xprofile-data-endpoint.php'; + require_once __DIR__ . '/includes/bp-xprofile/classes/class-bp-rest-xprofile-data-endpoint.php'; $controller = new BP_REST_XProfile_Data_Endpoint(); $controller->register_routes(); } if ( bp_is_active( 'groups' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-groups/classes/class-bp-rest-groups-endpoint.php'; + require_once __DIR__ . '/includes/bp-groups/classes/class-bp-rest-groups-endpoint.php'; $controller = new BP_REST_Groups_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-groups/classes/class-bp-rest-group-membership-endpoint.php'; + require_once __DIR__ . '/includes/bp-groups/classes/class-bp-rest-group-membership-endpoint.php'; $controller = new BP_REST_Group_Membership_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-groups/classes/class-bp-rest-group-invites-endpoint.php'; + require_once __DIR__ . '/includes/bp-groups/classes/class-bp-rest-group-invites-endpoint.php'; $controller = new BP_REST_Group_Invites_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-groups/classes/class-bp-rest-group-membership-request-endpoint.php'; + require_once __DIR__ . '/includes/bp-groups/classes/class-bp-rest-group-membership-request-endpoint.php'; $controller = new BP_REST_Group_Membership_Request_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-attachments/classes/trait-attachments.php'; - require_once dirname( __FILE__ ) . '/includes/bp-groups/classes/class-bp-rest-attachments-group-avatar-endpoint.php'; + require_once __DIR__ . '/includes/bp-attachments/classes/trait-attachments.php'; + require_once __DIR__ . '/includes/bp-groups/classes/class-bp-rest-attachments-group-avatar-endpoint.php'; $controller = new BP_REST_Attachments_Group_Avatar_Endpoint(); $controller->register_routes(); // Support to Group Cover. if ( bp_is_active( 'groups', 'cover_image' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-groups/classes/class-bp-rest-attachments-group-cover-endpoint.php'; + require_once __DIR__ . '/includes/bp-groups/classes/class-bp-rest-attachments-group-cover-endpoint.php'; $controller = new BP_REST_Attachments_Group_Cover_Endpoint(); $controller->register_routes(); } } if ( bp_is_active( 'messages' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-messages/classes/class-bp-rest-messages-endpoint.php'; + require_once __DIR__ . '/includes/bp-messages/classes/class-bp-rest-messages-endpoint.php'; $controller = new BP_REST_Messages_Endpoint(); $controller->register_routes(); - require_once dirname( __FILE__ ) . '/includes/bp-messages/classes/class-bp-rest-sitewide-notices-endpoint.php'; + require_once __DIR__ . '/includes/bp-messages/classes/class-bp-rest-sitewide-notices-endpoint.php'; $controller = new BP_REST_Sitewide_Notices_Endpoint(); $controller->register_routes(); } if ( bp_is_active( 'notifications' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-notifications/classes/class-bp-rest-notifications-endpoint.php'; + require_once __DIR__ . '/includes/bp-notifications/classes/class-bp-rest-notifications-endpoint.php'; $controller = new BP_REST_Notifications_Endpoint(); $controller->register_routes(); } if ( bp_is_active( 'friends' ) ) { - require_once dirname( __FILE__ ) . '/includes/bp-friends/classes/class-bp-rest-friends-endpoint.php'; + require_once __DIR__ . '/includes/bp-friends/classes/class-bp-rest-friends-endpoint.php'; $controller = new BP_REST_Friends_Endpoint(); $controller->register_routes(); } diff --git a/composer.json b/composer.json index 9b4f6175..ca4920e6 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "php": ">=5.6.0" }, "require-dev": { - "buddypress/bp-coding-standards": "0.1.0", + "buddypress/bp-coding-standards": "dev-trunk", "yoast/phpunit-polyfills": "^1.0" }, "scripts": { diff --git a/includes/bp-attachments/classes/trait-attachments.php b/includes/bp-attachments/classes/trait-attachments.php index 2e98887e..1ca13c2a 100644 --- a/includes/bp-attachments/classes/trait-attachments.php +++ b/includes/bp-attachments/classes/trait-attachments.php @@ -242,7 +242,7 @@ protected function upload_avatar_from_file( $files ) { $avatar_object = $this->get_avatar_object( $args ); if ( file_exists( $avatar_original['file'] ) ) { - unlink( $avatar_original['file'] ); + wp_delete_file( $avatar_original['file'] ); } return $avatar_object; @@ -281,7 +281,8 @@ protected function resize( $file ) { } else { $image_file = $resized['path']; $img_dir = str_replace( $upload_path, '', $resized['path'] ); - unlink( $file ); + + wp_delete_file( $file ); } // Check for WP_Error on what should be an image. diff --git a/includes/bp-friends/classes/class-bp-rest-friends-endpoint.php b/includes/bp-friends/classes/class-bp-rest-friends-endpoint.php index 4b014188..666c770d 100644 --- a/includes/bp-friends/classes/class-bp-rest-friends-endpoint.php +++ b/includes/bp-friends/classes/class-bp-rest-friends-endpoint.php @@ -552,7 +552,6 @@ public function delete_item( $request ) { // Remove a friendship. if ( true === $request->get_param( 'force' ) ) { $deleted = friends_remove_friend( $friendship->initiator_user_id, $friendship->friend_user_id ); - } else { /** * If this change is being initiated by the initiator, @@ -560,15 +559,14 @@ public function delete_item( $request ) { * * This is the user who requested the friendship, and is doing the withdrawing. */ - if ( bp_loggedin_user_id() === $friendship->initiator_user_id ) { - $deleted = friends_withdraw_friendship( $friendship->initiator_user_id, $friendship->friend_user_id ); - } else { - /** - * Otherwise, this change is being initiated by the user, friend, - * who received the friendship reject. - */ - $deleted = friends_reject_friendship( $friendship->id ); - } + } elseif ( bp_loggedin_user_id() === $friendship->initiator_user_id ) { + $deleted = friends_withdraw_friendship( $friendship->initiator_user_id, $friendship->friend_user_id ); + } else { + /** + * Otherwise, this change is being initiated by the user, friend, + * who received the friendship reject. + */ + $deleted = friends_reject_friendship( $friendship->id ); } if ( false === $deleted ) { diff --git a/includes/bp-groups/classes/class-bp-rest-group-invites-endpoint.php b/includes/bp-groups/classes/class-bp-rest-group-invites-endpoint.php index ded72599..ce8ff5b0 100644 --- a/includes/bp-groups/classes/class-bp-rest-group-invites-endpoint.php +++ b/includes/bp-groups/classes/class-bp-rest-group-invites-endpoint.php @@ -506,18 +506,16 @@ public function create_item_permissions_check( $request ) { 'status' => 404, ) ); - } else { - if ( bp_current_user_can( 'bp_moderate' ) || bp_loggedin_user_id() === $inviter_id_arg ) { + } elseif ( bp_current_user_can( 'bp_moderate' ) || bp_loggedin_user_id() === $inviter_id_arg ) { $retval = true; - } else { - $retval = new WP_Error( - 'bp_rest_group_invite_cannot_create_item', - __( 'Sorry, you are not allowed to create the invitation as requested.', 'buddypress' ), - array( - 'status' => rest_authorization_required_code(), - ) - ); - } + } else { + $retval = new WP_Error( + 'bp_rest_group_invite_cannot_create_item', + __( 'Sorry, you are not allowed to create the invitation as requested.', 'buddypress' ), + array( + 'status' => rest_authorization_required_code(), + ) + ); } } } diff --git a/includes/bp-groups/classes/class-bp-rest-groups-endpoint.php b/includes/bp-groups/classes/class-bp-rest-groups-endpoint.php index 9ca3d9d1..fcba9d76 100644 --- a/includes/bp-groups/classes/class-bp-rest-groups-endpoint.php +++ b/includes/bp-groups/classes/class-bp-rest-groups-endpoint.php @@ -929,7 +929,7 @@ protected function prepare_item_for_database( $request ) { // Remove group type(s). if ( isset( $prepared_group->group_id ) && ! empty( $request->get_param( 'remove_types' ) ) ) { array_map( - function( $type ) use ( $prepared_group ) { + function ( $type ) use ( $prepared_group ) { bp_groups_remove_group_type( $prepared_group->group_id, $type ); }, $request->get_param( 'remove_types' ) diff --git a/includes/bp-members/classes/class-bp-rest-members-endpoint.php b/includes/bp-members/classes/class-bp-rest-members-endpoint.php index 5df8d95b..82a7c507 100644 --- a/includes/bp-members/classes/class-bp-rest-members-endpoint.php +++ b/includes/bp-members/classes/class-bp-rest-members-endpoint.php @@ -880,19 +880,19 @@ protected function can_manage_member( $user, $action = 'delete' ) { * * @since 0.1.0 * - * @param WP_User $object The WordPress user object. + * @param WP_User $user The WordPress user object. * @param WP_REST_Request $request Full details about the request. * @return bool|WP_Error True on success, WP_Error object if a field cannot be updated. */ - protected function update_additional_fields_for_object( $object, $request ) { - if ( ! isset( $object->data ) ) { + protected function update_additional_fields_for_object( $user, $request ) { + if ( ! isset( $user->data ) ) { return new WP_Error( 'invalid_user', __( 'The data for the user was not found.', 'buddypress' ) ); } - $member = $object->data; + $member = $user->data; $member->id = $member->ID; return parent::update_additional_fields_for_object( $member, $request ); diff --git a/includes/bp-members/classes/class-bp-rest-signup-endpoint.php b/includes/bp-members/classes/class-bp-rest-signup-endpoint.php index ee7b96fe..3e37b045 100644 --- a/includes/bp-members/classes/class-bp-rest-signup-endpoint.php +++ b/includes/bp-members/classes/class-bp-rest-signup-endpoint.php @@ -471,16 +471,14 @@ public function create_item( $request ) { /** This action is documented in wp-includes/ms-functions.php */ do_action( 'after_signup_user', $signup->user_login, $signup->user_email, $signup->activation_key, $signup->meta ); } - } else { /** This filter is documented in bp-members/bp-members-functions.php */ - if ( apply_filters( 'bp_core_signup_send_activation_key', true, false, $signup->user_email, $signup->activation_key, $signup->meta ) ) { - $salutation = $signup->user_login; - if ( isset( $signup->user_name ) && $signup->user_name ) { - $salutation = $signup->user_name; - } - - bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key, $salutation ); + } elseif ( apply_filters( 'bp_core_signup_send_activation_key', true, false, $signup->user_email, $signup->activation_key, $signup->meta ) ) { + $salutation = $signup->user_login; + if ( isset( $signup->user_name ) && $signup->user_name ) { + $salutation = $signup->user_name; } + + bp_core_signup_send_validation_email( false, $signup->user_email, $signup->activation_key, $salutation ); } $retval = array( diff --git a/includes/bp-messages/classes/class-bp-rest-sitewide-notices-endpoint.php b/includes/bp-messages/classes/class-bp-rest-sitewide-notices-endpoint.php index 618cf337..9784f5ec 100644 --- a/includes/bp-messages/classes/class-bp-rest-sitewide-notices-endpoint.php +++ b/includes/bp-messages/classes/class-bp-rest-sitewide-notices-endpoint.php @@ -268,17 +268,15 @@ public function get_item_permissions_check( $request ) { 'status' => 404, ) ); - } else { - if ( bp_current_user_can( 'bp_moderate' ) ) { + } elseif ( bp_current_user_can( 'bp_moderate' ) ) { $retval = true; + } else { + // Non-admin users can only see the active notice. + $is_active = isset( $notice->is_active ) ? $notice->is_active : false; + if ( ! $is_active ) { + $retval = $error; } else { - // Non-admin users can only see the active notice. - $is_active = isset( $notice->is_active ) ? $notice->is_active : false; - if ( ! $is_active ) { - $retval = $error; - } else { - $retval = true; - } + $retval = true; } } } diff --git a/includes/bp-notifications/classes/class-bp-rest-notifications-endpoint.php b/includes/bp-notifications/classes/class-bp-rest-notifications-endpoint.php index 460e0b17..525a985c 100644 --- a/includes/bp-notifications/classes/class-bp-rest-notifications-endpoint.php +++ b/includes/bp-notifications/classes/class-bp-rest-notifications-endpoint.php @@ -118,10 +118,8 @@ public function get_items( $request ) { if ( ! empty( $args['user_ids'] ) ) { $args['user_id'] = $args['user_ids']; - } else { - if ( empty( $args['user_id'] ) ) { + } elseif ( empty( $args['user_id'] ) ) { $args['user_id'] = bp_loggedin_user_id(); - } } if ( empty( $request->get_param( 'component_name' ) ) ) { diff --git a/includes/bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php b/includes/bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php index 1ac2a604..d72e74c9 100644 --- a/includes/bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php +++ b/includes/bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php @@ -759,7 +759,7 @@ public function assemble_response_data( $field, $request ) { // Adding the options. if ( method_exists( $field, 'get_children' ) ) { $data['options'] = array_map( - function( $item ) use ( $request ) { + function ( $item ) use ( $request ) { return $this->assemble_response_data( $item, $request ); }, $field->get_children() diff --git a/phpcs.xml.dist b/phpcs.xml.dist index b89daaf5..ecc58f2b 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,13 +1,27 @@ - - PHP_CodeSniffer standard for the BuddyPress REST API plugin. + + BP REST API Coding Standards Configuration. - - */**/tests/ + + + + + + + + + + + */**/tests/