Skip to content

Commit

Permalink
add sponsor level to listing, add sponsorship amount and currency met…
Browse files Browse the repository at this point in the history
…a fields and to listing (#1000)
  • Loading branch information
timiwahalahti authored Sep 8, 2023
1 parent dd69c56 commit 4ad78fe
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/** Metabox view */

/** @var string $amount */
/** @var string $available_currencies */
/** @var string $currency */
/** @var string $company_name */
/** @var string $website */
/** @var string $first_name */
Expand All @@ -16,6 +21,56 @@
/** @var string $first_time */
/** @var array $available_countries */
?>
<ul class="wcpt-form">
<li class="wcpt-form-header">
<?php esc_html_e( 'Sponsorship', 'wordcamporg' ); ?>
</li>

<li>
<label for="_wcb_sponsor_amount">
<?php esc_html_e( 'Amount:', 'wordcamporg' ); ?>
</label>

<input
type="number"
class="regular-text"
id="_wcb_sponsor_amount"
name="_wcb_sponsor_amount"
value="<?php echo esc_attr( $amount ); ?>"
step="any"
min="0"
required
/>

<?php wcorg_required_indicator(); ?>

<span class="description"><?php esc_html_e( 'No commas, thousands separators or currency symbols. Ex. 1234.56', 'wordcamporg' ); ?></span>
</li>

<li>
<label for="_wcb_sponsor_currency">
<?php esc_html_e( 'Currency:', 'wordcamporg' ); ?>
</label>

<select
id="_wcb_sponsor_currency"
name="_wcb_sponsor_currency"
class="select-currency"
>
<?php foreach ( $available_currencies as $symbol => $name ) : ?>
<option
value="<?php echo esc_attr( $symbol ); ?>"
<?php selected( $symbol, $currency ); ?>
>
<?php echo ( $symbol ) ? esc_html( $name . ' (' . $symbol . ')' ) : ''; ?>
</option>
<?php endforeach; ?>
</select>

<?php wcorg_required_indicator(); ?>
</li>
</ul>

<ul class="wcpt-form">
<li class="wcpt-form-header">
<?php _e( 'Contact Information', 'wordcamporg' ); ?>
Expand Down
41 changes: 33 additions & 8 deletions public_html/wp-content/plugins/wc-post-types/wc-post-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,9 @@ public function add_meta_boxes() {
* @param WP_Post $sponsor
*/
public function metabox_sponsor_info( $sponsor ) {
$amount = get_post_meta( $sponsor->ID, '_wcb_sponsor_amount', true );
$currency = get_post_meta( $sponsor->ID, '_wcb_sponsor_currency', true );

$company_name = get_post_meta( $sponsor->ID, '_wcpt_sponsor_company_name', true );
$website = get_post_meta( $sponsor->ID, '_wcpt_sponsor_website', true );
$first_name = get_post_meta( $sponsor->ID, '_wcpt_sponsor_first_name', true );
Expand Down Expand Up @@ -1247,6 +1250,8 @@ public function metabox_sponsor_info( $sponsor ) {
$available_countries = wcorg_get_countries();
}

$available_currencies = WordCamp_Budgets::get_currencies();

wp_nonce_field( 'edit-sponsor-info', 'wcpt-meta-sponsor-info' );

require_once __DIR__ . '/views/sponsors/metabox-sponsor-info.php';
Expand Down Expand Up @@ -1376,6 +1381,8 @@ public function save_post_sponsor( $post_id, $post ) {
);

$text_values_wcb = array(
'amount',
'currency',
'first_time',
);

Expand Down Expand Up @@ -1727,14 +1734,15 @@ public function register_taxonomies() {
'wcb_sponsor_level',
'wcb_sponsor',
array(
'labels' => $labels,
'rewrite' => array( 'slug' => 'sponsor_level' ),
'query_var' => 'sponsor_level',
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'rest_base' => 'sponsor_level',
'labels' => $labels,
'rewrite' => array( 'slug' => 'sponsor_level' ),
'query_var' => 'sponsor_level',
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'rest_base' => 'sponsor_level',
)
);

Expand Down Expand Up @@ -1868,6 +1876,15 @@ function( $col ) {
ARRAY_FILTER_USE_KEY
);
break;

case 'manage_wcb_sponsor_posts_columns':
$original_columns = $columns;

$columns = array_slice( $original_columns, 0, 3, true );
$columns += array( 'wcb_sponsor_amount' => __( 'Amount', 'wordcamporg' ) );
$columns += array_slice( $original_columns, 1, null, true );

break;
default:
}

Expand Down Expand Up @@ -1951,6 +1968,14 @@ public function manage_post_types_columns_output( $column, $post_id ) {
case 'wcb_session_track':
echo get_the_term_list( get_the_ID(), 'wcb_track', '', ', ' );
break;

case 'wcb_sponsor_amount':
echo sprintf(
'%1$s %2$s',
esc_html( get_post_meta( get_the_ID(), '_wcb_sponsor_amount', true ) ),
esc_html( get_post_meta( get_the_ID(), '_wcb_sponsor_currency', true ) )
);
break;
default:
}
}
Expand Down

0 comments on commit 4ad78fe

Please sign in to comment.