Remove shortcode, add button & dialog by hooking into actions

This commit is contained in:
Kelly Dwan 2019-11-20 16:58:18 -05:00
parent a67ef04505
commit 04d1a12296
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D
6 changed files with 88 additions and 94 deletions

View file

@ -14,7 +14,6 @@ defined( 'WPINC' ) || die();
// Todo make this into simple optionless blocks instead? // Todo make this into simple optionless blocks instead?
add_shortcode( '5ftf_pledge_form_new', __NAMESPACE__ . '\render_form_new' ); 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', __NAMESPACE__ . '\render_form_manage' );
add_shortcode( '5ftf_pledge_form_manage_link', __NAMESPACE__ . '\render_manage_link_request' );
/** /**
* Render the form(s) for creating new pledges. * Render the form(s) for creating new pledges.
@ -175,19 +174,6 @@ function render_form_manage() {
return ob_get_clean(); 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. * Process a submission from the Manage Existing Pledge form.
* *

View file

@ -18,12 +18,18 @@ const SLUG = 'pledge';
const SLUG_PL = 'pledges'; const SLUG_PL = 'pledges';
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG; const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
add_action( 'init', __NAMESPACE__ . '\register', 0 ); // Admin hooks.
add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' ); add_action( 'init', __NAMESPACE__ . '\register', 0 );
add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
add_action( 'pre_get_posts', __NAMESPACE__ . '\filter_query' ); add_action( 'pre_get_posts', __NAMESPACE__ . '\filter_query' );
// List table columns.
add_filter( 'manage_edit-' . CPT_ID . '_columns', __NAMESPACE__ . '\add_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 ); add_action( 'manage_' . CPT_ID . '_posts_custom_column', __NAMESPACE__ . '\populate_list_table_columns', 10, 2 );
// Front end hooks.
add_action( 'pledge_footer', __NAMESPACE__ . '\render_manage_link_request' );
add_action( 'wp_footer', __NAMESPACE__ . '\render_js_templates' );
/** /**
* Register all the things. * Register all the things.
* *
@ -252,3 +258,28 @@ function filter_query( $query ) {
// see https://github.com/WordPress/five-for-the-future/issues/70#issuecomment-549066883. // see https://github.com/WordPress/five-for-the-future/issues/70#issuecomment-549066883.
$query->set( 'posts_per_page', 100 ); $query->set( 'posts_per_page', 100 );
} }
/**
* 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';
}
}

View file

@ -0,0 +1,13 @@
<?php
namespace WordPressDotOrg\FiveForTheFuture\View;
defined( 'WPINC' ) || die();
?>
<div class="edit-pledge-wrapper">
<button id="toggle-management-link-form" class="button button-link">
<span class="dashicons dashicons-edit" aria-hidden="true"></span>
<?php esc_html_e( 'Edit Pledge', 'wporg-5ftf' ); ?>
</button>
</div>

View file

@ -1,75 +0,0 @@
<?php
namespace WordPressDotOrg\FiveForTheFuture\View;
defined( 'WPINC' ) || die();
/**
* @var array $errors
*/
// Hide it if it hasn't submitted, but show success/error messages if it was submitted.
// phpcs:ignore
$hidden = empty( $errors ) && empty( $_POST['get_manage_pledge_link'] ) ? 'hidden' : '';
?>
<button id="toggle-management-link-form">
<span class="dashicons dashicons-edit"></span>
<?php esc_html_e( 'Edit Pledge', 'wporg-5ftf' ); ?>
</button>
<div id="request-management-link" <?php echo esc_attr( $hidden ); ?> >
<p>
<?php esc_html_e( 'Only pledge admins can edit pledges.', 'wporg-5ftf' ); ?>
</p>
<p>
<?php esc_html_e( "If you're the admin, enter your email address and a confirmation link will be sent to you.", 'wporg-5ftf' ); ?>
</p>
<form action="#form-messages" method="post">
<input type="hidden" name="pledge_id" value="<?php echo esc_attr( get_post()->ID ); ?>" />
<label for="pledge_admin_address">
<?php esc_html_e( 'Email Address', 'wporg-5ftf' ); ?>
</label>
<input
id="pledge_admin_address"
name="pledge_admin_address"
type="email"
required
value=""
/>
<input
type="submit"
name="get_manage_pledge_link"
value="Submit"
/>
<?php require __DIR__ . '/partial-result-messages.php'; ?>
</form>
</div>
<script>
( function() {
var toggleLinkFormButton = document.getElementById( 'toggle-management-link-form' ),
linkForm = document.getElementById( 'request-management-link' );
// Toggle the form when the button is clicked.
toggleLinkFormButton.addEventListener( 'click', function() {
switch( linkForm.hidden ) {
case true:
linkForm.hidden = false;
linkForm.scrollIntoView( { behavior: 'smooth' } );
break;
default:
linkForm.hidden = true;
break;
}
} );
}() );
</script>

View file

@ -0,0 +1,41 @@
<?php
namespace WordPressDotOrg\FiveForTheFuture\View;
defined( 'WPINC' ) || die();
?>
<script type="text/template" id="tmpl-5ftf-send-link-dialog">
<div id="send-link-dialog" role="dialog" class="pledge-dialog" hidden tabindex="-1" aria-label="<?php esc_attr_e( 'Request to edit this pledge', 'wporg-5ftf' ); ?>">
<p>
<?php esc_html_e( 'Only pledge admins can edit pledges.', 'wporg-5ftf' ); ?>
</p>
<p>
<?php esc_html_e( "If you're the admin, enter your email address and a confirmation link will be sent to you.", 'wporg-5ftf' ); ?>
</p>
<form method="post">
<input type="hidden" name="pledge_id" value="<?php echo esc_attr( get_post()->ID ); ?>" />
<label for="pledge_admin_address">
<?php esc_html_e( 'Email Address', 'wporg-5ftf' ); ?>
</label>
<input
id="pledge_admin_address"
name="pledge_admin_address"
type="email"
required
value=""
/>
<input
type="submit"
name="get_manage_pledge_link"
value="<?php esc_attr_e( 'Submit', 'wporg-5ftf' ); ?>"
/>
</form>
<button type="button" class="button button-link pledge-dialog__close" aria-label="Close"><span class="dashicons dashicons-no-alt" aria-hidden="true"></span></button></div>
</div>
</script>

View file

@ -130,9 +130,7 @@ get_header();
</a> </a>
</div> </div>
<div class="edit-pledge-wrapper"> <?php do_action( 'pledge_footer' ); ?>
<?php do_shortcode( '[5ftf_pledge_form_manage_link]' ); ?>
</div>
</footer> </footer>
</article> </article>