Choose an Elementor event template during or after migration
All checks were successful
WordPress release / release (push) Successful in 7s
All checks were successful
WordPress release / release (push) Successful in 7s
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user