'theme', 'oribi_sync_saved' => 'no_files', ], admin_url( 'options-general.php?page=oribi-sync' ) ) ); exit; } $theme_data = get_transient( 'oribi_sync_theme_preview' ); if ( ! $theme_data || empty( $theme_data['files'] ) ) { wp_redirect( add_query_arg( [ 'oribi_sync_tab' => 'theme', 'oribi_sync_saved' => 'expired', ], admin_url( 'options-general.php?page=oribi-sync' ) ) ); exit; } $applied = []; $errors = []; $theme_dir = get_template_directory(); foreach ( $theme_data['files'] as $file ) { $relative = $file['relative']; if ( ! in_array( $relative, $selected, true ) ) continue; $dest = $theme_dir . '/' . $relative; // Safety: only allow CSS, JS, JSON, PHP, HTML extensions $ext = strtolower( pathinfo( $relative, PATHINFO_EXTENSION ) ); $allowed = [ 'css', 'js', 'json', 'php', 'html', 'htm', 'svg', 'txt' ]; if ( ! in_array( $ext, $allowed, true ) ) { $errors[] = $relative . ' — file type not allowed.'; continue; } // Create subdirectory if needed $dir = dirname( $dest ); if ( ! is_dir( $dir ) ) { if ( ! wp_mkdir_p( $dir ) ) { $errors[] = $relative . ' — could not create directory.'; continue; } } // Write file $written = file_put_contents( $dest, $file['content'] ); if ( $written === false ) { $errors[] = $relative . ' — write failed (check permissions).'; } else { $applied[] = $relative; } } // Record update_option( 'oribi_sync_theme_applied', [ 'time' => current_time( 'mysql' ), 'applied' => $applied, 'errors' => $errors, ], 'no' ); set_transient( 'oribi_sync_theme_result', [ 'applied' => $applied, 'errors' => $errors, ], 60 ); wp_redirect( add_query_arg( [ 'oribi_sync_tab' => 'theme', 'oribi_sync_saved' => 'theme_applied', ], admin_url( 'options-general.php?page=oribi-sync' ) ) ); exit; } ); // ─── Render theme preview panel (called from settings page) ────────────────── /** * Render the theme preview panel within the settings page. */ function oribi_sync_render_theme_preview(): void { $theme_data = get_transient( 'oribi_sync_theme_preview' ); $theme_result = get_transient( 'oribi_sync_theme_result' ); if ( $theme_result ) delete_transient( 'oribi_sync_theme_result' ); $saved = $_GET['oribi_sync_saved'] ?? ''; ?>

Theme files applied:

No theme files were selected.

Theme preview data expired. Please preview again.

Click Preview Theme Files above to fetch files from the repo's theme/ directory.

Errors fetching theme files:

No files found under theme/ in the repository.

File Status Preview
/> New Changed Unchanged
View content
Current local content

Files will be written directly into the active theme: