From 80aca0153331c513abbbb174a1eea6fed2298ace Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Tue, 1 Oct 2019 16:23:22 -0700 Subject: [PATCH] Refine pledge meta config and metaboxes --- plugins/wporg-5ftf/includes/pledge-meta.php | 61 +++++++++++++---- plugins/wporg-5ftf/includes/pledge.php | 2 +- plugins/wporg-5ftf/views/metabox-org-info.php | 68 +++++++++++++------ .../views/metabox-pledge-contributors.php | 5 ++ .../wporg-5ftf/views/metabox-pledge-email.php | 30 ++++++++ 5 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 plugins/wporg-5ftf/views/metabox-pledge-contributors.php create mode 100644 plugins/wporg-5ftf/views/metabox-pledge-email.php diff --git a/plugins/wporg-5ftf/includes/pledge-meta.php b/plugins/wporg-5ftf/includes/pledge-meta.php index 941ccf0..95b4560 100755 --- a/plugins/wporg-5ftf/includes/pledge-meta.php +++ b/plugins/wporg-5ftf/includes/pledge-meta.php @@ -24,35 +24,35 @@ add_action( 'save_post', __NAMESPACE__ . '\save_pledge', 10, 2 ); */ function get_pledge_meta_config() { return array( - 'org-name' => array( + 'org-description' => 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', - 'show_in_rest' => true, - 'php_filter' => FILTER_VALIDATE_URL, - ), - 'org-domain' => array( + '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-description' => array( + 'org-name' => array( 'single' => true, 'sanitize_callback' => 'sanitize_text_field', 'show_in_rest' => true, 'php_filter' => FILTER_SANITIZE_STRING ), - 'admin-wporg-username' => array( + 'org-url' => array( 'single' => true, - 'sanitize_callback' => 'sanitize_user', + 'sanitize_callback' => 'esc_url_raw', + 'show_in_rest' => true, + 'php_filter' => FILTER_VALIDATE_URL, + ), + 'pledge-email' => array( + 'single' => true, + 'sanitize_callback' => 'sanitize_email', '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'; } /** diff --git a/plugins/wporg-5ftf/includes/pledge.php b/plugins/wporg-5ftf/includes/pledge.php index bad1f69..516041f 100755 --- a/plugins/wporg-5ftf/includes/pledge.php +++ b/plugins/wporg-5ftf/includes/pledge.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, diff --git a/plugins/wporg-5ftf/views/metabox-org-info.php b/plugins/wporg-5ftf/views/metabox-org-info.php index 57dba8e..e012115 100755 --- a/plugins/wporg-5ftf/views/metabox-org-info.php +++ b/plugins/wporg-5ftf/views/metabox-org-info.php @@ -1,39 +1,63 @@ - + + +
- url - total # employees - # employees pledged at least part time - total # hours pleged - what else was there? - - - - - + + + + - */ ?>
- - - - - - + + />
- - + + /> +
+ + +
diff --git a/plugins/wporg-5ftf/views/metabox-pledge-contributors.php b/plugins/wporg-5ftf/views/metabox-pledge-contributors.php new file mode 100644 index 0000000..a792de7 --- /dev/null +++ b/plugins/wporg-5ftf/views/metabox-pledge-contributors.php @@ -0,0 +1,5 @@ + + +TBD diff --git a/plugins/wporg-5ftf/views/metabox-pledge-email.php b/plugins/wporg-5ftf/views/metabox-pledge-email.php new file mode 100644 index 0000000..13ef541 --- /dev/null +++ b/plugins/wporg-5ftf/views/metabox-pledge-email.php @@ -0,0 +1,30 @@ + + + + + +/> + + + + + + + + +