base && Events::EVENT === $screen->post_type ) {
wp_enqueue_style( 'burn-events-editor', plugins_url( 'assets/event-editor.css', BURN_EVENTS_FILE ), [], BURN_EVENTS_VERSION );
wp_enqueue_script( 'burn-events-editor', plugins_url( 'assets/event-editor.js', BURN_EVENTS_FILE ), [], BURN_EVENTS_VERSION, true );
}
if ( ! $screen || Events::CATEGORY !== $screen->taxonomy || 'term' !== $screen->base ) {
return;
}
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_add_inline_script( 'wp-color-picker', 'jQuery(function ($) { $(".be-category-color").wpColorPicker(); });' );
}
public static function category_color_field( WP_Term $term ): void {
$color = sanitize_hex_color( (string) get_term_meta( $term->term_id, Calendar_Grid::COLOR_META, true ) );
?>
|
|
'list', 'per_page' => 12, 'timezone' => wp_timezone_string(),
'venue' => 0, 'organizer' => 0, 'anonymous' => false, 'community_edit' => true,
'maps' => false, 'fields' => [], 'definitions' => '',
];
}
public static function menu(): void {
add_submenu_page( 'edit.php?post_type=' . Events::EVENT, __( 'eventLabs Settings', 'burn-events' ), __( 'Settings', 'burn-events' ), 'manage_options', 'burn-events-settings', [ self::class, 'settings_page' ] );
add_submenu_page( 'edit.php?post_type=' . Events::EVENT, __( 'Import and Export Events', 'burn-events' ), __( 'Import and Export', 'burn-events' ), 'manage_options', 'burn-events-transfer', [ Transfer::class, 'admin_page' ] );
}
public static function settings(): void {
register_setting( 'burn_events', self::OPTION, [ 'sanitize_callback' => [ self::class, 'sanitize_options' ] ] );
Maps::register_setting();
}
public static function sanitize_options( $input ): array {
$input = (array) $input;
$view = sanitize_key( $input['view'] ?? 'list' );
$zone = sanitize_text_field( $input['timezone'] ?? '' );
try {
$timezone = ( new DateTimeZone( $zone ) )->getName();
} catch ( \Exception $error ) {
$timezone = wp_timezone_string();
add_settings_error( self::OPTION, 'timezone', __( 'The time zone was reset to the WordPress site time zone.', 'burn-events' ) );
}
$fields = [];
$definitions = sanitize_textarea_field( $input['definitions'] ?? '' );
foreach ( preg_split( '/\R/', $definitions, -1, PREG_SPLIT_NO_EMPTY ) as $line ) {
[ $key, $label, $type, $choices ] = array_pad( explode( '|', $line, 4 ), 4, '' );
$key = sanitize_key( trim( $key ) );
$label = sanitize_text_field( trim( $label ) );
$type = sanitize_key( trim( $type ) );
if ( $key && $label && in_array( $type, [ 'text', 'url', 'checkbox', 'select' ], true ) ) {
$fields[ $key ] = [ 'label' => $label, 'type' => $type, 'choices' => array_values( array_filter( array_map( 'sanitize_text_field', explode( ',', $choices ) ) ) ) ];
}
}
return [
'view' => in_array( $view, Calendar::VIEWS, true ) ? $view : 'list',
'per_page' => max( 1, min( 50, absint( $input['per_page'] ?? 12 ) ) ),
'timezone' => $timezone,
'venue' => absint( $input['venue'] ?? 0 ),
'organizer' => absint( $input['organizer'] ?? 0 ),
'anonymous' => ! empty( $input['anonymous'] ),
'community_edit' => ! empty( $input['community_edit'] ),
'maps' => ! empty( $input['maps'] ),
'definitions' => $definitions,
'fields' => $fields,
];
}
public static function settings_page(): void {
$options = self::options();
?>
ID );
$data['imported_schedule'] = Events::uses_imported_dates( $post->ID );
if ( ! $data['schedule'] ) {
$options = self::options();
$data['venue'] = array_filter( [ $options['venue'] ] );
$data['organizer'] = array_filter( [ $options['organizer'] ] );
}
self::event_fields( $data );
$options = Clubs::editor_options();
if ( null === $options ) {
return;
}
$scope = (string) get_post_meta( $post->ID, Clubs::EVENT_META, true );
?>
ID ) ) {
esc_html_e( 'This assignment is managed in burnWorks.', 'burn-events' );
} elseif ( ! $options ) {
esc_html_e( 'No active sub-clubs have synced from burnWorks.', 'burn-events' );
} else {
esc_html_e( 'This determines which CRM sub-club receives the event.', 'burn-events' );
}
?>
$start->format( 'Y-m-d' ), 'end_date' => $start->format( 'Y-m-d' ), 'start_time' => '10:00', 'end_time' => '11:00',
'timezone' => $options['timezone'], 'all_day' => false, 'repeat' => 'none', 'interval' => 1,
'weekdays' => [], 'monthly' => 'day', 'until' => '', 'count' => 0, 'include' => [], 'exclude' => [],
];
if ( ! $public ) {
self::editor_fields( $data, $rule, $options['fields'] );
return;
}
?>
Events::VENUE, 'organizer' => Events::ORGANIZER ] as $name => $type ) :
?>
$type ) { self::relation_picker( "be[$name]", $type, $data[ $name ] ?? [] ); } ?>
__( 'Does not repeat', 'burn-events' ), 'daily' => __( 'Daily', 'burn-events' ),
'weekly' => __( 'Weekly', 'burn-events' ), 'monthly' => __( 'Monthly', 'burn-events' ), 'yearly' => __( 'Yearly', 'burn-events' ),
];
$open = 'none' !== $rule['repeat'] || ( $editor && ( $rule['include'] || $rule['exclude'] ) );
?>
>
$field ) :
$value = $values[ $key ] ?? '';
?>
$type, 'post_status' => 'publish', 'has_password' => false, 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ] );
}
private static function relation_picker( string $name, string $type, array $selected ): void {
$posts = self::relation_posts( $type );
$selected = array_map( 'intval', $selected );
$choices = array_map( static fn( WP_Post $post ): string => get_the_title( $post ), $posts );
$chosen = [];
foreach ( $posts as $index => $post ) {
if ( in_array( $post->ID, $selected, true ) ) {
$chosen[] = $choices[ $index ];
}
}
$placeholder = __( 'None selected', 'burn-events' );
?>
getMessage(), MINUTE_IN_SECONDS );
}
}
public static function location_box( WP_Post $post ): void {
wp_nonce_field( 'burn_location_details', 'burn_location_nonce' );
$data = Events::location_data( $post->ID );
$labels = [
'address' => __( 'Street address', 'burn-events' ), 'city' => __( 'City', 'burn-events' ),
'region' => __( 'State or region', 'burn-events' ), 'postal' => __( 'Postal code', 'burn-events' ),
'country' => __( 'Country', 'burn-events' ), 'website' => __( 'Website', 'burn-events' ),
'email' => __( 'Email', 'burn-events' ), 'phone' => __( 'Phone', 'burn-events' ),
];
foreach ( $labels as $key => $label ) {
echo '';
}
echo '' . esc_html__( 'Address lookup', 'burn-events' ) . ' ' . esc_html( Maps::lookup_message( $data ) ) . '
';
if ( '' !== $data['latitude'] && '' !== $data['longitude'] ) {
echo '' . esc_html( $data['latitude'] . ', ' . $data['longitude'] ) . '
';
Maps::attribution( $data );
}
if ( Maps::has_key() && Maps::address( $data ) ) {
echo '';
}
}
public static function save_location( int $id ): void {
if ( ! self::valid_save( $id, 'burn_location_nonce', 'burn_location_details' ) || ! is_array( $_POST['be_location'] ?? null ) ) {
return;
}
try {
Events::save_location( $id, wp_unslash( $_POST['be_location'] ), ! empty( $_POST['be_lookup_address'] ) );
} catch ( \Throwable $error ) {
set_transient( 'burn_events_error_' . get_current_user_id(), $error->getMessage(), MINUTE_IN_SECONDS );
}
}
private static function valid_save( int $id, string $key, string $action ): bool {
return ! wp_is_post_autosave( $id ) && ! wp_is_post_revision( $id ) && current_user_can( 'edit_post', $id )
&& isset( $_POST[ $key ] ) && is_string( $_POST[ $key ] ) && wp_verify_nonce( wp_unslash( $_POST[ $key ] ), $action );
}
public static function errors(): void {
$key = 'burn_events_error_' . get_current_user_id();
$error = get_transient( $key );
if ( $error ) {
delete_transient( $key );
echo '' . esc_html( $error ) . '
';
}
}
public static function columns( array $columns ): array {
$columns['burn_event_schedule'] = __( 'Schedule', 'burn-events' );
return $columns;
}
public static function column( string $name, int $id ): void {
if ( 'burn_event_schedule' === $name ) {
$data = Events::event_data( $id );
$row = Events::occurrence( $id );
echo $row ? esc_html( Calendar::period( $row, $data ) ) : esc_html__( 'Unscheduled', 'burn-events' );
if ( $data['schedule'] && 'none' !== $data['schedule']['repeat'] ) {
echo '
' . esc_html__( 'Recurring', 'burn-events' );
}
}
}
}