Add sub-club selection to the WordPress event editor
All checks were successful
WordPress release / release (push) Successful in 6s
All checks were successful
WordPress release / release (push) Successful in 6s
This commit is contained in:
@@ -177,6 +177,30 @@ final class Admin {
|
||||
$data['organizer'] = array_filter( [ $options['organizer'] ] );
|
||||
}
|
||||
self::event_fields( $data );
|
||||
$scope = (string) get_post_meta( $post->ID, Clubs::EVENT_META, true );
|
||||
$options = Clubs::editor_options();
|
||||
?>
|
||||
<p><label for="burn-event-sub-club"><strong><?php esc_html_e( 'Sub-club', 'burn-events' ); ?></strong></label><br>
|
||||
<select id="burn-event-sub-club" name="be_sub_club" aria-describedby="burn-event-sub-club-help" <?php disabled( (bool) BurnWorks::snapshot( $post->ID ) ); ?>>
|
||||
<option value=""><?php esc_html_e( 'No sub-club (organization calendar)', 'burn-events' ); ?></option>
|
||||
<?php if ( $scope && ! isset( $options[ $scope ] ) ) : ?>
|
||||
<option value="<?php echo esc_attr( $scope ); ?>" selected><?php esc_html_e( 'Current assignment (unavailable)', 'burn-events' ); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php foreach ( $options as $value => $label ) : ?>
|
||||
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $scope, $value ); ?>><?php echo esc_html( $label ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select></p>
|
||||
<p class="description" id="burn-event-sub-club-help"><?php
|
||||
if ( BurnWorks::snapshot( $post->ID ) ) {
|
||||
esc_html_e( 'This assignment is managed in burnWorks.', 'burn-events' );
|
||||
} elseif ( ! $options ) {
|
||||
esc_html_e( 'Connect burnWorks and sync its club directory to populate this list.', 'burn-events' );
|
||||
} else {
|
||||
esc_html_e( 'This determines which CRM sub-club receives the event.', 'burn-events' );
|
||||
}
|
||||
?></p>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
public static function event_fields( array $data, bool $public = false ): void {
|
||||
@@ -424,7 +448,15 @@ final class Admin {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
$current = (string) get_post_meta( $id, Clubs::EVENT_META, true );
|
||||
$scope = ! BurnWorks::snapshot( $id ) && is_string( $_POST['be_sub_club'] ?? null ) ? wp_unslash( $_POST['be_sub_club'] ) : $current;
|
||||
if ( $scope !== $current && '' !== $scope && ! isset( Clubs::editor_options()[ $scope ] ) ) {
|
||||
throw new \InvalidArgumentException( __( 'Select an available sub-club.', 'burn-events' ) );
|
||||
}
|
||||
Events::save( $id, Events::validate_event( wp_unslash( $_POST['be'] ) ) );
|
||||
if ( $scope !== $current ) {
|
||||
Clubs::assign( $id, $scope );
|
||||
}
|
||||
} catch ( \Throwable $error ) {
|
||||
set_transient( 'burn_events_error_' . get_current_user_id(), $error->getMessage(), MINUTE_IN_SECONDS );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user