HOUR_IN_SECONDS, 'twicedaily' => 12 * HOUR_IN_SECONDS, 'daily' => DAY_IN_SECONDS, ]; $seconds = $map[ $interval_key ] ?? HOUR_IN_SECONDS; $schedules[ self::SCHEDULE ] = [ 'interval' => $seconds, 'display' => __( 'Eventbrite Sync', 'eb4tec' ), ]; return $schedules; } // --------------------------------------------------------------------------- // Sync execution // --------------------------------------------------------------------------- public function run_sync(): void { $result = $this->event_sync->run_full_sync(); set_transient( 'eb4tec_last_sync_result', $result, DAY_IN_SECONDS ); update_option( 'eb4tec_last_sync_timestamp', time() ); } public function handle_sync_now(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'eb4tec' ) ); } check_admin_referer( 'eb4tec_sync_now', '_eb4tec_sync_nonce' ); $this->run_sync(); $user_id = get_current_user_id(); set_transient( "eb4tec_sync_now_result_{$user_id}", get_transient( 'eb4tec_last_sync_result' ), 60 ); $redirect = wp_get_referer() ?: admin_url( 'edit.php?post_type=tribe_events&page=eb4tec-settings' ); wp_safe_redirect( $redirect ); exit; } // --------------------------------------------------------------------------- // Admin notices (sync result — shown on all admin screens) // --------------------------------------------------------------------------- public function admin_notices(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $screen = get_current_screen(); // Only show on TEC / EB4TEC admin screens. if ( ! $screen || ! str_contains( $screen->id ?? '', 'tribe_events' ) ) { return; } $user_id = get_current_user_id(); $sync_result = get_transient( "eb4tec_sync_now_result_{$user_id}" ); if ( ! is_array( $sync_result ) ) { return; } delete_transient( "eb4tec_sync_now_result_{$user_id}" ); $msg = sprintf( __( 'Eventbrite sync complete — %d pulled, %d pushed, %d errors.', 'eb4tec' ), (int) ( $sync_result['pulled'] ?? 0 ), (int) ( $sync_result['pushed'] ?? 0 ), (int) ( $sync_result['errors'] ?? 0 ) ); $class = ( ( $sync_result['errors'] ?? 0 ) > 0 ) ? 'notice-warning' : 'notice-success'; echo '
' . esc_html( $msg ) . '