mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-22 19:13:44 +03:00
Use JS + AJAX to resend the confirmation email
This commit is contained in:
parent
7dbc725581
commit
d5c740ae84
28
plugins/wporg-5ftf/assets/js/admin.js
Normal file
28
plugins/wporg-5ftf/assets/js/admin.js
Normal file
|
@ -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 );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
} );
|
35
plugins/wporg-5ftf/includes/endpoints.php
Normal file
35
plugins/wporg-5ftf/includes/endpoints.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Handle submissions to admin-ajax.php.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WordPressDotOrg\FiveForTheFuture\Endpoints;
|
||||||
|
|
||||||
|
use WordPressDotOrg\FiveForTheFuture\{ Contributor, PledgeForm };
|
||||||
|
|
||||||
|
add_action( 'wp_ajax_manage_contributors', __NAMESPACE__ . '\handler' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the AJAX request.
|
||||||
|
*/
|
||||||
|
function handler() {
|
||||||
|
check_ajax_referer( 'manage-pledge', '_ajax_nonce' );
|
||||||
|
|
||||||
|
$action = filter_input( INPUT_POST, 'manage_action' );
|
||||||
|
$pledge_id = filter_input( INPUT_POST, 'pledge_id', FILTER_VALIDATE_INT );
|
||||||
|
$contributor_id = filter_input( INPUT_POST, 'contributor_id', FILTER_VALIDATE_INT );
|
||||||
|
|
||||||
|
switch ( $action ) {
|
||||||
|
case 'resend-contributor-confirmation':
|
||||||
|
$contribution = get_post( $contributor_id );
|
||||||
|
PledgeForm\send_contributor_confirmation_emails( $pledge_id, $contributor_id );
|
||||||
|
wp_die( wp_json_encode( [
|
||||||
|
'success' => true,
|
||||||
|
'message' => sprintf( __( 'Confirmation email sent to %s.', 'wporg-5ftf' ), $contribution->post_title ),
|
||||||
|
] ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No matching action, we can just exit.
|
||||||
|
wp_die();
|
||||||
|
}
|
|
@ -279,13 +279,6 @@ function save_pledge( $pledge_id, $pledge ) {
|
||||||
get_page_by_path( 'for-organizations' )->ID
|
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' );
|
$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__ ), [], $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();
|
$current_page = get_current_screen();
|
||||||
if ( Pledge\CPT_ID === $current_page->id ) {
|
if ( Pledge\CPT_ID === $current_page->id ) {
|
||||||
wp_enqueue_style( '5ftf-admin' );
|
wp_enqueue_style( '5ftf-admin' );
|
||||||
|
wp_enqueue_script( '5ftf-admin' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ function load() {
|
||||||
require_once get_includes_path() . 'pledge-meta.php';
|
require_once get_includes_path() . 'pledge-meta.php';
|
||||||
require_once get_includes_path() . 'pledge-form.php';
|
require_once get_includes_path() . 'pledge-form.php';
|
||||||
require_once get_includes_path() . 'xprofile.php';
|
require_once get_includes_path() . 'xprofile.php';
|
||||||
|
require_once get_includes_path() . 'endpoints.php';
|
||||||
require_once get_includes_path() . 'miscellaneous.php';
|
require_once get_includes_path() . 'miscellaneous.php';
|
||||||
|
|
||||||
// The logger expects things like `$_POST` which aren't set during unit tests.
|
// The logger expects things like `$_POST` which aren't set during unit tests.
|
||||||
|
|
|
@ -25,18 +25,33 @@ namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||||
|
|
||||||
<ul class="contributor-list <?php echo esc_attr( $contributor_status ); ?>">
|
<ul class="contributor-list <?php echo esc_attr( $contributor_status ); ?>">
|
||||||
<?php foreach ( $group as $contributor_post ) :
|
<?php foreach ( $group as $contributor_post ) :
|
||||||
$contributor = get_user_by( 'login', $contributor_post->post_title );
|
$name = $contributor_post->post_title;
|
||||||
|
$contributor = get_user_by( 'login', $name );
|
||||||
|
$remove_confirm = sprintf( __( 'Remove %s from this pledge?', 'wporg-5ftf' ), $name );
|
||||||
|
$remove_label = sprintf( __( 'Remove %s', 'wporg' ), $name );
|
||||||
?>
|
?>
|
||||||
<li>
|
<li>
|
||||||
<button class="button-link button-link-delete" data-action="remove-contributor" data-contributor-post="<?php echo esc_attr( $contributor_post->ID ); ?>" aria-label="<?php esc_html_e( 'Remove', 'wporg' ); ?>">
|
<button
|
||||||
|
class="button-link button-link-delete"
|
||||||
|
data-action="remove-contributor"
|
||||||
|
data-pledge-post="<?php the_ID(); ?>"
|
||||||
|
data-contributor-post="<?php echo esc_attr( $contributor_post->ID ); ?>"
|
||||||
|
data-confirm="<?php echo esc_attr( $remove_confirm ); ?>"
|
||||||
|
aria-label="<?php echo esc_attr( $remove_label ); ?>"
|
||||||
|
>
|
||||||
<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>
|
<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>
|
||||||
</button>
|
</button>
|
||||||
<?php echo get_avatar( $contributor->user_email, 32 ); ?>
|
<?php echo get_avatar( $contributor->user_email, 32 ); ?>
|
||||||
<span class="contributor-list__name">
|
<span class="contributor-list__name">
|
||||||
<?php echo esc_html( $contributor_post->post_title ); ?>
|
<?php echo esc_html( $name ); ?>
|
||||||
</span>
|
</span>
|
||||||
<?php if ( 'pending' === $contributor_post->post_status ) : ?>
|
<?php if ( 'pending' === $contributor_post->post_status ) : ?>
|
||||||
<button class="button" data-action="resend-contributor-confirmation" data-contributor-post="<?php echo esc_attr( $contributor_post->ID ); ?>">
|
<button
|
||||||
|
class="button"
|
||||||
|
data-action="resend-contributor-confirmation"
|
||||||
|
data-pledge-post="<?php the_ID(); ?>"
|
||||||
|
data-contributor-post="<?php echo esc_attr( $contributor_post->ID ); ?>"
|
||||||
|
>
|
||||||
<?php esc_html_e( 'Resend Confirmation', 'wporg' ); ?>
|
<?php esc_html_e( 'Resend Confirmation', 'wporg' ); ?>
|
||||||
</button>
|
</button>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
Loading…
Reference in a new issue