Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,32 @@ public function common_admin_scripts() {
wp_enqueue_script( 'wcpt-admin' );
wp_enqueue_script( 'select2' );

wp_add_inline_script(
'wcpt-admin',
"jQuery( function( $ ) {
$( document ).on( 'click', '.wcpt-multi-text-add', function() {
var group = $( this ).closest( '.wcpt-multi-text-group' );
var name = group.data( 'name' );
var row = $( '<span class=\"wcpt-multi-text-row\" style=\"display: flex; gap: 4px; margin-bottom: 4px;\">' +
'<input type=\"text\" name=\"' + name + '[]\" value=\"\" style=\"flex: 1;\" />' +
'<button type=\"button\" class=\"button wcpt-multi-text-remove\" title=\"Remove\">&times;</button>' +
'</span>' );
$( this ).before( row );
row.find( 'input' ).focus();
} );

$( document ).on( 'click', '.wcpt-multi-text-remove', function() {
var group = $( this ).closest( '.wcpt-multi-text-group' );
var rows = group.find( '.wcpt-multi-text-row' );
if ( rows.length > 1 ) {
$( this ).closest( '.wcpt-multi-text-row' ).remove();
} else {
$( this ).siblings( 'input' ).val( '' );
}
} );
} );"
);

}

/**
Expand Down Expand Up @@ -537,6 +563,15 @@ static function ( $value ) {
}

switch ( $value ) {
case 'multi-text':
if ( isset( $values[ $key ] ) && is_array( $values[ $key ] ) ) {
$clean = array_values( array_filter( array_map( 'sanitize_text_field', $values[ $key ] ) ) );
update_post_meta( $post_id, $key, $clean );
} else {
update_post_meta( $post_id, $key, array() );
}
break;

case 'text':
case 'deputy_list':
case 'textarea':
Expand Down Expand Up @@ -856,6 +891,36 @@ class="date-field"
<?php echo esc_attr( $readonly ); ?>
/>

<?php
break;
case 'multi-text':
$multi_values = get_post_meta( $post_id, $key, true );

if ( is_string( $multi_values ) && '' !== $multi_values ) {
// Backwards compat: convert old single-value string to array.
$multi_values = array( $multi_values );
} elseif ( ! is_array( $multi_values ) ) {
$multi_values = array( '' );
}

if ( empty( $multi_values ) ) {
$multi_values = array( '' );
}

?>

<span class="wcpt-multi-text-group" data-name="<?php echo esc_attr( $object_name ); ?>">
<?php foreach ( $multi_values as $i => $multi_value ) : ?>
<span class="wcpt-multi-text-row" style="display: flex; gap: 4px; margin-bottom: 4px;">
<input type="text" name="<?php echo esc_attr( $object_name ); ?>[]"
value="<?php echo esc_attr( $multi_value ); ?>"<?php echo esc_attr( $readonly ); ?>
style="flex: 1;" />
<button type="button" class="button wcpt-multi-text-remove" title="<?php esc_attr_e( 'Remove', 'wordcamporg' ); ?>">&times;</button>
</span>
<?php endforeach; ?>
<button type="button" class="button wcpt-multi-text-add"<?php echo esc_attr( $readonly ); ?>><?php esc_html_e( '+ Add another', 'wordcamporg' ); ?></button>
</span>

<?php
break;
case 'textarea':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public static function meta_keys( $meta_group = '' ) {
'Host region' => 'textarea',

// In-person
'Venue Name' => 'text',
'Venue Name' => 'multi-text',
'Physical Address' => 'textarea',
'Maximum Capacity' => 'text',
'Available Rooms' => 'text',
Expand Down Expand Up @@ -590,7 +590,7 @@ public static function meta_keys( $meta_group = '' ) {
'Virtual event only' => 'checkbox',
'Streaming account to use' => 'select-streaming',
'Host region' => 'textarea',
'Venue Name' => 'text',
'Venue Name' => 'multi-text',
'Physical Address' => 'textarea',
'Maximum Capacity' => 'text',
'Available Rooms' => 'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,14 @@ function wcpt_get_wordcamp_venue_name( $wordcamp_id = 0 ) {
$wordcamp_id = wcpt_get_wordcamp_id();
}

return apply_filters( 'wcpt_get_wordcamp_venue_name', get_post_meta( $wordcamp_id, 'Venue Name', true ) );
$venue_name = get_post_meta( $wordcamp_id, 'Venue Name', true );

// Multi-venue support: join array values with comma for display.
if ( is_array( $venue_name ) ) {
$venue_name = implode( ', ', array_filter( $venue_name ) );
}

return apply_filters( 'wcpt_get_wordcamp_venue_name', $venue_name );
}

/**
Expand Down Expand Up @@ -637,10 +644,16 @@ function wcpt_feed_event_info( $content ) {
</p>
<?php endif; ?>

<?php if ( isset( $custom_fields['Venue Name'][0] ) && $custom_fields['Venue Name'][0] ) : ?>
<?php
$venue_display = isset( $custom_fields['Venue Name'][0] ) ? $custom_fields['Venue Name'][0] : '';
if ( is_serialized( $venue_display ) ) {
$venue_display = implode( ', ', array_filter( maybe_unserialize( $venue_display ) ) );
}
?>
<?php if ( $venue_display ) : ?>
<p>
Venue:
<?php echo esc_html( $custom_fields['Venue Name'][0] ); ?>
<?php echo esc_html( $venue_display ); ?>
</p>
<?php endif; ?>

Expand Down
Loading