mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-06 10:45:44 +03:00
Manage Pledge: Update email dialog to use JS submission (#104)
Use the proper dialog behavior for submitting an email to generate a manage link. Fixes #98.
This commit is contained in:
parent
a67ef04505
commit
a11e3c5fa5
14 changed files with 1202 additions and 134 deletions
|
@ -109,7 +109,7 @@ function send_manage_email_handler() {
|
|||
}
|
||||
} else {
|
||||
$error_message = sprintf(
|
||||
__( 'That\'s not the address that we have for this pledge, please try a different one. If none of the addresses you try are working, please <a href="%s">email us</a> for help.', 'wporg-5ftf' ),
|
||||
__( 'That\'s not the address that we have for this pledge. If you don\'t know the email associated with this pledge, <a href="%s">please contact us for help.</a>', 'wporg-5ftf' ),
|
||||
get_permalink( get_page_by_path( 'report' ) )
|
||||
);
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ defined( 'WPINC' ) || die();
|
|||
// Todo make this into simple optionless blocks instead?
|
||||
add_shortcode( '5ftf_pledge_form_new', __NAMESPACE__ . '\render_form_new' );
|
||||
add_shortcode( '5ftf_pledge_form_manage', __NAMESPACE__ . '\render_form_manage' );
|
||||
add_shortcode( '5ftf_pledge_form_manage_link', __NAMESPACE__ . '\render_manage_link_request' );
|
||||
|
||||
/**
|
||||
* Render the form(s) for creating new pledges.
|
||||
|
@ -175,19 +174,6 @@ function render_form_manage() {
|
|||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the `render_manage_link_request` shortcode.
|
||||
*/
|
||||
function render_manage_link_request() {
|
||||
// @todo enable when https://github.com/WordPress/five-for-the-future/issues/6 is done
|
||||
if ( ! defined( 'WPORG_SANDBOXED' ) || ! WPORG_SANDBOXED ) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once FiveForTheFuture\get_views_path() . 'form-pledge-request-manage-link.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a submission from the Manage Existing Pledge form.
|
||||
*
|
||||
|
|
|
@ -18,12 +18,19 @@ const SLUG = 'pledge';
|
|||
const SLUG_PL = 'pledges';
|
||||
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
|
||||
|
||||
add_action( 'init', __NAMESPACE__ . '\register', 0 );
|
||||
add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
|
||||
// Admin hooks.
|
||||
add_action( 'init', __NAMESPACE__ . '\register', 0 );
|
||||
add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
|
||||
add_action( 'pre_get_posts', __NAMESPACE__ . '\filter_query' );
|
||||
// List table columns.
|
||||
add_filter( 'manage_edit-' . CPT_ID . '_columns', __NAMESPACE__ . '\add_list_table_columns' );
|
||||
add_action( 'manage_' . CPT_ID . '_posts_custom_column', __NAMESPACE__ . '\populate_list_table_columns', 10, 2 );
|
||||
|
||||
// Front end hooks.
|
||||
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
|
||||
add_action( 'pledge_footer', __NAMESPACE__ . '\render_manage_link_request' );
|
||||
add_action( 'wp_footer', __NAMESPACE__ . '\render_js_templates' );
|
||||
|
||||
/**
|
||||
* Register all the things.
|
||||
*
|
||||
|
@ -252,3 +259,56 @@ function filter_query( $query ) {
|
|||
// see https://github.com/WordPress/five-for-the-future/issues/70#issuecomment-549066883.
|
||||
$query->set( 'posts_per_page', 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue assets for front-end management.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function enqueue_assets() {
|
||||
wp_register_script( 'wicg-inert', plugins_url( 'assets/js/inert.min.js', __DIR__ ), [], '3.0.0', true );
|
||||
|
||||
if ( CPT_ID === get_post_type() ) {
|
||||
$ver = filemtime( FiveForTheFuture\PATH . '/assets/js/frontend.js' );
|
||||
wp_enqueue_script( '5ftf-frontend', plugins_url( 'assets/js/frontend.js', __DIR__ ), [ 'jquery', 'wp-a11y', 'wp-util', 'wicg-inert' ], $ver, true );
|
||||
|
||||
$script_data = [
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), // The global ajaxurl is not set on the frontend.
|
||||
'pledgeId' => get_the_ID(),
|
||||
'ajaxNonce' => wp_create_nonce( 'send-manage-email' ),
|
||||
];
|
||||
wp_add_inline_script(
|
||||
'5ftf-frontend',
|
||||
sprintf(
|
||||
'var FiveForTheFuture = JSON.parse( decodeURIComponent( \'%s\' ) );',
|
||||
rawurlencode( wp_json_encode( $script_data ) )
|
||||
),
|
||||
'before'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the button to toggle the "Request Manage Email" dialog.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function render_manage_link_request() {
|
||||
// @todo enable when https://github.com/WordPress/five-for-the-future/issues/6 is done
|
||||
if ( ! defined( 'WPORG_SANDBOXED' ) || ! WPORG_SANDBOXED ) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once FiveForTheFuture\get_views_path() . 'button-request-manage-link.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render JS templates at the end of the page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function render_js_templates() {
|
||||
if ( CPT_ID === get_post_type() ) {
|
||||
require_once FiveForTheFuture\get_views_path() . 'modal-request-manage-link.php';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue