Apply coding standards.

This commit is contained in:
Ian Dunn 2020-11-13 12:16:06 -08:00
parent c1ce72d447
commit 13a417ce8e
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB
9 changed files with 50 additions and 52 deletions

View file

@ -46,7 +46,7 @@ add_action( 'wp_head', __NAMESPACE__ . '\prevent_caching_auth_tokens', 99 );
* etc could create situations where they're leaked to others.
*/
function prevent_caching_auth_tokens() {
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce not required, not processing form data.
// phpcs:ignore WordPress.Security.NonceVerification -- Nonce not required, not processing form data.
if ( isset( $_GET['auth_token'] ) || isset( $_POST['auth_token'] ) ) {
nocache_headers();
}
@ -162,7 +162,7 @@ function can_manage_pledge( $requested_pledge_id, $auth_token = '' ) {
// A valid token supersedes other auth methods.
if ( true === is_valid_authentication_token( $requested_pledge_id, 'manage_pledge', $auth_token ) ) {
return true;
} else if ( is_user_logged_in() ) {
} elseif ( is_user_logged_in() ) {
if ( current_user_can( 'manage_options' ) ) {
return true;
}

View file

@ -265,7 +265,7 @@ function get_pledge_contributors_data( $pledge_id ) {
$name = $contributor_post->post_title;
$contributor = get_user_by( 'login', $name );
return [
return array(
'pledgeId' => $pledge_id,
'contributorId' => $contributor_post->ID,
'status' => $contributor_status,
@ -277,7 +277,7 @@ function get_pledge_contributors_data( $pledge_id ) {
'resendLabel' => __( 'Resend Confirmation', 'wporg-5ftf' ),
'removeConfirm' => sprintf( __( 'Remove %s from this pledge?', 'wporg-5ftf' ), $name ),
'removeLabel' => sprintf( __( 'Remove %s', 'wporg-5ftf' ), $name ),
];
);
},
$group
);

View file

@ -28,39 +28,39 @@ function manage_contributors_handler() {
$authenticated = Auth\can_manage_pledge( $pledge_id, $token );
if ( is_wp_error( $authenticated ) ) {
wp_die( wp_json_encode( [
wp_die( wp_json_encode( array(
'success' => false,
'message' => __( "Sorry, you don't have permissions to do that.", 'wporg-5ftf' ),
] ) );
) ) );
}
switch ( $action ) {
case 'resend-contributor-confirmation':
$contribution = get_post( $contributor_id );
Email\send_contributor_confirmation_emails( $pledge_id, $contributor_id );
wp_die( wp_json_encode( [
wp_die( wp_json_encode( array(
'success' => true,
'message' => sprintf( __( 'Confirmation email sent to %s.', 'wporg-5ftf' ), $contribution->post_title ),
] ) );
) ) );
break;
case 'remove-contributor':
// Trash contributor.
Contributor\remove_contributor( $contributor_id );
wp_die( wp_json_encode( [
wp_die( wp_json_encode( array(
'success' => true,
'contributors' => Contributor\get_pledge_contributors_data( $pledge_id ),
] ) );
) ) );
break;
case 'add-contributor':
$pledge = get_post( $pledge_id );
$new_contributors = Contributor\parse_contributors( $_POST['contributors'] );
if ( is_wp_error( $new_contributors ) ) {
wp_die( wp_json_encode( [
wp_die( wp_json_encode( array(
'success' => false,
'message' => $new_contributors->get_error_message(),
] ) );
) ) );
}
$contributor_ids = Contributor\add_pledge_contributors( $pledge_id, $new_contributors );
@ -73,10 +73,10 @@ function manage_contributors_handler() {
// Fetch all contributors, now that the new ones have been added.
$contributors = Contributor\get_pledge_contributors_data( $pledge_id );
wp_die( wp_json_encode( [
wp_die( wp_json_encode( array(
'success' => true,
'contributors' => $contributors,
] ) );
) ) );
break;
}
@ -99,15 +99,15 @@ function send_manage_email_handler() {
$message_sent = Email\send_manage_pledge_link( $pledge_id );
if ( $message_sent ) {
$result = [
$result = array(
'success' => true,
'message' => __( 'Thanks! Weve emailed you a link you can open in order to update your pledge.', 'wporg-5ftf' ),
];
);
} else {
$result = [
$result = array(
'success' => false,
'message' => __( 'There was an error while trying to send the email.', 'wporg-5ftf' ),
];
);
}
} else {
$error_message = sprintf(
@ -115,10 +115,10 @@ function send_manage_email_handler() {
get_permalink( get_page_by_path( 'report' ) )
);
$result = [
$result = array(
'success' => false,
'message' => $error_message,
];
);
}
wp_die( wp_json_encode( $result ) );

View file

@ -30,7 +30,7 @@ function render_form_new() {
$is_manage = false;
$pledge_id = 0;
$data = get_form_submission();
$errors = [];
$errors = array();
$pledge = null;
$complete = false;
$directory_url = home_url( 'pledges' );
@ -113,8 +113,8 @@ function render_form_manage() {
return '';
}
$messages = [];
$errors = [];
$messages = array();
$errors = array();
$action = sanitize_text_field( $_REQUEST['action'] ?? '' );
$pledge_id = absint( $_REQUEST['pledge_id'] ?? 0 );
@ -123,7 +123,7 @@ function render_form_manage() {
if ( is_wp_error( $can_view_form ) ) {
$errors = array( strip_tags( $can_view_form->get_error_message() ) );
} else if ( ! Pledge\is_active_pledge( $pledge_id ) ) {
} elseif ( ! Pledge\is_active_pledge( $pledge_id ) ) {
$errors = array(
sprintf(
__( 'This pledge has been removed from Five for the Future. If this was a mistake, please <a href="%s">contact us</a> to reactivate your pledge.', 'wporg-5ftf' ),
@ -161,7 +161,7 @@ function render_form_manage() {
ob_start();
require FiveForTheFuture\get_views_path() . 'partial-result-messages.php';
return ob_get_clean();
} else if ( 'Update Pledge' === $action ) {
} elseif ( 'Update Pledge' === $action ) {
$results = process_form_manage( $pledge_id, $auth_token );
if ( is_wp_error( $results ) ) {

View file

@ -188,7 +188,7 @@ function capture_updated_postmeta( $meta_id, $object_id, $meta_key, $meta_value
$meta_key => $meta_value,
)
);
} else if ( '_thumbnail_id' === $meta_key ) {
} elseif ( '_thumbnail_id' === $meta_key ) {
add_log_entry(
$object_id,
'pledge_logo_changed',

View file

@ -208,7 +208,7 @@ function add_meta_boxes() {
* @param array $box
*/
function render_meta_boxes( $pledge, $box ) {
$readonly = (
$readonly = (
! current_user_can( 'edit_page', $pledge->ID ) ||
Pledge\DEACTIVE_STATUS === $pledge->post_status
);
@ -259,7 +259,7 @@ function save_pledge( $pledge_id, $pledge ) {
* This is only intended to run when the front end form and wp-admin forms are submitted, not when posts are
* programmatically updated.
*/
if ( ! in_array( $post_action, [ 'Submit Pledge', 'editpost' ], true ) ) {
if ( ! in_array( $post_action, array( 'Submit Pledge', 'editpost' ), true ) ) {
return;
}
@ -551,10 +551,10 @@ function enqueue_assets() {
$auth_token = sanitize_text_field( $_REQUEST['auth_token'] ?? '' );
$script_data = array(
// The global ajaxurl is not set on the frontend.
'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
'pledgeId' => $pledge_id,
'manageNonce' => wp_create_nonce( 'manage-contributors' ),
'authToken' => $auth_token,
'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
'pledgeId' => $pledge_id,
'manageNonce' => wp_create_nonce( 'manage-contributors' ),
'authToken' => $auth_token,
'removePrompt' => __( 'Are you sure you want to remove this pledge?', 'wporg-5ftf' ),
);
wp_add_inline_script(

View file

@ -14,10 +14,10 @@ use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX;
defined( 'WPINC' ) || die();
const SLUG = 'pledge';
const SLUG_PL = 'pledges';
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
const DEACTIVE_STATUS = FiveForTheFuture\PREFIX . '-deactivated';
const SLUG = 'pledge';
const SLUG_PL = 'pledges';
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
const DEACTIVE_STATUS = FiveForTheFuture\PREFIX . '-deactivated';
// Admin hooks.
add_action( 'init', __NAMESPACE__ . '\register', 0 );
@ -182,7 +182,7 @@ function add_row_action( $actions, $post ) {
*/
function handle_activation_action( $post_id ) {
$action = $_REQUEST['action'];
if ( ! in_array( $action, [ 'deactivate', 'reactivate' ] ) ) {
if ( ! in_array( $action, array( 'deactivate', 'reactivate' ) ) ) {
return;
}
@ -202,7 +202,7 @@ function handle_activation_action( $post_id ) {
}
$sendback = wp_get_referer();
$sendback = remove_query_arg( [ 'deactivated', 'reactivated' ], $sendback );
$sendback = remove_query_arg( array( 'deactivated', 'reactivated' ), $sendback );
if ( 'deactivate' === $action ) {
deactivate( $post_id );

View file

@ -18,7 +18,7 @@ use const WordPressDotOrg\FiveForTheFuture\PREFIX;
defined( 'WPINC' ) || die();
const CPT_ID = PREFIX . '_stats_snapshot';
const CPT_ID = PREFIX . '_stats_snapshot';
add_action( 'init', __NAMESPACE__ . '\register_post_types' );
add_action( 'init', __NAMESPACE__ . '\schedule_cron_jobs' );
@ -32,9 +32,9 @@ add_shortcode( PREFIX . '_stats', __NAMESPACE__ . '\render_shortcode' );
*/
function register_post_types() {
$args = array(
'supports' => array( 'custom-fields' ),
'public' => false,
'show_in_rest' => true,
'supports' => array( 'custom-fields' ),
'public' => false,
'show_in_rest' => true,
// Only allow posts to be created programmatically.
'capability_type' => CPT_ID,
@ -120,8 +120,8 @@ function get_snapshot_data() {
* but `WP_Query` doesn't support `DISTINCT` directly, and it's premature at this point. It may be possible
* with the filters mentioned above.
*/
$confirmed_user_ids = array_unique( Contributor\get_contributor_user_ids( $confirmed_contributors ) );
$snapshot_data['confirmed_contributors'] = count( $confirmed_user_ids );
$confirmed_user_ids = array_unique( Contributor\get_contributor_user_ids( $confirmed_contributors ) );
$snapshot_data['confirmed_contributors'] = count( $confirmed_user_ids );
$snapshot_data['confirmed_sponsored_contributors'] = 0;
$contributors_profile_data = get_xprofile_contribution_data( $confirmed_user_ids );
@ -131,7 +131,7 @@ function get_snapshot_data() {
foreach ( $contributors_profile_data as $profile_data ) {
switch ( (int) $profile_data['field_id'] ) {
case XProfile\FIELD_IDS['hours_per_week']:
$user_id = (int) $profile_data['user_id'];
$user_id = (int) $profile_data['user_id'];
$snapshot_data['confirmed_hours'] += absint( $profile_data['value'] );

View file

@ -31,13 +31,11 @@ defined( 'WPINC' ) || die();
function get_xprofile_contribution_data( array $user_ids ) {
global $wpdb;
$sql = $wpdb->prepare(
'
SELECT user_id, field_id, value
FROM bpmain_bp_xprofile_data
WHERE user_id IN ( %1$s )
AND field_id IN ( %2$s )
',
$sql = $wpdb->prepare( '
SELECT user_id, field_id, value
FROM bpmain_bp_xprofile_data
WHERE user_id IN ( %1$s )
AND field_id IN ( %2$s )',
implode( ', ', array_map( 'absint', $user_ids ) ),
implode( ', ', array_map( 'absint', array_values( FIELD_IDS ) ) )
);