mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-01 16:51:18 +03:00
Refactor forms to be able to reuse inputs in multiple contexts
This commit is contained in:
parent
213531ca08
commit
9199e44c66
|
@ -12,6 +12,7 @@ use WP_Error;
|
|||
|
||||
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' );
|
||||
|
||||
|
|
|
@ -136,25 +136,24 @@ function add_meta_boxes() {
|
|||
*/
|
||||
function render_meta_boxes( $pledge, $box ) {
|
||||
$editable = current_user_can( 'edit_pledge', $pledge->ID );
|
||||
$data = array();
|
||||
|
||||
foreach ( get_pledge_meta_config() as $key => $config ) {
|
||||
$data[ $key ] = get_post_meta( $pledge->ID, META_PREFIX . $key, $config['single'] );
|
||||
}
|
||||
|
||||
switch ( $box['id'] ) {
|
||||
case 'pledge-email':
|
||||
$email = get_post_meta( $pledge->ID, META_PREFIX . 'pledge-email', true );
|
||||
$confirmed = get_post_meta( $pledge->ID, META_PREFIX . 'pledge-email-confirmed', true );
|
||||
require FiveForTheFuture\get_views_path() . 'inputs-pledge-org-email.php';
|
||||
break;
|
||||
case 'org-info':
|
||||
$data = array();
|
||||
|
||||
foreach ( get_pledge_meta_config( 'user_input' ) as $key => $config ) {
|
||||
$data[ $key ] = get_post_meta( $pledge->ID, META_PREFIX . $key, $config['single'] );
|
||||
}
|
||||
require FiveForTheFuture\get_views_path() . 'inputs-pledge-org-info.php';
|
||||
break;
|
||||
case 'pledge-contributors':
|
||||
|
||||
case 'pledge-contributors':
|
||||
require FiveForTheFuture\get_views_path() . 'inputs-pledge-contributors.php';
|
||||
break;
|
||||
}
|
||||
|
||||
require dirname( __DIR__ ) . '/views/metabox-' . sanitize_file_name( $box['id'] ) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,3 +28,39 @@ function load() {
|
|||
require_once PATH . 'includes/pledge-form.php';
|
||||
require_once PATH . 'includes/shortcodes.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to the assets directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_assets_path() {
|
||||
return PATH . 'assets/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to the assets URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_assets_url() {
|
||||
return URL . 'assets/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to the includes directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_includes_path() {
|
||||
return PATH . 'includes/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to the views directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_views_path() {
|
||||
return PATH . 'views/';
|
||||
}
|
||||
|
|
|
@ -1,8 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||
|
||||
use function WordPressDotOrg\FiveForTheFuture\get_views_path;
|
||||
|
||||
/** @var array $messages */
|
||||
/** @var bool $updated */
|
||||
?>
|
||||
|
||||
<form id="5ftf-form-pledge-new" action="" method="post">
|
||||
<?php
|
||||
require get_views_path() . 'inputs-pledge-org-info.php';
|
||||
require get_views_path() . 'inputs-pledge-org-logo.php';
|
||||
require get_views_path() . 'inputs-pledge-org-email.php';
|
||||
require get_views_path() . 'inputs-pledge-contributors.php';
|
||||
?>
|
||||
|
||||
<div>
|
||||
<input type="submit" id="5ftf-pledge-submit" name="action" class="button button-primary" value="<?php esc_attr_e( 'Update Pledge', 'wporg' ); ?>" />
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||
|
||||
use function WordPressDotOrg\FiveForTheFuture\get_views_path;
|
||||
|
||||
/** @var array $messages */
|
||||
/** @var bool $complete */
|
||||
|
@ -29,77 +29,14 @@
|
|||
|
||||
<?php else : ?>
|
||||
|
||||
<form action="" method="post">
|
||||
<div>
|
||||
<label for="5ftf-org-name">
|
||||
<?php _e( 'Organization Name', 'wporg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="5ftf-org-name"
|
||||
name="org-name"
|
||||
value="<?php echo esc_attr( filter_input( INPUT_POST, 'org-name' ) ); ?>"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Logo <strong>TODO</strong>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="5ftf-org-description">
|
||||
<?php _e( 'Organization Blurb', 'wporg' ); ?>
|
||||
</label>
|
||||
<textarea
|
||||
id="5ftf-org-description"
|
||||
name="org-description"
|
||||
required
|
||||
>
|
||||
<?php echo esc_html( filter_input( INPUT_POST, 'org-description' ) ); ?>
|
||||
</textarea>
|
||||
<span class="field-help">280 characters</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="5ftf-admin-wporg-username">
|
||||
<?php _e( 'Admin Username', 'wporg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="5ftf-admin-wporg-username"
|
||||
name="admin-wporg-username"
|
||||
value="<?php echo esc_attr( filter_input( INPUT_POST, 'admin-wporg-username' ) ); ?>"
|
||||
required
|
||||
/>
|
||||
<span class="field-help">This user will be responsible for managing your organization's pledge.</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="5ftf-contributor-wporg-usernames">
|
||||
<?php _e( 'Contributing Employee Usernames', 'wporg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="5ftf-contributor-wporg-usernames"
|
||||
name="contributor-wporg-usernames"
|
||||
value="<?php echo esc_attr( filter_input( INPUT_POST, 'contributor-wporg-usernames' ) ); ?>"
|
||||
required
|
||||
/>
|
||||
<span class="field-help">Separate each username with a comma.</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="5ftf-pledge-agreement">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="5ftf-pledge-agreement"
|
||||
name="pledge-agreement"
|
||||
required
|
||||
/>
|
||||
<?php _e( 'I agree', 'wporg' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
<form id="5ftf-form-pledge-new" action="" method="post">
|
||||
<?php
|
||||
require get_views_path() . 'inputs-pledge-org-info.php';
|
||||
require get_views_path() . 'inputs-pledge-org-logo.php';
|
||||
require get_views_path() . 'inputs-pledge-org-email.php';
|
||||
require get_views_path() . 'inputs-pledge-contributors.php';
|
||||
require get_views_path() . 'inputs-pledge-new-misc.php';
|
||||
?>
|
||||
|
||||
<div>
|
||||
<input type="submit" id="5ftf-pledge-submit" name="action" class="button button-primary" value="<?php esc_attr_e( 'Submit Pledge', 'wporg' ); ?>" />
|
||||
|
|
34
plugins/wporg-5ftf/views/inputs-pledge-contributors.php
Normal file
34
plugins/wporg-5ftf/views/inputs-pledge-contributors.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||
|
||||
/** @var bool $editable */
|
||||
/** @var array $data */
|
||||
/** @var array $contributors */
|
||||
?>
|
||||
|
||||
<?php if ( empty( $contributors ) ) : ?>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="5ftf-pledge-contributors">
|
||||
<?php esc_html_e( 'Contributors', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
class="large-text"
|
||||
id="5ftf-pledge-contributors"
|
||||
name="pledge-contributors"
|
||||
value=""
|
||||
required
|
||||
/>
|
||||
<p>
|
||||
<!-- Instructions for inputting wporg usernames -->
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<div class="5ftf-contributors">
|
||||
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
22
plugins/wporg-5ftf/views/inputs-pledge-new-misc.php
Normal file
22
plugins/wporg-5ftf/views/inputs-pledge-new-misc.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||
|
||||
/** @var bool $editable */
|
||||
/** @var array $data */
|
||||
?>
|
||||
|
||||
<div class="form-field">
|
||||
<p>
|
||||
<!-- Statement of agreement to pledge, link to further info maybe? -->
|
||||
</p>
|
||||
|
||||
<input
|
||||
type="checkbox"
|
||||
id="5ftf-pledge-agree"
|
||||
name="pledge-agree"
|
||||
required
|
||||
/>
|
||||
<label for="5ftf-pledge-agree">
|
||||
<?php esc_html_e( 'I agree', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
</div>
|
34
plugins/wporg-5ftf/views/inputs-pledge-org-email.php
Normal file
34
plugins/wporg-5ftf/views/inputs-pledge-org-email.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||
|
||||
/** @var bool $editable */
|
||||
/** @var array $data */
|
||||
?>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="5ftf-pledge-email" class="screen-reader-text">
|
||||
<?php esc_html_e( 'Email', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
class="large-text"
|
||||
id="5ftf-pledge-email"
|
||||
name="org-pledge-email"
|
||||
value="<?php echo esc_attr( $data['pledge-email'] ); ?>"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
/>
|
||||
|
||||
<?php if ( is_admin() ) : ?>
|
||||
<?php if ( $data['pledge-email-confirmed'] ) : ?>
|
||||
<span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
|
||||
<?php esc_html_e( 'Confirmed', 'wporg' ); ?>
|
||||
<?php else : ?>
|
||||
<span class="dashicons dashicons-warning" aria-hidden="true"></span>
|
||||
<?php esc_html_e( 'Unconfirmed', 'wporg' ); ?>
|
||||
<button class="button-secondary">
|
||||
<?php esc_html_e( 'Resend confirmation', 'wporg' ); ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
51
plugins/wporg-5ftf/views/inputs-pledge-org-info.php
Normal file
51
plugins/wporg-5ftf/views/inputs-pledge-org-info.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||
|
||||
/** @var bool $editable */
|
||||
/** @var array $data */
|
||||
?>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="5ftf-org-name">
|
||||
<?php esc_html_e( 'Organization Name', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
class="large-text"
|
||||
id="5ftf-org-name"
|
||||
name="org-name"
|
||||
value="<?php echo esc_attr( $data['org-name'] ); ?>"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="5ftf-org-url">
|
||||
<?php esc_html_e( 'Website Address', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="url"
|
||||
class="large-text"
|
||||
id="5ftf-org-url"
|
||||
name="org-url"
|
||||
value="<?php echo esc_attr( $data['org-url'] ); ?>"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="5ftf-org-description">
|
||||
<?php _e( 'Organization Blurb', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
<textarea
|
||||
class="large-text"
|
||||
id="5ftf-org-description"
|
||||
name="org-description"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
>
|
||||
<?php echo esc_html( $data['org-description'] ); ?>
|
||||
</textarea>
|
||||
</div>
|
17
plugins/wporg-5ftf/views/inputs-pledge-org-logo.php
Normal file
17
plugins/wporg-5ftf/views/inputs-pledge-org-logo.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
namespace WordPressDotOrg\FiveForTheFuture\View;
|
||||
|
||||
/** @var bool $editable */
|
||||
/** @var array $data */
|
||||
?>
|
||||
|
||||
<div class="form-field">
|
||||
<label for="5ftf-org-logo">
|
||||
<?php esc_html_e( 'Logo', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
<input
|
||||
type="file"
|
||||
id="5ftf-org-logo"
|
||||
name="org-logo"
|
||||
/>
|
||||
</div>
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
/** @var bool $editable */
|
||||
/** @var array $data */
|
||||
?>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="5ftf-org-name">
|
||||
<?php esc_html_e( 'Organization Name', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<input
|
||||
type="text"
|
||||
class="large-text"
|
||||
id="5ftf-org-name"
|
||||
name="org-name"
|
||||
value="<?php echo esc_attr( $data['org-name'] ); ?>"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="5ftf-org-url">
|
||||
<?php esc_html_e( 'Website Address', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<input
|
||||
type="url"
|
||||
class="large-text"
|
||||
id="5ftf-org-url"
|
||||
name="org-url"
|
||||
value="<?php echo esc_attr( $data['org-url'] ); ?>"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="5ftf-org-description">
|
||||
<?php _e( 'Organization Blurb', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<textarea
|
||||
class="large-text"
|
||||
id="5ftf-org-description"
|
||||
name="org-description"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
>
|
||||
<?php echo esc_html( $data['org-description'] ); ?>
|
||||
</textarea>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
|
||||
?>
|
||||
|
||||
TBD
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
/** @var bool $editable */
|
||||
/** @var string $email */
|
||||
/** @var bool $confirmed */
|
||||
?>
|
||||
|
||||
<label for="5ftf-pledge-email" class="screen-reader-text">
|
||||
<?php esc_html_e( 'Email', 'wordpressorg' ); ?>
|
||||
</label>
|
||||
|
||||
<input
|
||||
type="text"
|
||||
class="regular-text"
|
||||
id="5ftf-pledge-email"
|
||||
name="org-pledge-email"
|
||||
value="<?php echo esc_attr( $data['pledge-email'] ); ?>"
|
||||
required
|
||||
<?php echo ( $editable ) ? '' : 'readonly'; ?>
|
||||
/>
|
||||
|
||||
<?php if ( $confirmed ) : ?>
|
||||
<span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
|
||||
<?php esc_html_e( 'Confirmed', 'wporg' ); ?>
|
||||
<?php else : ?>
|
||||
<span class="dashicons dashicons-warning" aria-hidden="true"></span>
|
||||
<?php esc_html_e( 'Unconfirmed', 'wporg' ); ?>
|
||||
<button class="button-secondary">
|
||||
<?php esc_html_e( 'Resend confirmation', 'wporg' ); ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
Loading…
Reference in a new issue