2 Commits

Author SHA1 Message Date
josh
db4747d85f Choose an Elementor event template during or after migration
All checks were successful
WordPress release / release (push) Successful in 7s
2026-11-12 15:34:43 -05:00
josh
6df287d530 Hide event sub-club field until burnWorks syncs
All checks were successful
WordPress release / release (push) Successful in 5s
2026-11-12 15:17:32 -05:00
10 changed files with 263 additions and 54 deletions

View File

@@ -4,7 +4,7 @@
Publish an events calendar, design single-event pages in Elementor, and sync club events from burnWorks. eventLabs manages schedules, venues, organizers, and series in WordPress and provides its own versioned REST API.
[Download the latest release](https://git.labs.casa/josh/eventLabs/releases/latest) · [API reference](docs/API.md) · [Release guide](docs/RELEASING.md)
[Download the latest release](https://git.labs.casa/josh/eventLabs/releases/latest) · [Migration guide](docs/MIGRATION.md) · [API reference](docs/API.md) · [Release guide](docs/RELEASING.md)
![Month calendar with a multi-day event, category colors, and an event preview](docs/images/calendar.webp)
@@ -23,7 +23,7 @@ Starting with **0.5.2**, the active plugin checks Gitea for stable releases and
- **Schedules** support all-day and timed events, daily through yearly recurrence, additional dates, and exclusions. Link multiple venues and organizers and group related events into series.
- **Maps** load on single events with mapped venues when enabled. The calendar Map view groups events into pins by location and filters them by date range. Save a Geoapify key and enable OpenStreetMap maps under **Events → Settings**.
- **Community submissions** use `[burn_events_submit]` and `[burn_events_mine]`. Submitted events enter Pending Review.
- **Imports and migration** are under **Events → Import and Export**. Upload CSV or iCalendar files, or review a detected The Events Calendar migration. The migration copies drafts with their saved occurrence dates and linked records.
- **Imports and migration** are under **Events → Import and Export**. The Events Calendar migration copies events as drafts with their saved occurrence dates and linked records. Choose a Single Event Template before copying, or apply one to events already copied. Follow the [migration guide](docs/MIGRATION.md) to review and publish the results. The same screen accepts CSV and iCalendar files.
![A single-event page with its photo, venue, map, and calendar links](docs/images/single-event.webp)

View File

@@ -317,7 +317,13 @@
padding: clamp(30px, 5vw, 60px);
background: radial-gradient(ellipse at 15% 100%, #323b80, transparent 75%);
}
.be-single-layout .be-event-title { color: #fff; font-size: clamp(2.2rem, 5vw, 4.05rem); line-height: 1.02; text-wrap: pretty; }
.be-single-layout .be-event-title {
color: #fff;
font: 700 clamp(2.2rem, 5vw, 4.05rem)/1.06 Inter, system-ui, sans-serif;
letter-spacing: -.045em;
overflow-wrap: anywhere;
text-wrap: pretty;
}
.be-single-layout .be-single-date { color: #dce4ff; font-size: clamp(.92rem, 1.7vw, 1.06rem); line-height: 1.5; }
.be-single-layout .be-layout-title .be-status { margin: 0; border-radius: 999px; padding: .3em .8em; background: #dedfff; color: #272d65; }
.be-single-layout .be-layout-photo.e-con { position: relative; min-height: clamp(265px, 33vw, 390px); padding: 0; }

View File

@@ -5,14 +5,44 @@
const endpoint = form.getAttribute('action');
const {__, sprintf} = wp.i18n;
const button = form.querySelector('button[type="submit"]');
const buttons = Array.from(form.querySelectorAll('[data-be-operation]'));
const template = form.querySelector('[name="template_id"]');
const status = form.querySelector('[data-be-migrate-status]');
const errors = form.querySelector('[data-be-migrate-errors]');
const retryableStatuses = new Set([408, 429, 502, 503, 504]);
let copied = 0;
const messages = {
copy: {
count: 'copied',
starting: __('Copying events…', 'burn-events'),
progress: __('Copying events. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
finished: __('Migration finished. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
paused: __('Migration paused. %1$d copied, %2$d already copied. %3$s', 'burn-events'),
},
apply: {
count: 'applied',
starting: __('Applying the template…', 'burn-events'),
progress: __('Applying the template. %1$d applied, %2$d already assigned, %3$d need review.', 'burn-events'),
finished: __('Template assignment finished. %1$d applied, %2$d already assigned, %3$d need review.', 'burn-events'),
paused: __('Template assignment paused. %1$d applied, %2$d already assigned. %3$s', 'burn-events'),
},
};
let operation = '';
let templateId = '0';
let hasCopies = form.dataset.hasCopies === '1';
let processed = 0;
let skipped = 0;
let after = 0;
button.disabled = false;
function updateControls(busy) {
if (template) template.disabled = busy;
for (const button of buttons) {
const canApply = hasCopies && template && template.value !== '0';
button.disabled = busy || (button.value === 'apply' && !canApply);
}
}
template?.addEventListener('change', () => updateControls(false));
updateControls(false);
async function requestBatch(body) {
for (let attempt = 0; ; attempt++) {
@@ -29,16 +59,16 @@
if (requestedDelay > 10000) return response;
if (requestedDelay > delay) delay = requestedDelay;
}
status.textContent = __('Waiting to retry the last migration batch…', 'burn-events');
status.textContent = __('Waiting to retry the last batch…', 'burn-events');
await new Promise(resolve => setTimeout(resolve, delay));
}
}
async function readBatch(response) {
async function readBatch(response, count) {
const result = await response.json().catch(() => null);
if (response.ok && result?.success === true) {
const batch = result.data;
const counts = [batch?.copied, batch?.skipped, batch?.next];
const counts = [batch?.[count], batch?.skipped, batch?.next];
if (counts.every(value => Number.isSafeInteger(value) && value >= 0)
&& (batch.next === 0 || batch.next > after) && Array.isArray(batch.errors)) return batch;
}
@@ -55,39 +85,41 @@
form.addEventListener('submit', async event => {
event.preventDefault();
if (button.disabled) return;
button.disabled = true;
if (after === 0) {
copied = 0;
const button = event.submitter ?? buttons.find(control => !control.disabled);
if (!button || button.disabled) return;
const selectedTemplate = template?.value ?? '0';
if (after === 0 || operation !== button.value || templateId !== selectedTemplate) {
after = 0;
processed = 0;
skipped = 0;
errors.replaceChildren();
}
status.textContent = __('Copying events…', 'burn-events');
operation = button.value;
templateId = selectedTemplate;
const labels = messages[operation];
const body = new URLSearchParams(new FormData(form));
body.set('operation', operation);
updateControls(true);
status.textContent = labels.starting;
try {
do {
body.set('after', String(after));
const batch = await readBatch(await requestBatch(body));
copied += batch.copied;
const batch = await readBatch(await requestBatch(body), labels.count);
processed += batch[labels.count];
skipped += batch.skipped;
if (operation === 'copy' && (processed || skipped)) hasCopies = true;
for (const error of batch.errors) {
const item = document.createElement('li');
item.textContent = error;
errors.append(item);
}
after = batch.next;
status.textContent = sprintf(
after ? __('Copying events. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events')
: __('Migration finished. %1$d copied, %2$d already copied, %3$d need review.', 'burn-events'),
copied, skipped, errors.childElementCount
);
status.textContent = sprintf(after ? labels.progress : labels.finished, processed, skipped, errors.childElementCount);
} while (after);
} catch (error) {
status.textContent = sprintf(
__('Migration paused. %1$d copied, %2$d already copied. %3$s', 'burn-events'), copied, skipped, error.message
);
status.textContent = sprintf(labels.paused, processed, skipped, error.message);
} finally {
button.disabled = false;
updateControls(false);
}
});
})();

View File

@@ -3,7 +3,7 @@
* Plugin Name: eventLabs
* Plugin URI: https://git.labs.casa/josh/eventLabs
* Description: Calendars, recurring events, community submissions, and a Single Event template builder for Elementor.
* Version: 0.5.5
* Version: 0.5.7
* Requires at least: 6.9
* Requires PHP: 8.1
* Author: hostLabs
@@ -16,7 +16,7 @@ declare(strict_types=1);
defined( 'ABSPATH' ) || exit;
define( 'BURN_EVENTS_FILE', __FILE__ );
define( 'BURN_EVENTS_VERSION', '0.5.5' );
define( 'BURN_EVENTS_VERSION', '0.5.7' );
foreach ( [ 'schedule', 'maps', 'events', 'admin', 'map-view', 'calendar-grid', 'calendar', 'community', 'transfer', 'single-event-templates', 'api', 'burnworks', 'clubs', 'legacy-migration', 'updates', 'platform' ] as $module ) {
require_once __DIR__ . '/includes/class-' . $module . '.php';

35
docs/MIGRATION.md Normal file
View File

@@ -0,0 +1,35 @@
# Migrate from The Events Calendar to eventLabs
Use this guide to copy events on a WordPress site that contains The Events Calendar data. The migration uses the records already in that site's database. To test before switching your live calendar, start with a staging clone that includes the database and media library.
## 1. Install eventLabs on the clone
1. Sign in as a WordPress administrator.
2. Install and activate eventLabs through **Plugins → Add Plugin → Upload Plugin**. Existing eventLabs installations can update through **Dashboard → Updates**. The template controls in this guide require eventLabs 0.5.7 or later. [Download eventLabs](https://git.labs.casa/josh/eventLabs/releases/latest)
3. Open **Events → Import and Export** in the eventLabs menu. Under **Migrate from The Events Calendar**, check the count of source events. The importer can read those records while The Events Calendar is inactive.
## 2. Prepare a single event template (optional)
1. Activate Elementor. Elementor Free supports the eventLabs template builder.
2. Go to **Events → Single Event Templates → Create starter template**. The starter layout uses eventLabs widgets for the title, schedule, featured image, description, venue, and other event details. Edit the layout in Elementor and publish it.
3. Return to **Events → Import and Export**. Under **Single event template**, select the published layout to assign it to new copies. **Inherit site default** uses the default from **Single Event Templates** or the built-in layout when no default is set.
## 3. Copy events as drafts
1. Under **Migrate from The Events Calendar**, click **Copy events as drafts**. Keep the tab open until the migration summary appears. Large calendars take time to process in batches.
2. Check the copied, already copied, and need review totals. Each new event is saved as an eventLabs draft. The copy includes event descriptions, saved occurrence dates, categories, tags, featured images, and linked venues, organizers, and series. Source records remain available for comparison.
3. Review the warnings by source event ID. For a missing or invalid schedule, restore or correct the dates in the source calendar and run the copy again. If a request pauses, click **Copy events as drafts** again. A new run skips existing copies, so it can safely pick up the remaining source events.
Imported recurring events keep their saved dates. Set a repeat rule in eventLabs if you need it to generate new occurrences. Set up ticketing, registrations, and calendar display settings separately.
## 4. Apply a template after copying (optional)
1. Open **Events → Import and Export** and choose a published **Single event template**.
2. Click **Apply template to copied events** and wait for the assignment summary. This sets the layout on the existing copies from The Events Calendar, including published copies. It replaces their current template choices.
3. Use the **Single Event Template** box in the event editor to adjust an individual event. Preview a draft or open a published event to check the layout. If an already published page still shows a previous layout, clear your host's page cache and reload it.
## 5. Review, publish, and check the calendar
1. Open the eventLabs **Events** list and filter to **Draft**. Review the schedule, links, and template on representative events. Check a recurring event by opening different dates on the calendar.
2. Publish individual drafts from their editor. To publish a selection, select the drafts in the list, choose **Bulk actions → Edit**, click **Apply**, set **Status** to **Published**, and click **Update**. Repeat for the next page as needed. Review any linked venues, organizers, or series that are still drafts before publishing those too.
3. On the clone, deactivate The Events Calendar when testing eventLabs as the public calendar so eventLabs can serve the calendar and event URLs. Open **Events → Settings → View calendar** and check the list, month, and individual event pages. Choose **Past events** in List view to see historical events.

View File

@@ -177,8 +177,11 @@ 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();
if ( null === $options ) {
return;
}
$scope = (string) get_post_meta( $post->ID, Clubs::EVENT_META, true );
?>
<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 ) ); ?>>
@@ -194,7 +197,7 @@ final class Admin {
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' );
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' );
}
@@ -449,8 +452,9 @@ final class Admin {
}
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 ] ) ) {
$options = ! BurnWorks::snapshot( $id ) && is_string( $_POST['be_sub_club'] ?? null ) ? Clubs::editor_options() : null;
$scope = null !== $options ? wp_unslash( $_POST['be_sub_club'] ) : $current;
if ( $scope !== $current && '' !== $scope && ! isset( $options[ $scope ] ) ) {
throw new \InvalidArgumentException( __( 'Select an available sub-club.', 'burn-events' ) );
}
Events::save( $id, Events::validate_event( wp_unslash( $_POST['be'] ) ) );

View File

@@ -47,7 +47,7 @@ final class Api {
}
}
private static function table(): string {
public static function table(): string {
global $wpdb;
return $wpdb->prefix . 'eventlabs_external_ids';
}
@@ -309,6 +309,9 @@ final class Api {
if ( is_wp_error( $result ) ) {
return $result;
}
if ( ! $id && 'events' === $resource && Legacy_Migration::SOURCE === ( $identity[0] ?? '' ) && ! empty( $payload['migration_template_id'] ) ) {
Single_Event_Templates::assign( $saved_id, (int) $payload['migration_template_id'] );
}
if ( $identity && ! $id && ! $wpdb->insert( self::table(), [
'sync_key' => $sync_key, 'post_id' => $saved_id, 'source' => $identity[0], 'external_id' => $identity[1],
], [ '%s', '%d', '%s', '%s' ] ) ) {

View File

@@ -151,10 +151,20 @@ final class Clubs {
return [ '' => __( 'All events', 'burn-events' ) ] + $workspaces + $clubs;
}
public static function editor_options(): array {
public static function editor_options(): ?array {
$directory = self::directory();
$connected = [];
foreach ( $directory as $club ) {
if ( 'organization' === $club['kind'] && 'active' === $club['status'] && $club['club_id'] === $club['workspace_id'] ) {
$connected[ $club['workspace_id'] ] = true;
}
}
if ( ! $connected ) {
return null;
}
$options = [];
foreach ( self::directory() as $club ) {
if ( 'archived' !== $club['status'] ) {
foreach ( $directory as $club ) {
if ( isset( $connected[ $club['workspace_id'] ] ) && 'subclub' === $club['kind'] && 'active' === $club['status'] ) {
$prefix = $club['workspace_name'] ?: sprintf( __( 'Workspace %s', 'burn-events' ), substr( $club['workspace_id'], 0, 8 ) );
$options[ $club['scope'] ] = $prefix . ' / ' . $club['name'];
}

View File

@@ -16,6 +16,7 @@ final class Legacy_Migration {
private const EVENT = 'tribe_events';
private const CATEGORY = 'tribe_events_cat';
private const BATCH = 8;
private const TEMPLATE_BATCH = 100;
private const ACTION = 'burn_events_legacy_migrate';
private const TYPES = [ 'venue' => 'tribe_venue', 'organizer' => 'tribe_organizer', 'series' => 'tribe_event_series' ];
@@ -50,24 +51,60 @@ final class Legacy_Migration {
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft', 'inherit')", self::EVENT ) );
}
private static function copied_count(): int {
global $wpdb;
$table = Api::table();
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $table x JOIN $wpdb->posts p ON p.ID = x.post_id WHERE x.source = %s AND p.post_type = %s AND p.post_status NOT IN ('trash', 'auto-draft', 'inherit')", self::SOURCE, Events::EVENT ) );
}
public static function section(): void {
$count = self::count();
if ( ! $count && ! self::installed() ) {
$copies = self::copied_count();
if ( ! $count && ! $copies && ! self::installed() ) {
return;
}
$templates = $count || $copies ? Single_Event_Templates::migration_templates() : [];
?>
<section id="eventlabs-migration">
<h2><?php esc_html_e( 'Migrate from The Events Calendar', 'burn-events' ); ?></h2>
<p><a href="<?php echo esc_url( 'https://git.labs.casa/josh/eventLabs/src/branch/main/docs/MIGRATION.md' ); ?>"><?php esc_html_e( 'Read the migration guide', 'burn-events' ); ?></a></p>
<?php if ( ! $count ) : ?>
<p><?php esc_html_e( 'The plugin is installed. No events are available to migrate.', 'burn-events' ); ?></p>
<p><?php esc_html_e( 'No source events are available to copy.', 'burn-events' ); ?></p>
<?php else : ?>
<p><?php printf( esc_html( _n( '%s source event found.', '%s source events found.', $count, 'burn-events' ) ), esc_html( number_format_i18n( $count ) ) ); ?></p>
<p><?php esc_html_e( 'Copy events as drafts with their saved dates, linked venues, organizers and series, categories, tags, and featured images. The source events stay available for review.', 'burn-events' ); ?></p>
<p><?php esc_html_e( 'Imported recurring events use the dates already saved in the source calendar. Set a new repeat rule to generate new dates.', 'burn-events' ); ?></p>
<form data-be-migrate action="<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ); ?>" method="post">
<?php endif; ?>
<?php if ( $copies ) : ?>
<p><?php printf( esc_html( _n( '%s event already copied.', '%s events already copied.', $copies, 'burn-events' ) ), esc_html( number_format_i18n( $copies ) ) ); ?></p>
<?php endif; ?>
<?php if ( ( $count || $copies ) && ! $templates ) : ?>
<p><?php esc_html_e( 'To choose an Elementor layout here, activate Elementor and publish a layout under', 'burn-events' ); ?> <a href="<?php echo esc_url( Single_Event_Templates::list_url() ); ?>"><?php esc_html_e( 'Single Event Templates', 'burn-events' ); ?></a>.</p>
<?php endif; ?>
<?php if ( $count || ( $copies && $templates ) ) : ?>
<form data-be-migrate data-has-copies="<?php echo $copies ? '1' : '0'; ?>" action="<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ); ?>" method="post">
<input type="hidden" name="action" value="<?php echo esc_attr( self::ACTION ); ?>">
<?php wp_nonce_field( self::ACTION ); ?>
<button type="submit" class="button button-primary" disabled><?php esc_html_e( 'Copy events as drafts', 'burn-events' ); ?></button>
<?php if ( $templates ) : ?>
<p>
<label for="be-migration-template"><?php esc_html_e( 'Single event template', 'burn-events' ); ?></label>
<select id="be-migration-template" name="template_id" aria-describedby="be-migration-template-help">
<option value="0"><?php esc_html_e( 'Inherit site default', 'burn-events' ); ?></option>
<?php foreach ( $templates as $template ) : ?>
<option value="<?php echo esc_attr( (string) $template->ID ); ?>"><?php echo esc_html( get_the_title( $template ) ); ?></option>
<?php endforeach; ?>
</select>
</p>
<p class="description" id="be-migration-template-help"><?php esc_html_e( 'Choose a template for new copies. Applying it to copied events replaces their current template, including on published events.', 'burn-events' ); ?></p>
<?php endif; ?>
<p>
<?php if ( $count ) : ?>
<button type="submit" class="button button-primary" data-be-operation value="copy" disabled><?php esc_html_e( 'Copy events as drafts', 'burn-events' ); ?></button>
<?php endif; ?>
<?php if ( $templates ) : ?>
<button type="submit" class="button" data-be-operation value="apply" disabled><?php esc_html_e( 'Apply template to copied events', 'burn-events' ); ?></button>
<?php endif; ?>
</p>
<p data-be-migrate-status role="status"></p>
<ul data-be-migrate-errors></ul>
</form>
@@ -83,11 +120,20 @@ final class Legacy_Migration {
wp_send_json_error( __( 'Refresh the migration page and sign in as an administrator.', 'burn-events' ), $signed_in ? 403 : 401 );
}
$after = is_scalar( $_POST['after'] ?? null ) ? absint( $_POST['after'] ) : 0;
$operation = $_POST['operation'] ?? 'copy';
$template_id = $_POST['template_id'] ?? '0';
if ( ! in_array( $operation, [ 'copy', 'apply' ], true ) || ! is_scalar( $template_id ) || ! ctype_digit( (string) $template_id ) ) {
wp_send_json_error( __( 'Choose a valid migration action and template.', 'burn-events' ), 400 );
}
$template_id = (int) $template_id;
// Other plugins may print during post creation. Keep that output out of the JSON response.
$buffer_level = ob_get_level();
ob_start();
try {
$result = self::batch( $after );
$result = 'apply' === $operation ? self::apply_template_batch( $after, $template_id ) : self::batch( $after, $template_id );
} catch ( InvalidArgumentException $error ) {
$validation_error = $error->getMessage();
$result = null;
} catch ( \Throwable ) {
$result = null;
} finally {
@@ -95,14 +141,21 @@ final class Legacy_Migration {
// Close only buffers opened while copying this batch.
}
}
if ( isset( $validation_error ) ) {
wp_send_json_error( $validation_error, 400 );
}
if ( null === $result ) {
wp_send_json_error( __( 'The source calendar could not be read. You can retry the migration.', 'burn-events' ), 500 );
$message = 'apply' === $operation ? __( 'The copied events could not be updated. You can retry the template assignment.', 'burn-events' ) : __( 'The source calendar could not be read. You can retry the migration.', 'burn-events' );
wp_send_json_error( $message, 500 );
}
wp_send_json_success( $result );
}
public static function batch( int $after ): array {
public static function batch( int $after, int $template_id = 0 ): array {
global $wpdb;
if ( $template_id ) {
self::require_template( $template_id );
}
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND ID > %d AND post_status NOT IN ('trash', 'auto-draft', 'inherit') ORDER BY ID LIMIT %d", self::EVENT, $after, self::BATCH + 1 ) );
if ( $wpdb->last_error ) {
throw new RuntimeException( 'Source event query failed.' );
@@ -112,7 +165,7 @@ final class Legacy_Migration {
foreach ( array_slice( $ids, 0, self::BATCH ) as $id ) {
$after = (int) $id;
try {
++$result[ self::event( $after ) ];
++$result[ self::event( $after, $template_id ) ];
} catch ( InvalidArgumentException $error ) {
$result['errors'][] = sprintf( __( 'Event #%1$d — %2$s', 'burn-events' ), $after, $error->getMessage() );
} catch ( \Throwable $error ) {
@@ -123,7 +176,43 @@ final class Legacy_Migration {
return $result;
}
private static function event( int $id ): string {
private static function require_template( int $template_id ): void {
if ( ! Single_Event_Templates::can_use_for_migration( $template_id ) ) {
throw new InvalidArgumentException( __( 'Choose a published template built with Elementor. Refresh the migration page if the template changed.', 'burn-events' ) );
}
}
public static function apply_template_batch( int $after, int $template_id ): array {
global $wpdb;
self::require_template( $template_id );
$table = Api::table();
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT p.ID FROM $table x JOIN $wpdb->posts p ON p.ID = x.post_id WHERE x.source = %s AND p.post_type = %s AND p.ID > %d AND p.post_status NOT IN ('trash', 'auto-draft', 'inherit') ORDER BY p.ID LIMIT %d", self::SOURCE, Events::EVENT, $after, self::TEMPLATE_BATCH + 1 ) );
if ( $wpdb->last_error ) {
throw new RuntimeException( 'Copied event query failed.' );
}
$result = [ 'applied' => 0, 'skipped' => 0, 'errors' => [], 'next' => 0 ];
foreach ( array_slice( $ids, 0, self::TEMPLATE_BATCH ) as $id ) {
$after = (int) $id;
if ( ! current_user_can( 'edit_post', $after ) ) {
$result['errors'][] = sprintf( __( 'You cannot edit event #%d.', 'burn-events' ), $after );
continue;
}
try {
if ( Single_Event_Templates::assign( $after, $template_id ) ) {
clean_post_cache( $after );
++$result['applied'];
} else {
++$result['skipped'];
}
} catch ( \Throwable ) {
$result['errors'][] = sprintf( __( 'The template could not be assigned to event #%d.', 'burn-events' ), $after );
}
}
$result['next'] = count( $ids ) > self::TEMPLATE_BATCH ? $after : 0;
return $result;
}
private static function event( int $id, int $template_id ): string {
$source = get_post( $id );
if ( ! $source || self::EVENT !== $source->post_type || 'trash' === $source->post_status ) {
throw new InvalidArgumentException( __( 'The source event is unavailable.', 'burn-events' ) );
@@ -146,6 +235,9 @@ final class Legacy_Migration {
'hidden' => self::flag( $id, '_EventHideFromUpcoming' ),
'metadata' => [ 'migration' => [ 'source_post_id' => $id, 'source_status' => $source->post_status, 'saved_dates' => count( $dates ) ] ],
];
if ( $template_id ) {
$payload['migration_template_id'] = $template_id;
}
foreach ( self::TYPES as $type => $post_type ) {
$payload[ $type ] = [];
$links = 'series' === $type ? self::series_ids( $id ) : get_post_meta( $id, '_Event' . ucfirst( $type ) . 'ID', false );

View File

@@ -4,6 +4,7 @@ namespace BurnEvents;
use Elementor\Core\Base\Document;
use Elementor\Plugin as Elementor;
use InvalidArgumentException;
use WP_Post;
defined( 'ABSPATH' ) || exit;
@@ -151,6 +152,41 @@ final class Single_Event_Templates {
return (int) get_post_meta( $event_id, self::EVENT_TEMPLATE_META, true );
}
private static function published_templates(): array {
return get_posts( [
'post_type' => self::POST_TYPE, 'post_status' => 'publish', 'has_password' => false,
'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC',
] );
}
public static function migration_templates(): array {
if ( ! self::is_elementor_ready() ) {
return [];
}
return array_filter( self::published_templates(), static fn( WP_Post $post ): bool => self::can_use_for_migration( $post->ID ) );
}
public static function can_use_for_migration( int $template_id ): bool {
if ( $template_id < 1 || ! self::is_elementor_ready() || ! self::is_layout( get_post( $template_id ) ) ) {
return false;
}
$document = Elementor::instance()->documents->get( $template_id );
$data = get_post_meta( $template_id, Document::ELEMENTOR_DATA_META_KEY, true );
$elements = is_string( $data ) ? json_decode( $data, true ) : null;
return $document instanceof Document && $document->is_built_with_elementor() && is_array( $elements ) && $elements && array_is_list( $elements );
}
public static function assign( int $event_id, int $template_id ): bool {
if ( $event_id < 1 || self::EVENT !== get_post_type( $event_id ) || $template_id < 1 || ! self::is_layout( get_post( $template_id ) ) ) {
throw new InvalidArgumentException( __( 'The event or published template is unavailable.', 'burn-events' ) );
}
if ( self::get_assignment( $event_id ) === $template_id ) {
return false;
}
Events::write_meta( $event_id, self::EVENT_TEMPLATE_META, (string) $template_id );
return true;
}
public static function render( WP_Post $event, ?array $row ): string {
if ( ! self::is_elementor_ready() || Elementor::instance()->preview->is_preview_mode() ) {
return '';
@@ -216,16 +252,7 @@ final class Single_Event_Templates {
public static function assignment_box( WP_Post $post ): void {
$selected = self::get_assignment( $post->ID );
$templates = get_posts(
[
'post_type' => self::POST_TYPE,
'post_status' => 'publish',
'has_password' => false,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
]
);
$templates = self::published_templates();
wp_nonce_field( 'burn_events_save_assignment', 'burn_events_assignment_nonce' );
?>
<label class="screen-reader-text" for="burn-events-assignment"><?php esc_html_e( 'Single Event Template', 'burn-events' ); ?></label>