From 171c70e03e3c42a4ae7e2f0620303e8507136ea8 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Mon, 18 Nov 2019 14:36:13 -0500 Subject: [PATCH] Endpoints: Update handler to "manage contributors" --- plugins/wporg-5ftf/assets/js/admin.js | 4 ++-- plugins/wporg-5ftf/includes/endpoints.php | 11 ++++++----- plugins/wporg-5ftf/includes/pledge-meta.php | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/wporg-5ftf/assets/js/admin.js b/plugins/wporg-5ftf/assets/js/admin.js index 3777723..4d83add 100644 --- a/plugins/wporg-5ftf/assets/js/admin.js +++ b/plugins/wporg-5ftf/assets/js/admin.js @@ -51,7 +51,7 @@ jQuery( document ).ready( function( $ ) { } /** - * Send an ajax request using the `manage_contributors` action. This function also automatically adds the + * Send an ajax request using the `manage-contributors` action. This function also automatically adds the * nonce, which should be defined in the global FiveForTheFuture variable. * * @param {Object} data - A list of data to send to the endpoint. @@ -65,7 +65,7 @@ jQuery( document ).ready( function( $ ) { type: 'POST', url: ajaxurl, data: Object.assign( { - action: 'manage_contributors', + action: 'manage-contributors', pledge_id: FiveForTheFuture.pledgeId, _ajax_nonce: FiveForTheFuture.manageNonce, }, data ), diff --git a/plugins/wporg-5ftf/includes/endpoints.php b/plugins/wporg-5ftf/includes/endpoints.php index 604bb31..0a49413 100644 --- a/plugins/wporg-5ftf/includes/endpoints.php +++ b/plugins/wporg-5ftf/includes/endpoints.php @@ -7,13 +7,14 @@ namespace WordPressDotOrg\FiveForTheFuture\Endpoints; use WordPressDotOrg\FiveForTheFuture\{ Auth, Contributor, Email }; -add_action( 'wp_ajax_manage_contributors', __NAMESPACE__ . '\handler' ); +add_action( 'wp_ajax_manage-contributors', __NAMESPACE__ . '\manage_contributors_handler' ); /** - * Handle the AJAX request. + * Handle the AJAX request for managing contributors on a pledge. + * This responds to adding, removing, and resending emails to contributors. */ -function handler() { - check_ajax_referer( 'manage-pledge', '_ajax_nonce' ); +function manage_contributors_handler() { + check_ajax_referer( 'manage-contributors', '_ajax_nonce' ); $action = filter_input( INPUT_POST, 'manage_action' ); $pledge_id = filter_input( INPUT_POST, 'pledge_id', FILTER_VALIDATE_INT ); @@ -23,7 +24,7 @@ function handler() { if ( is_wp_error( $authenticated ) ) { wp_die( wp_json_encode( [ - 'success' => true, + 'success' => false, 'message' => $authenticated->get_error_message(), ] ) ); } diff --git a/plugins/wporg-5ftf/includes/pledge-meta.php b/plugins/wporg-5ftf/includes/pledge-meta.php index 213b346..1e9d0d8 100755 --- a/plugins/wporg-5ftf/includes/pledge-meta.php +++ b/plugins/wporg-5ftf/includes/pledge-meta.php @@ -484,7 +484,7 @@ function enqueue_assets() { $script_data = [ 'pledgeId' => get_the_ID(), - 'manageNonce' => wp_create_nonce( 'manage-pledge' ), + 'manageNonce' => wp_create_nonce( 'manage-contributors' ), ]; wp_add_inline_script( '5ftf-admin',