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. * etc could create situations where they're leaked to others.
*/ */
function prevent_caching_auth_tokens() { 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'] ) ) { if ( isset( $_GET['auth_token'] ) || isset( $_POST['auth_token'] ) ) {
nocache_headers(); nocache_headers();
} }
@ -162,7 +162,7 @@ function can_manage_pledge( $requested_pledge_id, $auth_token = '' ) {
// A valid token supersedes other auth methods. // A valid token supersedes other auth methods.
if ( true === is_valid_authentication_token( $requested_pledge_id, 'manage_pledge', $auth_token ) ) { if ( true === is_valid_authentication_token( $requested_pledge_id, 'manage_pledge', $auth_token ) ) {
return true; return true;
} else if ( is_user_logged_in() ) { } elseif ( is_user_logged_in() ) {
if ( current_user_can( 'manage_options' ) ) { if ( current_user_can( 'manage_options' ) ) {
return true; return true;
} }

View file

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

View file

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

View file

@ -30,7 +30,7 @@ function render_form_new() {
$is_manage = false; $is_manage = false;
$pledge_id = 0; $pledge_id = 0;
$data = get_form_submission(); $data = get_form_submission();
$errors = []; $errors = array();
$pledge = null; $pledge = null;
$complete = false; $complete = false;
$directory_url = home_url( 'pledges' ); $directory_url = home_url( 'pledges' );
@ -113,8 +113,8 @@ function render_form_manage() {
return ''; return '';
} }
$messages = []; $messages = array();
$errors = []; $errors = array();
$action = sanitize_text_field( $_REQUEST['action'] ?? '' ); $action = sanitize_text_field( $_REQUEST['action'] ?? '' );
$pledge_id = absint( $_REQUEST['pledge_id'] ?? 0 ); $pledge_id = absint( $_REQUEST['pledge_id'] ?? 0 );
@ -123,7 +123,7 @@ function render_form_manage() {
if ( is_wp_error( $can_view_form ) ) { if ( is_wp_error( $can_view_form ) ) {
$errors = array( strip_tags( $can_view_form->get_error_message() ) ); $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( $errors = array(
sprintf( 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' ), __( '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(); ob_start();
require FiveForTheFuture\get_views_path() . 'partial-result-messages.php'; require FiveForTheFuture\get_views_path() . 'partial-result-messages.php';
return ob_get_clean(); return ob_get_clean();
} else if ( 'Update Pledge' === $action ) { } elseif ( 'Update Pledge' === $action ) {
$results = process_form_manage( $pledge_id, $auth_token ); $results = process_form_manage( $pledge_id, $auth_token );
if ( is_wp_error( $results ) ) { 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, $meta_key => $meta_value,
) )
); );
} else if ( '_thumbnail_id' === $meta_key ) { } elseif ( '_thumbnail_id' === $meta_key ) {
add_log_entry( add_log_entry(
$object_id, $object_id,
'pledge_logo_changed', 'pledge_logo_changed',

View file

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

View file

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

View file

@ -18,7 +18,7 @@ use const WordPressDotOrg\FiveForTheFuture\PREFIX;
defined( 'WPINC' ) || die(); 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__ . '\register_post_types' );
add_action( 'init', __NAMESPACE__ . '\schedule_cron_jobs' ); add_action( 'init', __NAMESPACE__ . '\schedule_cron_jobs' );
@ -32,9 +32,9 @@ add_shortcode( PREFIX . '_stats', __NAMESPACE__ . '\render_shortcode' );
*/ */
function register_post_types() { function register_post_types() {
$args = array( $args = array(
'supports' => array( 'custom-fields' ), 'supports' => array( 'custom-fields' ),
'public' => false, 'public' => false,
'show_in_rest' => true, 'show_in_rest' => true,
// Only allow posts to be created programmatically. // Only allow posts to be created programmatically.
'capability_type' => CPT_ID, '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 * but `WP_Query` doesn't support `DISTINCT` directly, and it's premature at this point. It may be possible
* with the filters mentioned above. * with the filters mentioned above.
*/ */
$confirmed_user_ids = array_unique( Contributor\get_contributor_user_ids( $confirmed_contributors ) ); $confirmed_user_ids = array_unique( Contributor\get_contributor_user_ids( $confirmed_contributors ) );
$snapshot_data['confirmed_contributors'] = count( $confirmed_user_ids ); $snapshot_data['confirmed_contributors'] = count( $confirmed_user_ids );
$snapshot_data['confirmed_sponsored_contributors'] = 0; $snapshot_data['confirmed_sponsored_contributors'] = 0;
$contributors_profile_data = get_xprofile_contribution_data( $confirmed_user_ids ); $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 ) { foreach ( $contributors_profile_data as $profile_data ) {
switch ( (int) $profile_data['field_id'] ) { switch ( (int) $profile_data['field_id'] ) {
case XProfile\FIELD_IDS['hours_per_week']: 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'] ); $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 ) { function get_xprofile_contribution_data( array $user_ids ) {
global $wpdb; global $wpdb;
$sql = $wpdb->prepare( $sql = $wpdb->prepare( '
' SELECT user_id, field_id, value
SELECT user_id, field_id, value FROM bpmain_bp_xprofile_data
FROM bpmain_bp_xprofile_data WHERE user_id IN ( %1$s )
WHERE user_id IN ( %1$s ) AND field_id IN ( %2$s )',
AND field_id IN ( %2$s )
',
implode( ', ', array_map( 'absint', $user_ids ) ), implode( ', ', array_map( 'absint', $user_ids ) ),
implode( ', ', array_map( 'absint', array_values( FIELD_IDS ) ) ) implode( ', ', array_map( 'absint', array_values( FIELD_IDS ) ) )
); );