mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-22 02:53:43 +03:00
Views: Modularize success/error notices for DRYness.
This commit is contained in:
parent
7e89d1794a
commit
963dbd41e3
|
@ -23,7 +23,7 @@ add_shortcode( '5ftf_pledge_form_manage', __NAMESPACE__ . '\render_form_manage'
|
||||||
function render_form_new() {
|
function render_form_new() {
|
||||||
$action = isset( $_GET['action'] ) ? filter_input( INPUT_GET, 'action' ) : filter_input( INPUT_POST, 'action' );
|
$action = isset( $_GET['action'] ) ? filter_input( INPUT_GET, 'action' ) : filter_input( INPUT_POST, 'action' );
|
||||||
$data = get_form_submission();
|
$data = get_form_submission();
|
||||||
$messages = [];
|
$errors = [];
|
||||||
$pledge = null;
|
$pledge = null;
|
||||||
$complete = false;
|
$complete = false;
|
||||||
$directory_url = get_permalink( get_page_by_path( 'pledges' ) );
|
$directory_url = get_permalink( get_page_by_path( 'pledges' ) );
|
||||||
|
@ -33,7 +33,7 @@ function render_form_new() {
|
||||||
$pledge_id = process_form_new();
|
$pledge_id = process_form_new();
|
||||||
|
|
||||||
if ( is_wp_error( $pledge_id ) ) {
|
if ( is_wp_error( $pledge_id ) ) {
|
||||||
$messages = array_merge( $messages, $pledge_id->get_error_messages() );
|
$errors = array_merge( $errors, $pledge_id->get_error_messages() );
|
||||||
} elseif ( is_int( $pledge_id ) ) {
|
} elseif ( is_int( $pledge_id ) ) {
|
||||||
$complete = true;
|
$complete = true;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ function render_form_new() {
|
||||||
$unverified_token = filter_input( INPUT_GET, 'auth_token', FILTER_SANITIZE_STRING );
|
$unverified_token = filter_input( INPUT_GET, 'auth_token', FILTER_SANITIZE_STRING );
|
||||||
$email_confirmed = process_pledge_confirmation_email( $pledge_id, $action, $unverified_token );
|
$email_confirmed = process_pledge_confirmation_email( $pledge_id, $action, $unverified_token );
|
||||||
$pledge = get_post( $pledge_id );
|
$pledge = get_post( $pledge_id );
|
||||||
|
|
||||||
} elseif ( filter_input( INPUT_GET, 'resend_pledge_confirmation' ) ) {
|
} elseif ( filter_input( INPUT_GET, 'resend_pledge_confirmation' ) ) {
|
||||||
$pledge_id = filter_input( INPUT_GET, 'pledge_id', FILTER_VALIDATE_INT );
|
$pledge_id = filter_input( INPUT_GET, 'pledge_id', FILTER_VALIDATE_INT );
|
||||||
$complete = true;
|
$complete = true;
|
||||||
|
|
|
@ -9,6 +9,9 @@ use WP_Post;
|
||||||
* @var bool $complete
|
* @var bool $complete
|
||||||
* @var string $directory_url
|
* @var string $directory_url
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require __DIR__ . '/partial-result-messages.php';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- TODO Reveal this once managing an existing pledge is actually possible.
|
<!-- TODO Reveal this once managing an existing pledge is actually possible.
|
||||||
|
@ -17,19 +20,9 @@ use WP_Post;
|
||||||
</p>
|
</p>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<?php if ( ! empty( $messages ) ) : ?>
|
|
||||||
|
|
||||||
<div id="form-message" class="notice notice-error notice-alt">
|
|
||||||
<?php foreach ( $messages as $message ) : ?>
|
|
||||||
<p><?php echo wp_kses_post( $message ); ?></p>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ( true === $complete ) : ?>
|
<?php if ( true === $complete ) : ?>
|
||||||
|
|
||||||
<div id="form-message" class="notice notice-success notice-alt">
|
<div id="form-messages" class="notice notice-success notice-alt">
|
||||||
<p>
|
<p>
|
||||||
<?php esc_html_e( "Thanks for pledging to Five for the Future! Your new pledge profile has been created, and we've emailed you a link to confirm your address. Once that's done, we'll also email confirmation links to the contributors you named in your pledge.", 'wporg' ); ?>
|
<?php esc_html_e( "Thanks for pledging to Five for the Future! Your new pledge profile has been created, and we've emailed you a link to confirm your address. Once that's done, we'll also email confirmation links to the contributors you named in your pledge.", 'wporg' ); ?>
|
||||||
</p>
|
</p>
|
||||||
|
@ -53,7 +46,7 @@ use WP_Post;
|
||||||
|
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
||||||
<form class="pledge-form" id="5ftf-form-pledge-new" action="#form-message" method="post" enctype="multipart/form-data">
|
<form class="pledge-form" id="5ftf-form-pledge-new" action="#form-messages" method="post" enctype="multipart/form-data">
|
||||||
<?php
|
<?php
|
||||||
require get_views_path() . 'inputs-pledge-org-info.php';
|
require get_views_path() . 'inputs-pledge-org-info.php';
|
||||||
require get_views_path() . 'inputs-pledge-contributors.php';
|
require get_views_path() . 'inputs-pledge-contributors.php';
|
||||||
|
|
34
plugins/wporg-5ftf/views/partial-result-messages.php
Normal file
34
plugins/wporg-5ftf/views/partial-result-messages.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||||
|
|
||||||
|
defined( 'WPINC' ) || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array $messages
|
||||||
|
* @var array $errors
|
||||||
|
*/
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div id="form-messages">
|
||||||
|
<?php if ( ! empty( $messages ) ) : ?>
|
||||||
|
<div id="success-messages" class="notice notice-success notice-alt">
|
||||||
|
<?php foreach ( $messages as $message ) : ?>
|
||||||
|
<p>
|
||||||
|
<?php echo wp_kses_post( $message ); ?>
|
||||||
|
</p>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ( ! empty( $errors ) ) : ?>
|
||||||
|
<div id="error-messages" class="notice notice-error notice-alt">
|
||||||
|
<?php foreach ( $errors as $error ) : ?>
|
||||||
|
<p>
|
||||||
|
<?php echo wp_kses_post( $error ); ?>
|
||||||
|
</p>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
Loading…
Reference in a new issue