Skip to content

Commit 8c04064

Browse files
WPCS - miscellaneous fixes for the BP Settings component.
See #9174 See #9173 git-svn-id: https://buddypress.svn.wordpress.org/trunk@14124 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
1 parent ed4f085 commit 8c04064

File tree

8 files changed

+69
-51
lines changed

8 files changed

+69
-51
lines changed

phpcs.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
5252
<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
5353

54+
<!-- Usually harmless, let's skip them. -->
55+
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
56+
<exclude name="Squiz.PHP.CommentedOutCode.Found" />
57+
5458
<exclude name="WordPress.Security.ValidatedSanitizedInput.InputNotValidated" />
5559
<exclude name="WordPress.Security.ValidatedSanitizedInput.InputNotSanitized" />
5660
<exclude name="WordPress.Security.NonceVerification.Missing" />

src/bp-settings/actions/capabilities.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function bp_settings_action_capabilities() {
5353

5454
$is_spammer = ! empty( $_POST['user-spammer'] ) ? true : false;
5555

56-
if ( bp_is_user_spammer( bp_displayed_user_id() ) != $is_spammer ) {
57-
$status = ( true == $is_spammer ) ? 'spam' : 'ham';
56+
if ( bp_is_user_spammer( bp_displayed_user_id() ) !== $is_spammer ) {
57+
$status = ( true === $is_spammer ) ? 'spam' : 'ham';
5858
bp_core_process_spammer_status( bp_displayed_user_id(), $status );
5959

6060
/**

src/bp-settings/actions/general.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function bp_settings_action_general() {
155155

156156
if ( ! $pass_error->get_error_message() ) {
157157
// Password change attempt is successful.
158-
if ( ( ! empty( $_POST['pwd'] ) && wp_unslash( $_POST['pwd'] ) !== $pass ) || is_super_admin() ) {
158+
if ( ( ! empty( $_POST['pwd'] ) && wp_unslash( $_POST['pwd'] ) !== $pass ) || is_super_admin() ) {
159159
$update_user['user_pass'] = $_POST['pass1'];
160160
$pass_error = false;
161161
$pass_changed = true;
@@ -195,19 +195,19 @@ function bp_settings_action_general() {
195195

196196
// Email feedback.
197197
switch ( $email_error ) {
198-
case 'invalid' :
199-
$feedback['email_invalid'] = __( 'That email address is invalid. Check the formatting and try again.', 'buddypress' );
198+
case 'invalid':
199+
$feedback['email_invalid'] = __( 'That email address is invalid. Check the formatting and try again.', 'buddypress' );
200200
break;
201-
case 'blocked' :
202-
$feedback['email_blocked'] = __( 'That email address is currently unavailable for use.', 'buddypress' );
201+
case 'blocked':
202+
$feedback['email_blocked'] = __( 'That email address is currently unavailable for use.', 'buddypress' );
203203
break;
204-
case 'taken' :
205-
$feedback['email_taken'] = __( 'That email address is already taken.', 'buddypress' );
204+
case 'taken':
205+
$feedback['email_taken'] = __( 'That email address is already taken.', 'buddypress' );
206206
break;
207-
case 'empty' :
208-
$feedback['email_empty'] = __( 'Email address cannot be empty.', 'buddypress' );
207+
case 'empty':
208+
$feedback['email_empty'] = __( 'Email address cannot be empty.', 'buddypress' );
209209
break;
210-
case false :
210+
case false:
211211
// No change.
212212
break;
213213
}
@@ -217,7 +217,7 @@ function bp_settings_action_general() {
217217
}
218218

219219
// No errors so show a simple success message.
220-
if ( ( ( false === $email_error ) || ( false == $pass_error ) ) && ( ( true === $pass_changed ) || ( true === $email_changed ) ) ) {
220+
if ( ( ( false === $email_error ) || ( false === $pass_error ) ) && ( ( true === $pass_changed ) || ( true === $email_changed ) ) ) {
221221
$feedback[] = __( 'Your settings have been saved.', 'buddypress' );
222222
$feedback_type = 'success';
223223

@@ -296,10 +296,12 @@ function bp_settings_verify_email_change() {
296296
return;
297297
}
298298

299-
$email_changed = wp_update_user( array(
300-
'ID' => $user_id,
301-
'user_email' => trim( $pending_email['newemail'] ),
302-
) );
299+
$email_changed = wp_update_user(
300+
array(
301+
'ID' => $user_id,
302+
'user_email' => trim( $pending_email['newemail'] ),
303+
)
304+
);
303305

304306
if ( $email_changed ) {
305307
// Delete the pending email change key.

src/bp-settings/actions/notifications.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function bp_settings_action_notifications() {
3939

4040
// Switch feedback for super admins.
4141
if ( bp_is_my_profile() ) {
42-
bp_core_add_message( __( 'Your notification settings have been saved.', 'buddypress' ), 'success' );
42+
bp_core_add_message( __( 'Your notification settings have been saved.', 'buddypress' ), 'success' );
4343
} else {
4444
bp_core_add_message( __( "This user's notification settings have been saved.", 'buddypress' ), 'success' );
4545
}

src/bp-settings/bp-settings-filters.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @since 4.0.0
88
*/
99

10-
// Personal data export.
11-
add_filter( 'wp_privacy_personal_data_exporters', 'bp_settings_register_personal_data_exporter' );
10+
// Exit if accessed directly.
11+
defined( 'ABSPATH' ) || exit;
1212

1313
/**
1414
* Registers Settings personal data exporter.
@@ -28,3 +28,4 @@ function bp_settings_register_personal_data_exporter( $exporters ) {
2828

2929
return $exporters;
3030
}
31+
add_filter( 'wp_privacy_personal_data_exporters', 'bp_settings_register_personal_data_exporter' );

src/bp-settings/bp-settings-functions.php

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ function bp_settings_sanitize_notification_settings( $settings = array() ) {
8888
* @return array
8989
*/
9090
function bp_settings_get_registered_notification_keys() {
91-
9291
ob_start();
92+
9393
/**
9494
* Fires at the start of the building of the notification keys allowed list.
9595
*
9696
* @since 1.0.0
9797
*/
9898
do_action( 'bp_notification_settings' );
99+
99100
$screen = ob_get_clean();
100101

101102
$matched = preg_match_all( '/<input[^>]+name="notifications\[([^\]]+)\]/', $screen, $matches );
@@ -113,12 +114,12 @@ function bp_settings_get_registered_notification_keys() {
113114
* Finds and exports personal data associated with an email address from the Settings component.
114115
*
115116
* @since 4.0.0
117+
* @since 15.0.0 The `$page` parameter was removed since it was unused.
116118
*
117-
* @param string $email_address The user's email address.
118-
* @param int $page Batch number.
119+
* @param string $email_address The user's email address.
119120
* @return array An array of personal data.
120121
*/
121-
function bp_settings_personal_data_exporter( $email_address, $page ) {
122+
function bp_settings_personal_data_exporter( $email_address ) {
122123
$email_address = trim( $email_address );
123124

124125
$data_to_export = array();
@@ -238,20 +239,22 @@ function bp_settings_get_personal_data_request( $user_id = 0 ) {
238239
return false;
239240
}
240241

241-
$query = new WP_Query( array(
242-
'author' => (int) $user_id,
243-
'post_type' => 'user_request',
244-
'post_status' => 'any',
245-
'post_name__in' => array(
246-
'export_personal_data',
247-
),
248-
) );
242+
$query = new WP_Query(
243+
array(
244+
'author' => (int) $user_id,
245+
'post_type' => 'user_request',
246+
'post_status' => 'any',
247+
'post_name__in' => array(
248+
'export_personal_data',
249+
),
250+
)
251+
);
249252

250253
if ( ! empty( $query->post ) ) {
251254
return wp_get_user_request( $query->post->ID );
252-
} else {
253-
return false;
254255
}
256+
257+
return false;
255258
}
256259

257260
/**
@@ -327,15 +330,19 @@ function bp_settings_personal_data_export_exists( WP_User_Request $request ) {
327330
function bp_settings_data_exporter_items() {
328331
/** This filter is documented in /wp-admin/includes/ajax-actions.php */
329332
$exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
330-
$custom_friendly_names = apply_filters( 'bp_settings_data_custom_friendly_names', array(
331-
'wordpress-comments' => _x( 'Comments', 'WP Comments data exporter friendly name', 'buddypress' ),
332-
'wordpress-media' => _x( 'Media', 'WP Media data exporter friendly name', 'buddypress' ),
333-
'wordpress-user' => _x( 'Personal information', 'WP Media data exporter friendly name', 'buddypress' ),
334-
) );
333+
$custom_friendly_names = apply_filters(
334+
'bp_settings_data_custom_friendly_names',
335+
array(
336+
'wordpress-comments' => _x( 'Comments', 'WP Comments data exporter friendly name', 'buddypress' ),
337+
'wordpress-media' => _x( 'Media', 'WP Media data exporter friendly name', 'buddypress' ),
338+
'wordpress-user' => _x( 'Personal information', 'WP Media data exporter friendly name', 'buddypress' ),
339+
)
340+
);
335341

336342
?>
337343
<ul>
338-
<?php foreach ( $exporters as $exporter => $data ) :
344+
<?php
345+
foreach ( $exporters as $exporter => $data ) :
339346
// Use the exporter friendly name by default.
340347
$friendly_name = $data['exporter_friendly_name'];
341348

src/bp-settings/bp-settings-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function bp_settings_pending_email_notice() {
7878
return;
7979
}
8080

81-
if ( bp_get_displayed_user_email() == $pending_email['newemail'] ) {
81+
if ( bp_get_displayed_user_email() === $pending_email['newemail'] ) {
8282
return;
8383
}
8484

src/bp-settings/classes/class-bp-settings-component.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ public function __construct() {
4242
* @param array $includes Array of values to include. Not used.
4343
*/
4444
public function includes( $includes = array() ) {
45-
parent::includes( array(
46-
'template',
47-
'filters',
48-
'functions',
49-
) );
45+
parent::includes(
46+
array(
47+
'template',
48+
'filters',
49+
'functions',
50+
)
51+
);
5052
}
5153

5254
/**
@@ -112,10 +114,12 @@ public function setup_globals( $args = array() ) {
112114
}
113115

114116
// All globals for settings component.
115-
parent::setup_globals( array(
116-
'slug' => $default_slug,
117-
'has_directory' => false,
118-
) );
117+
parent::setup_globals(
118+
array(
119+
'slug' => $default_slug,
120+
'has_directory' => false,
121+
)
122+
);
119123
}
120124

121125
/**
@@ -131,7 +135,7 @@ public function setup_globals( $args = array() ) {
131135
* description.
132136
*/
133137
public function register_nav( $main_nav = array(), $sub_nav = array() ) {
134-
$slug = bp_get_settings_slug();
138+
$slug = bp_get_settings_slug();
135139

136140
// Add the settings navigation item.
137141
$main_nav = array(

0 commit comments

Comments
 (0)