diff --git a/plugins/wporg-5ftf/assets/js/admin.js b/plugins/wporg-5ftf/assets/js/admin.js new file mode 100644 index 0000000..74403d2 --- /dev/null +++ b/plugins/wporg-5ftf/assets/js/admin.js @@ -0,0 +1,28 @@ +/* global ajaxurl, FiveForTheFuture_ManageNonce, jQuery */ +/* eslint no-alert: "off" */ +jQuery( document ).ready( function( $ ) { + function sendAjaxRequest( data, callback ) { + $.ajax( { + type: 'POST', + url: ajaxurl, + data: { + action: 'manage_contributors', + pledge_id: data.pledgePost || 0, + contributor_id: data.contributorPost || 0, + manage_action: data.action || '', + _ajax_nonce: FiveForTheFuture_ManageNonce, + }, + success: callback, + dataType: 'json', + } ); + } + + $( '.contributor-list [data-action="resend-contributor-confirmation"]' ).click( function( event ) { + event.preventDefault(); + sendAjaxRequest( event.currentTarget.dataset, function( response ) { + if ( response.message ) { + alert( response.message ); + } + } ); + } ); +} ); diff --git a/plugins/wporg-5ftf/includes/endpoints.php b/plugins/wporg-5ftf/includes/endpoints.php new file mode 100644 index 0000000..8e8a1ba --- /dev/null +++ b/plugins/wporg-5ftf/includes/endpoints.php @@ -0,0 +1,35 @@ + true, + 'message' => sprintf( __( 'Confirmation email sent to %s.', 'wporg-5ftf' ), $contribution->post_title ), + ] ) ); + break; + } + + // No matching action, we can just exit. + wp_die(); +} diff --git a/plugins/wporg-5ftf/includes/pledge-meta.php b/plugins/wporg-5ftf/includes/pledge-meta.php index 4a8b53f..6eb7def 100755 --- a/plugins/wporg-5ftf/includes/pledge-meta.php +++ b/plugins/wporg-5ftf/includes/pledge-meta.php @@ -279,13 +279,6 @@ function save_pledge( $pledge_id, $pledge ) { get_page_by_path( 'for-organizations' )->ID ); } - - if ( filter_input( INPUT_POST, 'resend-contributor-confirmation' ) ) { - Email\send_contributor_confirmation_emails( - $pledge_id, - filter_input( INPUT_GET, 'resend-contributor-id', FILTER_VALIDATE_INT ) - ); - } } /** @@ -485,8 +478,13 @@ function enqueue_assets() { $ver = filemtime( FiveForTheFuture\PATH . '/assets/css/admin.css' ); wp_register_style( '5ftf-admin', plugins_url( 'assets/css/admin.css', __DIR__ ), [], $ver ); + $ver = filemtime( FiveForTheFuture\PATH . '/assets/js/admin.js' ); + wp_register_script( '5ftf-admin', plugins_url( 'assets/js/admin.js', __DIR__ ), [ 'jquery' ], $ver ); + wp_localize_script( '5ftf-admin', 'FiveForTheFuture_ManageNonce', wp_create_nonce( 'manage-pledge' ) ); + $current_page = get_current_screen(); if ( Pledge\CPT_ID === $current_page->id ) { wp_enqueue_style( '5ftf-admin' ); + wp_enqueue_script( '5ftf-admin' ); } } diff --git a/plugins/wporg-5ftf/index.php b/plugins/wporg-5ftf/index.php index 070ed41..c165f3b 100755 --- a/plugins/wporg-5ftf/index.php +++ b/plugins/wporg-5ftf/index.php @@ -32,6 +32,7 @@ function load() { require_once get_includes_path() . 'pledge-meta.php'; require_once get_includes_path() . 'pledge-form.php'; require_once get_includes_path() . 'xprofile.php'; + require_once get_includes_path() . 'endpoints.php'; require_once get_includes_path() . 'miscellaneous.php'; // The logger expects things like `$_POST` which aren't set during unit tests. diff --git a/plugins/wporg-5ftf/views/manage-contributors.php b/plugins/wporg-5ftf/views/manage-contributors.php index f8d004b..dd2a238 100644 --- a/plugins/wporg-5ftf/views/manage-contributors.php +++ b/plugins/wporg-5ftf/views/manage-contributors.php @@ -25,18 +25,33 @@ namespace WordPressDotOrg\FiveForTheFuture\View;