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

@ -12,24 +12,22 @@ use WP_Error;
defined( 'WPINC' ) || die();
add_shortcode( 'five_for_the_future_pledge_form', __NAMESPACE__ . '\render_shortcode' );
// 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' );
/**
*
*
* @param $attributes
* @param $content
* Render the form(s) for creating new pledges.
*
* @return false|string
*/
function render_shortcode( $attributes, $content ) {
function render_form_new() {
$action = filter_input( INPUT_POST, 'action' );
$messages = [];
$complete = false;
$html = '';
if ( 'Submit' === $action ) {
$processed = process_form( $_POST );
if ( 'Submit Pledge' === $action ) {
$processed = process_form_new();
if ( is_wp_error( $processed ) ) {
$messages = array_merge( $messages, $processed->get_error_messages() );
@ -38,34 +36,38 @@ function render_shortcode( $attributes, $content ) {
}
}
if ( $complete ) {
$html = wpautop( __( 'Thank you for your submission.', 'wporg' ) );
} else {
ob_start();
require FiveForTheFuture\PATH . 'views/pledge-form.php';
$html = ob_get_clean();
}
ob_start();
require FiveForTheFuture\PATH . 'views/form-pledge-new.php';
return $html;
return ob_get_clean();
}
/**
*
*
* @param array $form_values
*
* @return string|WP_Error String "success" if the form processed correctly. Otherwise WP_Error.
*/
function process_form( array $form_values ) {
$required_fields = PledgeMeta\has_required_pledge_meta( $form_values );
function process_form_new() {
$submission = filter_input_array( INPUT_POST, get_input_filters() );
if ( is_wp_error( $required_fields ) ) {
return $required_fields;
$has_required = PledgeMeta\has_required_pledge_meta( $submission );
if ( is_wp_error( $has_required ) ) {
return $has_required;
}
$domain = PledgeMeta\get_normalized_domain_from_url( $submission['org-url'] );
if ( has_existing_pledge( $domain ) ) {
return new WP_Error(
'existing_pledge',
__( 'A pledge already exists for this domain.', 'wporg' )
);
}
$name = sanitize_meta(
PledgeMeta\META_PREFIX . 'company-name',
$form_values['company-name'],
PledgeMeta\META_PREFIX . 'org-name',
$submission['org-name'],
'post',
Pledge\CPT_ID
);
@ -76,12 +78,108 @@ function process_form( array $form_values ) {
return $created;
}
PledgeMeta\save_pledge_meta( $created, $form_values );
// save teams contirbuted to as terms
//PledgeMeta\save_pledge_meta( $created, $submission );
return 'success';
}
/**
* Render the form(s) for managing existing pledges.
*
* @return false|string
*/
function render_form_manage() {
$action = filter_input( INPUT_POST, 'action' );
$messages = [];
$updated = false;
if ( 'Update Pledge' === $action ) {
$processed = process_form_manage();
if ( is_wp_error( $processed ) ) {
$messages = array_merge( $messages, $processed->get_error_messages() );
} elseif ( 'success' === $processed ) {
$updated = true;
}
}
ob_start();
require FiveForTheFuture\PATH . 'views/form-pledge-manage.php';
return ob_get_clean();
}
/**
*
*
* @return string|WP_Error String "success" if the form processed correctly. Otherwise WP_Error.
*/
function process_form_manage() {
$submission = filter_input_array( INPUT_POST, get_input_filters() );
$has_required = PledgeMeta\has_required_pledge_meta( $submission );
if ( is_wp_error( $has_required ) ) {
return $has_required;
}
$domain = PledgeMeta\get_normalized_domain_from_url( $submission['org-url'] );
if ( has_existing_pledge( $domain ) ) {
return new WP_Error(
'existing_pledge',
__( 'A pledge already exists for this domain.', 'wporg' )
);
}
}
/**
*
*
* @return array
*/
function get_input_filters() {
return array_merge(
// Inputs that correspond to meta values.
wp_list_pluck( PledgeMeta\get_pledge_meta_config( 'user_input' ), 'php_filter' ),
// Inputs with no corresponding meta value.
array(
'contributor-wporg-usernames' => [
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_REQUIRE_ARRAY,
],
'pledge-agreement' => FILTER_VALIDATE_BOOLEAN,
)
);
}
/**
*
*
* @param string $domain
* @param int $current_pledge_id
*
* @return bool
*/
function has_existing_pledge( $domain, int $current_pledge_id = 0 ) {
$args = array(
'post_type' => Pledge\CPT_ID,
'post_status' => array( 'pending', 'publish' ),
'meta_query' => array(
'key' => PledgeMeta\META_PREFIX . 'org-domain',
'value' => $domain,
),
);
if ( $current_pledge_id ) {
$args['exclude'] = array( $current_pledge_id );
}
$matching_pledge = get_posts( $args );
return ! empty( $matching_pledge );
}
/**
*
*
@ -93,8 +191,7 @@ function create_new_pledge( $name ) {
$args = [
'post_type' => Pledge\CPT_ID,
'post_title' => $name,
'post_status' => 'pending',
'post_author' => get_current_user_id(), // TODO is this how we want to do this?
'post_status' => 'draft',
];
return wp_insert_post( $args, true );

View file

@ -11,77 +11,78 @@ use WP_Post, WP_Error;
defined( 'WPINC' ) || die();
const META_PREFIX = FiveForTheFuture\PREFIX . '-';
const META_PREFIX = FiveForTheFuture\PREFIX . '_';
add_action( 'init', __NAMESPACE__ . '\register' );
add_action( 'init', __NAMESPACE__ . '\register_pledge_meta' );
add_action( 'admin_init', __NAMESPACE__ . '\add_meta_boxes' );
add_action( 'save_post', __NAMESPACE__ . '\save_pledge', 10, 2 );
/**
*
*/
function register() {
register_pledge_meta();
}
add_action( 'updated_' . Pledge\CPT_ID . '_meta', __NAMESPACE__ . '\update_generated_meta', 10, 4 );
/**
* Define pledge meta fields and their properties.
*
* @return array
*/
function get_pledge_meta_config() {
return [
'company-name' => [
'show_in_rest' => true,
function get_pledge_meta_config( $context = '' ) {
$user_input = array(
'org-description' => array(
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
'required' => true,
],
'company-url' => [
'show_in_rest' => true,
'php_filter' => FILTER_SANITIZE_STRING
),
'org-name' => array(
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'php_filter' => FILTER_SANITIZE_STRING
),
'org-url' => array(
'single' => true,
'sanitize_callback' => 'esc_url_raw',
'required' => true,
],
'company-email' => [
'show_in_rest' => false,
'show_in_rest' => true,
'php_filter' => FILTER_VALIDATE_URL,
),
'pledge-email' => array(
'single' => true,
'sanitize_callback' => 'sanitize_email',
'required' => true,
],
'company-phone' => [
'show_in_rest' => false,
'php_filter' => FILTER_VALIDATE_EMAIL
),
);
$generated = array(
'org-domain' => array(
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
'required' => false,
],
'company-total-employees' => [
'show_in_rest' => true,
'sanitize_callback' => 'absint',
'required' => true,
],
// todo add # sponsored employees here and also to form, etc
'contact-name' => [
'show_in_rest' => false,
'sanitize_callback' => 'sanitize_text_field',
'required' => true,
],
'contact-wporg-username' => [
'show_in_rest' => false,
'sanitize_callback' => 'sanitize_user',
'required' => true,
],
'pledge-hours' => [
'show_in_rest' => true,
'sanitize_callback' => 'absint',
'required' => true,
],
'pledge-agreement' => [
'show_in_rest' => false,
),
'pledge-email-confirmed' => array(
'single' => true,
'sanitize_callback' => 'wp_validate_boolean',
'required' => true,
],
];
'show_in_rest' => false,
),
);
switch ( $context ) {
case 'user_input':
$return = $user_input;
break;
case 'generated':
$return = $generated;
break;
default:
$return = array_merge( $user_input, $generated );
break;
}
return $return;
}
/**
* Register post meta keys for the custom post type.
*
* @return void
*/
function register_pledge_meta() {
$meta = get_pledge_meta_config();
@ -94,16 +95,36 @@ function register_pledge_meta() {
}
/**
* Adds meta boxes for the custom post type
* Adds meta boxes for the custom post type.
*
* @return void
*/
function add_meta_boxes() {
add_meta_box(
'company-information',
__( 'Company Information', 'wordpressorg' ),
'pledge-email',
__( 'Pledge Email', 'wordpressorg' ),
__NAMESPACE__ . '\render_meta_boxes',
Pledge\CPT_ID,
'normal',
'default'
'high'
);
add_meta_box(
'org-info',
__( 'Organization Information', 'wordpressorg' ),
__NAMESPACE__ . '\render_meta_boxes',
Pledge\CPT_ID,
'normal',
'high'
);
add_meta_box(
'pledge-contributors',
__( 'Contributors', 'wordpressorg' ),
__NAMESPACE__ . '\render_meta_boxes',
Pledge\CPT_ID,
'normal',
'high'
);
}
@ -114,9 +135,23 @@ function add_meta_boxes() {
* @param array $box
*/
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 'company-information':
require dirname( __DIR__ ) . '/views/metabox-' . sanitize_file_name( $box['id'] ) . '.php';
case 'pledge-email':
require FiveForTheFuture\get_views_path() . 'inputs-pledge-org-email.php';
break;
case 'org-info':
require FiveForTheFuture\get_views_path() . 'inputs-pledge-org-info.php';
break;
case 'pledge-contributors':
require FiveForTheFuture\get_views_path() . 'inputs-pledge-contributors.php';
break;
}
}
@ -124,24 +159,30 @@ function render_meta_boxes( $pledge, $box ) {
/**
* Check that an array contains values for all required keys.
*
* @return bool|WP_Error True if all required values are present.
* @return bool|WP_Error True if all required values are present. Otherwise WP_Error.
*/
function has_required_pledge_meta( array $values ) {
$config = get_pledge_meta_config();
$plucked = wp_list_pluck( get_pledge_meta_config(), 'required' );
$required = array_combine( array_keys( $config ), $plucked );
function has_required_pledge_meta( array $submission ) {
$error = new WP_Error();
$required_keys = array_keys( $required, true, true );
$error = new WP_Error();
$required = array_keys( get_pledge_meta_config( 'user_input' ) );
foreach ( $required_keys as $key ) {
if ( ! isset( $values[ $key ] ) || empty( $values[ $key ] ) ) {
foreach ( $required as $key ) {
if ( ! isset( $submission[ $key ] ) || is_null( $submission[ $key ] ) ) {
$error->add(
'required_field',
__( 'Please fill all required fields.', 'wporg' )
'required_field_empty',
sprintf(
__( 'The <code>%s</code> field does not have a value.', 'wporg' ),
sanitize_key( $key )
)
);
} elseif ( false === $submission[ $key ] ) {
$error->add(
'required_field_invalid',
sprintf(
__( 'The <code>%s</code> field has an invalid value.', 'wporg' ),
sanitize_key( $key )
)
);
break;
}
}
@ -153,19 +194,26 @@ function has_required_pledge_meta( array $values ) {
}
/**
* Save the pledge data
* Save the pledge data.
*
* This only fires when the pledge post itself is created or updated.
*
* @param int $pledge_id
* @param WP_Post $pledge
*/
function save_pledge( $pledge_id, $pledge ) {
$action = filter_input( INPUT_GET, 'action' );
$ignored_actions = array( 'trash', 'untrash', 'restore' );
if ( isset( $_GET['action'] ) && in_array( $_GET['action'], $ignored_actions, true ) ) {
if ( $action && in_array( $action, $ignored_actions, true ) ) {
return;
}
if ( ! $pledge || $pledge->post_type !== Pledge\CPT_ID || ! current_user_can( 'edit_pledge', $pledge_id ) ) {
if ( ! $pledge instanceof WP_Post || $pledge->post_type !== Pledge\CPT_ID ) {
return;
}
if ( ! current_user_can( 'edit_pledge', $pledge_id ) ) {
return;
}
@ -173,39 +221,82 @@ function save_pledge( $pledge_id, $pledge ) {
return;
}
if ( is_wp_error( has_required_pledge_meta( $_POST ) ) ) {
$definitions = wp_list_pluck( get_pledge_meta_config( 'user_input' ), 'php_filter' );
$submitted_meta = filter_input_array( INPUT_POST, $definitions );
if ( is_wp_error( has_required_pledge_meta( $submitted_meta ) ) ) {
return;
}
save_pledge_meta( $pledge_id, $_POST );
save_pledge_meta( $pledge_id, $submitted_meta );
}
/**
* Save the pledge's meta fields
* Save the pledge's meta fields.
*
* @param int $pledge_id
* @param array $new_values
*
* @return void
*/
function save_pledge_meta( $pledge_id, $new_values ) {
$keys = array_keys( get_pledge_meta_config() );
$config = get_pledge_meta_config();
foreach ( $keys as $key ) {
$meta_key = META_PREFIX . $key;
if ( isset( $new_values[ $key ] ) ) {
foreach ( $new_values as $key => $value ) {
if ( array_key_exists( $key, $config ) ) {
$meta_key = META_PREFIX . $key;
// Since the sanitize callback is called during this function, it could still end up
// saving an empty value to the database.
update_post_meta( $pledge_id, $meta_key, $new_values[ $key ] );
} else {
delete_post_meta( $pledge_id, $meta_key );
update_post_meta( $pledge_id, $meta_key, $value );
}
}
// maybe set the wporg username as the company author, so they can edit it themselves to keep it updated,
// then make the user a contributor if they don't already have a role on the site
// setup cron to automatically email once per quarter
// "here's all the info we have: x, y, z"
// is that still accurate? if not, click here to update it
// if want to be removed from public listing, emailing support@wordcamp.org
// don't let them edit the "featured" taxonomy, only admins
}
/**
* Updated some generated meta values based on changes in user input meta values.
*
* This is hooked to the `updated_{$meta_type}_meta` action, which only fires if a submitted post meta value
* is different from the previous value. Thus here we assume the values of specific meta keys are changed
* when they come through this function.
*
* @param int $meta_id
* @param int $object_id
* @param string $meta_key
* @param mixed $_meta_value
*
* @return void
*/
function update_generated_meta( $meta_id, $object_id, $meta_key, $_meta_value ) {
switch ( $meta_key ) {
case META_PREFIX . 'org-url':
$domain = get_normalized_domain_from_url( $_meta_value );
update_post_meta( $object_id, META_PREFIX . 'org-domain', $domain );
break;
case META_PREFIX . 'pledge-email':
delete_post_meta( $object_id, META_PREFIX . 'pledge-email-confirmed' );
break;
}
}
/**
* Isolate the domain from a given URL and remove the `www.` if necessary.
*
* @param string $url
*
* @return string
*/
function get_normalized_domain_from_url( $url ) {
$domain = wp_parse_url( $url, PHP_URL_HOST );
$domain = preg_replace( '#^www\.#', '', $domain );
return $domain;
}
// maybe set the wporg username as the company author, so they can edit it themselves to keep it updated,
// then make the user a contributor if they don't already have a role on the site
// setup cron to automatically email once per quarter
// "here's all the info we have: x, y, z"
// is that still accurate? if not, click here to update it
// if want to be removed from public listing, emailing support@wordcamp.org
// don't let them edit the "featured" taxonomy, only admins

View file

@ -16,10 +16,22 @@ const SLUG = 'pledge';
const SLUG_PL = 'pledges';
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
add_action( 'init', __NAMESPACE__ . '\register_custom_post_type', 0 );
add_action( 'init', __NAMESPACE__ . '\register', 0 );
/**
* Register the post type.
* Register all the things.
*
* @return void
*/
function register() {
register_custom_post_type();
register_custom_post_status();
}
/**
* Register the post type(s).
*
* @return void
*/
function register_custom_post_type() {
$labels = array(
@ -49,7 +61,7 @@ function register_custom_post_type() {
$args = array(
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'author', 'revisions' ),
'supports' => array( 'title', 'thumbnail' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
@ -71,3 +83,22 @@ function register_custom_post_type() {
register_post_type( CPT_ID, $args );
}
/**
* Register the post status(es).
*
* @return void
*/
function register_custom_post_status() {
register_post_status(
FiveForTheFuture\PREFIX . '-deactivated',
array(
'label' => __( 'Deactivated', 'wporg' ),
'label_count' => _n_noop( 'Deactivated <span class="count">(%s)</span>', 'Deactivated <span class="count">(%s)</span>', 'wporg' ),
'public' => false,
'internal' => false,
'protected' => true,
CPT_ID => true, // Custom parameter to streamline its use with the Pledge CPT.
)
);
}

View file

@ -5,6 +5,8 @@
* or two, we may want to create a subfolder and have a separate file for each block.
*/
// TODO are we actually using any of this?
namespace WordPressDotOrg\FiveForTheFuture\Blocks;
use WordPressDotOrg\FiveForTheFuture;
use WordPressDotOrg\FiveForTheFuture\Pledge;

View file

@ -23,8 +23,44 @@ add_action( 'plugins_loaded', __NAMESPACE__ . '\load' );
*
*/
function load() {
require_once PATH . 'includes/pledge.php';
require_once PATH . 'includes/pledge-meta.php';
require_once PATH . 'includes/pledge-form.php';
require_once PATH . 'includes/shortcodes.php';
require_once get_includes_path() . 'pledge.php';
require_once get_includes_path() . 'pledge-meta.php';
require_once get_includes_path() . 'pledge-form.php';
require_once get_includes_path() . '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/';
}

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>