Plugin: Refactor to use as foundation for planned pledge workflows (#23)

This starts to address several items in the roadmap, but probably doesn't fully address any of them. It takes the plugin code that was written several months ago, before the scope of this project was fully sorted out, and refactors it to be a starting point for the roadmap.

* Adds template files for form inputs that can be used to both create new pledges and manage existing pledges
* Does some validation and sanitization work on form submissions
* Adds a custom post status for deactivated pledges
This commit is contained in:
Corey McKrill 2019-10-04 12:35:02 -07:00 committed by GitHub
parent 7a355b8314
commit ded645fabc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 613 additions and 323 deletions

View file

@ -0,0 +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-manage" 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>

View file

@ -0,0 +1,46 @@
<?php
namespace WordPressDotOrg\FiveForTheFuture\View;
use function WordPressDotOrg\FiveForTheFuture\get_views_path;
/** @var array $messages */
/** @var bool $complete */
?>
<p>
<a href="#">Manage an existing pledge</a>
</p>
<?php if ( ! empty( $messages ) ) : ?>
<?php foreach ( $messages as $message ) : ?>
<div class="notice notice-error">
<?php echo wpautop( $message ); ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php if ( true === $complete ) : ?>
<div class="notice notice-info">
<?php echo wpautop( __( 'Thank you for your submission. You will receive an email confirmation.', 'wporg' ) ); ?>
</div>
<?php else : ?>
<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' ); ?>" />
</div>
</form>
<?php endif; ?>

View file

@ -1,6 +1,8 @@
<?php // todo i18n
//// change all id/class prefixes to fftf (or something better) b/c not valid to start w/ number
/// ?>
// TODO are we using this, or is all the front end stuff happening in the 5ftF theme now?
?>
<article class="5ftf">
<section class="about">
@ -96,4 +98,4 @@
<?php // link to pledge form ?>
</section>
</article>
</article>

View 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; ?>

View 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>

View 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>

View 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>

View 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>

View file

@ -1,39 +0,0 @@
<table>
<tbody>
url
total # employees
# employees pledged at least part time
total # hours pleged
what else was there?
<?php /*
<tr>
<th>
<label for="_5ftf_wporg_username">
<?php _e( 'WordPress.org Username:', 'wordpressorg' ); ?>
</label>
</th>
<td>
<input id="_5ftf_wporg_username" name="_5ftf_wporg_username" type="text" value="<?php echo esc_attr( $company->_5ftf_wporg_username ); ?>" required class="regular-text" />
<?php if ( $avatar_url ) : ?>
<img src="<?php echo esc_url( $avatar_url ); ?>" width="95" height="95" />
<?php endif; ?>
</td>
</tr>
<tr>
<th>
<label for="_5ftf_hours_per_month">
<?php _e( 'Hours per Month:', 'wordpressorg' ); ?>
</label>
</th>
<td>
<input id="_5ftf_hours_per_month" name="_5ftf_hours_per_month" type="number" value="<?php echo esc_attr( $company->_5ftf_hours_per_month ); ?>" required class="regular-text" />
</td>
</tr>
*/ ?>
</tbody>
</table>

View file

@ -1,155 +0,0 @@
<?php
/**
*
*/
/** @var array $messages */
?>
<?php if ( ! empty( $messages ) ) : ?>
<?php foreach ( $messages as $message ) : ?>
<div class="notice notice-error">
<?php echo wpautop( $message ); ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
<form action="" method="post">
<fieldset>
<legend><?php _e( 'Company Details', 'wporg' ); ?></legend>
<div>
<label for="5ftf-company-name">
<?php _e( 'Company Name', 'wporg' ); ?>
<input
type="text"
id="5ftf-company-name"
name="company-name"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'company-name' ) ); ?>"
required
/>
</label>
</div>
<div>
<label for="5ftf-company-url">
<?php _e( 'Company URL', 'wporg' ); ?>
<input
type="url"
id="5ftf-company-url"
name="company-url"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'company-url' ) ); ?>"
required
/>
</label>
</div>
<div>
<label for="5ftf-company-email">
<?php _e( 'Company Email', 'wporg' ); ?>
<input
type="email"
id="5ftf-company-email"
name="company-email"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'company-email' ) ); ?>"
required
/>
</label>
</div>
<div>
<label for="5ftf-company-phone">
<?php _e( 'Company Phone Number', 'wporg' ); ?>
<input
type="text"
id="5ftf-company-phone"
name="company-phone"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'company-phone' ) ); ?>"
/>
</label>
</div>
<div>
<label for="5ftf-company-total-employees">
<?php _e( 'Total Employees', 'wporg' ); ?>
<input
type="number"
id="5ftf-company-total-employees"
name="company-total-employees"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'company-total-employees' ) ); ?>"
required
/>
</label>
</div>
</fieldset>
<fieldset>
<legend><?php _e( 'Pledge Manager', 'wporg' ); ?></legend>
<div>
<label for="5ftf-contact-name">
<?php _e( 'Name', 'wporg' ); ?>
<input
type="text"
id="5ftf-contact-name"
name="contact-name"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'contact-name' ) ); ?>"
required
/>
</label>
</div>
<div>
<label for="5ftf-contact-wporg-username">
<?php _e( 'WordPress.org User Name', 'wporg' ); ?>
<input
type="text"
id="5ftf-contact-wporg-username"
name="contact-wporg-username"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'contact-wporg-username' ) ); ?>"
required
/>
</label>
</div>
</fieldset>
<fieldset>
<legend><?php _e( 'Pledge', 'wporg' ); ?></legend>
<div>
<label for="5ftf-pledge-hours">
<?php _e( 'Pledged Hours Per Week', 'wporg' ); ?>
<input
type="number"
id="5ftf-pledge-hours"
name="pledge-hours"
value="<?php echo esc_attr( filter_input( INPUT_POST, 'pledge-hours' ) ); ?>"
required
/>
</label>
</div>
<div>
<?php
printf(
__( 'The company pledges that it meets the <a href="%s">expectations</a> of the Five For The Future program and that it will dedicate this amount of employee time per week to the WordPress project', 'wporg' ),
esc_url( '#' )
);
?>
<label>
<input
type="checkbox"
id="5ftf-pledge-agreement"
name="pledge-agreement"
<?php checked( filter_input( INPUT_POST, 'pledge-agreement', FILTER_VALIDATE_BOOLEAN ) ) ?>
required
/>
<?php _e( 'Yes', 'wporg' ); ?>
</label>
</div>
</fieldset>
<div>
<input type="submit" id="5ftf-pledge-submit" name="action" class="button button-primary" value="<?php esc_attr_e( 'Submit', 'wporg' ); ?>" />
</div>
</form>