Apply coding standards

This commit is contained in:
Ian Dunn 2019-12-03 12:09:35 -08:00
parent a71a1abd74
commit e4deb6809a
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB
5 changed files with 28 additions and 15 deletions

View file

@ -27,7 +27,7 @@
*/
namespace WordPressDotOrg\FiveForTheFuture\Auth;
use WordPressDotOrg\FiveForTheFuture;
use WP_Error;
defined( 'WPINC' ) || die();
@ -151,7 +151,7 @@ function is_valid_authentication_token( $pledge_id, $action, $unverified_token )
}
/**
* Checks user capabilties or auth token to see if this user can edit the given pledge.
* Checks user capabilities or auth token to see if this user can edit the given pledge.
*
* @param int $requested_pledge_id The pledge to edit.
* @param string $auth_token The supplied auth token to check.
@ -159,14 +159,15 @@ function is_valid_authentication_token( $pledge_id, $action, $unverified_token )
* @return true|WP_Error
*/
function can_manage_pledge( $requested_pledge_id, $auth_token = '' ) {
// A valid token superceeds other auth methods.
// 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() ) {
if ( current_user_can( 'manage_options' ) ) {
return true;
}
return new \WP_Error(
return new WP_Error(
'invalid_token',
sprintf(
__( 'You don\'t have permissions to edit this page. <a href="%s">Request an edit link.</a>', 'wporg-5ftf' ),
@ -175,7 +176,7 @@ function can_manage_pledge( $requested_pledge_id, $auth_token = '' ) {
);
}
return new \WP_Error(
return new WP_Error(
'invalid_token',
sprintf(
__( 'Your link has expired, please <a href="%s">obtain a new one.</a>', 'wporg-5ftf' ),

View file

@ -8,6 +8,7 @@ namespace WordPressDotOrg\FiveForTheFuture\Email;
use WordPressDotOrg\FiveForTheFuture\{ Auth, Contributor };
use const WordPressDotOrg\FiveForTheFuture\PREFIX;
use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX;
use WP_Error;
defined( 'WPINC' ) || die();

View file

@ -30,7 +30,7 @@ function manage_contributors_handler() {
if ( is_wp_error( $authenticated ) ) {
wp_die( wp_json_encode( [
'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' ),
] ) );
}
@ -54,7 +54,7 @@ function manage_contributors_handler() {
break;
case 'add-contributor':
$pledge = get_post( $pledge_id );
$pledge = get_post( $pledge_id );
$new_contributors = Contributor\parse_contributors( $_POST['contributors'] );
if ( is_wp_error( $new_contributors ) ) {
wp_die( wp_json_encode( [
@ -62,6 +62,7 @@ function manage_contributors_handler() {
'message' => $new_contributors->get_error_message(),
] ) );
}
$contributor_ids = Contributor\add_pledge_contributors( $pledge_id, $new_contributors );
if ( 'publish' === $pledge->post_status ) {
foreach ( $contributor_ids as $contributor_id ) {

View file

@ -7,7 +7,7 @@ namespace WordPressDotOrg\FiveForTheFuture\PledgeForm;
use WordPressDotOrg\FiveForTheFuture;
use WordPressDotOrg\FiveForTheFuture\{ Auth, Contributor, Email, Pledge, PledgeMeta };
use WP_Error, WP_User;
use WP_Error;
defined( 'WPINC' ) || die();
@ -27,6 +27,7 @@ add_filter( 'pre_do_shortcode_tag', __NAMESPACE__ . '\process_resend_confirm_ema
*/
function render_form_new() {
$action = isset( $_GET['action'] ) ? filter_input( INPUT_GET, 'action' ) : filter_input( INPUT_POST, 'action' );
$is_manage = false;
$pledge_id = 0;
$data = get_form_submission();
$errors = [];
@ -229,7 +230,7 @@ function process_form_manage( $pledge_id, $auth_token ) {
* @return bool|string
*/
function process_confirmed_email( $value, $tag ) {
if ( ! in_array( $tag, [ '5ftf_pledge_form_new', '5ftf_pledge_form_manage' ] ) ) {
if ( ! in_array( $tag, array( '5ftf_pledge_form_new', '5ftf_pledge_form_manage' ), true ) ) {
return $value;
}
@ -286,7 +287,7 @@ function process_confirmed_email( $value, $tag ) {
* @return bool|string
*/
function process_resend_confirm_email( $value, $tag ) {
if ( ! in_array( $tag, [ '5ftf_pledge_form_new', '5ftf_pledge_form_manage' ] ) ) {
if ( ! in_array( $tag, array( '5ftf_pledge_form_new', '5ftf_pledge_form_manage' ), true ) ) {
return $value;
}

View file

@ -444,7 +444,7 @@ function has_required_pledge_meta( array $submission, $context ) {
$required = array_keys( $meta_config );
foreach ( $required as $key ) {
if ( ! in_array( $context, $meta_config[ $key ]['context'] ) ) {
if ( ! in_array( $context, $meta_config[ $key ]['context'], true ) ) {
continue;
}
@ -529,11 +529,20 @@ function get_normalized_domain_from_url( $url ) {
* @return void
*/
function enqueue_assets() {
$ver = filemtime( FiveForTheFuture\PATH . '/assets/css/admin.css' );
wp_register_style( '5ftf-admin', plugins_url( 'assets/css/admin.css', __DIR__ ), [], $ver );
wp_register_style(
'5ftf-admin',
plugins_url( 'assets/css/admin.css', __DIR__ ),
array(),
filemtime( FiveForTheFuture\PATH . '/assets/css/admin.css' )
);
$ver = filemtime( FiveForTheFuture\PATH . '/assets/js/admin.js' );
wp_register_script( '5ftf-admin', plugins_url( 'assets/js/admin.js', __DIR__ ), [ 'jquery', 'wp-util' ], $ver );
wp_register_script(
'5ftf-admin',
plugins_url( 'assets/js/admin.js', __DIR__ ),
array( 'jquery', 'wp-util' ),
filemtime( FiveForTheFuture\PATH . '/assets/js/admin.js' ),
true
);
$pledge_id = is_admin() ? get_the_ID() : absint( $_REQUEST['pledge_id'] ?? 0 );
$auth_token = sanitize_text_field( $_REQUEST['auth_token'] ?? '' );