mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-22 02:53:43 +03:00
Refine pledge meta config and metaboxes
This commit is contained in:
parent
9ccf13b9de
commit
80aca01533
|
@ -24,6 +24,18 @@ add_action( 'save_post', __NAMESPACE__ . '\save_pledge', 10, 2 );
|
|||
*/
|
||||
function get_pledge_meta_config() {
|
||||
return array(
|
||||
'org-description' => array(
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'show_in_rest' => true,
|
||||
'php_filter' => FILTER_SANITIZE_STRING
|
||||
),
|
||||
'org-domain' => array( // This value is derived programmatically from `org-url`.
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'show_in_rest' => false,
|
||||
'php_filter' => FILTER_SANITIZE_STRING,
|
||||
),
|
||||
'org-name' => array(
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
|
@ -36,23 +48,11 @@ function get_pledge_meta_config() {
|
|||
'show_in_rest' => true,
|
||||
'php_filter' => FILTER_VALIDATE_URL,
|
||||
),
|
||||
'org-domain' => array(
|
||||
'pledge-email' => array(
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'sanitize_callback' => 'sanitize_email',
|
||||
'show_in_rest' => false,
|
||||
'php_filter' => FILTER_SANITIZE_STRING,
|
||||
),
|
||||
'org-description' => array(
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'show_in_rest' => true,
|
||||
'php_filter' => FILTER_SANITIZE_STRING
|
||||
),
|
||||
'admin-wporg-username' => array(
|
||||
'single' => true,
|
||||
'sanitize_callback' => 'sanitize_user',
|
||||
'show_in_rest' => false,
|
||||
'php_filter' => FILTER_SANITIZE_STRING
|
||||
'php_filter' => FILTER_VALIDATE_EMAIL
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -78,13 +78,31 @@ function register_pledge_meta() {
|
|||
* @return void
|
||||
*/
|
||||
function add_meta_boxes() {
|
||||
add_meta_box(
|
||||
'pledge-email',
|
||||
__( 'Pledge Email', 'wordpressorg' ),
|
||||
__NAMESPACE__ . '\render_meta_boxes',
|
||||
Pledge\CPT_ID,
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'org-info',
|
||||
__( 'Organization Information', 'wordpressorg' ),
|
||||
__NAMESPACE__ . '\render_meta_boxes',
|
||||
Pledge\CPT_ID,
|
||||
'normal',
|
||||
'default'
|
||||
'high'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'pledge-contributors',
|
||||
__( 'Contributors', 'wordpressorg' ),
|
||||
__NAMESPACE__ . '\render_meta_boxes',
|
||||
Pledge\CPT_ID,
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -95,11 +113,26 @@ function add_meta_boxes() {
|
|||
* @param array $box
|
||||
*/
|
||||
function render_meta_boxes( $pledge, $box ) {
|
||||
$editable = current_user_can( 'edit_pledge', $pledge->ID );
|
||||
|
||||
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 );
|
||||
break;
|
||||
case 'org-info':
|
||||
require dirname( __DIR__ ) . '/views/metabox-' . sanitize_file_name( $box['id'] ) . '.php';
|
||||
$data = array();
|
||||
|
||||
foreach ( get_pledge_meta_config() as $key => $config ) {
|
||||
$data[ $key ] = get_post_meta( $pledge->ID, META_PREFIX . $key, $config['single'] );
|
||||
}
|
||||
break;
|
||||
case 'pledge-contributors':
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
require dirname( __DIR__ ) . '/views/metabox-' . sanitize_file_name( $box['id'] ) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,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,
|
||||
|
|
|
@ -1,39 +1,63 @@
|
|||
<table>
|
||||
<?php
|
||||
/** @var bool $editable */
|
||||
/** @var array $data */
|
||||
?>
|
||||
|
||||
<table class="form-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 for="5ftf-org-name">
|
||||
<?php esc_html_e( 'Organization Name', '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; ?>
|
||||
<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_hours_per_month">
|
||||
<?php _e( 'Hours per Month:', 'wordpressorg' ); ?>
|
||||
<label for="5ftf-org-url">
|
||||
<?php esc_html_e( 'Website Address', '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" />
|
||||
<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>
|
||||
|
|
5
plugins/wporg-5ftf/views/metabox-pledge-contributors.php
Normal file
5
plugins/wporg-5ftf/views/metabox-pledge-contributors.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
?>
|
||||
|
||||
TBD
|
30
plugins/wporg-5ftf/views/metabox-pledge-email.php
Normal file
30
plugins/wporg-5ftf/views/metabox-pledge-email.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?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