Endpoints: Update handler to "manage contributors"

This commit is contained in:
Kelly Dwan 2019-11-18 14:36:13 -05:00
parent 4594c44597
commit 171c70e03e
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D
3 changed files with 9 additions and 8 deletions

View file

@ -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. * nonce, which should be defined in the global FiveForTheFuture variable.
* *
* @param {Object} data - A list of data to send to the endpoint. * @param {Object} data - A list of data to send to the endpoint.
@ -65,7 +65,7 @@ jQuery( document ).ready( function( $ ) {
type: 'POST', type: 'POST',
url: ajaxurl, url: ajaxurl,
data: Object.assign( { data: Object.assign( {
action: 'manage_contributors', action: 'manage-contributors',
pledge_id: FiveForTheFuture.pledgeId, pledge_id: FiveForTheFuture.pledgeId,
_ajax_nonce: FiveForTheFuture.manageNonce, _ajax_nonce: FiveForTheFuture.manageNonce,
}, data ), }, data ),

View file

@ -7,13 +7,14 @@ namespace WordPressDotOrg\FiveForTheFuture\Endpoints;
use WordPressDotOrg\FiveForTheFuture\{ Auth, Contributor, Email }; 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() { function manage_contributors_handler() {
check_ajax_referer( 'manage-pledge', '_ajax_nonce' ); check_ajax_referer( 'manage-contributors', '_ajax_nonce' );
$action = filter_input( INPUT_POST, 'manage_action' ); $action = filter_input( INPUT_POST, 'manage_action' );
$pledge_id = filter_input( INPUT_POST, 'pledge_id', FILTER_VALIDATE_INT ); $pledge_id = filter_input( INPUT_POST, 'pledge_id', FILTER_VALIDATE_INT );
@ -23,7 +24,7 @@ function handler() {
if ( is_wp_error( $authenticated ) ) { if ( is_wp_error( $authenticated ) ) {
wp_die( wp_json_encode( [ wp_die( wp_json_encode( [
'success' => true, 'success' => false,
'message' => $authenticated->get_error_message(), 'message' => $authenticated->get_error_message(),
] ) ); ] ) );
} }

View file

@ -484,7 +484,7 @@ function enqueue_assets() {
$script_data = [ $script_data = [
'pledgeId' => get_the_ID(), 'pledgeId' => get_the_ID(),
'manageNonce' => wp_create_nonce( 'manage-pledge' ), 'manageNonce' => wp_create_nonce( 'manage-contributors' ),
]; ];
wp_add_inline_script( wp_add_inline_script(
'5ftf-admin', '5ftf-admin',