Refactor Oribi Sync settings: remove pages folder option and enhance case-insensitive directory handling
This commit is contained in:
@@ -9,6 +9,21 @@
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Strip a case-insensitive directory prefix from a file path.
|
||||
*
|
||||
* Example: oribi_sync_strip_prefix( 'Theme/header.php', 'theme' ) → 'header.php'
|
||||
*/
|
||||
function oribi_sync_strip_prefix( string $path, string $prefix ): string {
|
||||
$prefix = rtrim( $prefix, '/' ) . '/';
|
||||
if ( strncasecmp( $path, $prefix, strlen( $prefix ) ) === 0 ) {
|
||||
return substr( $path, strlen( $prefix ) );
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
// ─── Gutenberg block helpers ──────────────────────────────────────────────────
|
||||
|
||||
/** Generate a self-closing block comment (standalone or child blocks). */
|
||||
@@ -129,18 +144,12 @@ function oribi_sync_run( bool $dry_run = false ): array {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// ── Filter to selected Pages sub-folder ────────────────────────────────
|
||||
$pages_folder = get_option( 'oribi_sync_pages_folder', '' );
|
||||
// ── Filter to Pages/ directory ─────────────────────────────────────────
|
||||
$synced_slugs = [];
|
||||
$page_files = oribi_sync_filter_tree( $tree, 'Pages' );
|
||||
|
||||
if ( empty( $pages_folder ) ) {
|
||||
$result['skipped'][] = 'Pages sync skipped — no folder selected in settings.';
|
||||
$page_files = [];
|
||||
} else {
|
||||
$page_files = oribi_sync_filter_tree( $tree, 'Pages/' . $pages_folder );
|
||||
if ( empty( $page_files ) ) {
|
||||
$result['errors'][] = 'No files found under Pages/' . $pages_folder . '/ in the repository.';
|
||||
}
|
||||
if ( empty( $page_files ) ) {
|
||||
$result['skipped'][] = 'No files found under Pages/ in the repository.';
|
||||
}
|
||||
|
||||
// ── Process each page file ─────────────────────────────────────────────
|
||||
@@ -274,7 +283,7 @@ function oribi_sync_run( bool $dry_run = false ): array {
|
||||
}
|
||||
|
||||
// ── Trash pages removed from repo ──────────────────────────────────────
|
||||
if ( ! $dry_run && ! empty( $pages_folder ) ) {
|
||||
if ( ! $dry_run ) {
|
||||
$trashed = oribi_sync_trash_removed_pages( $synced_slugs );
|
||||
$result['trashed'] = $trashed;
|
||||
}
|
||||
@@ -456,7 +465,7 @@ function oribi_sync_apply_theme_files( string $api_base, string $branch, string
|
||||
$theme_entries = oribi_sync_filter_tree( $tree, 'theme', true );
|
||||
|
||||
foreach ( $theme_entries as $entry ) {
|
||||
$relative = substr( $entry['path'], strlen( 'theme/' ) );
|
||||
$relative = oribi_sync_strip_prefix( $entry['path'], 'theme' );
|
||||
$ext = strtolower( pathinfo( $relative, PATHINFO_EXTENSION ) );
|
||||
|
||||
if ( ! in_array( $ext, $allowed, true ) ) {
|
||||
@@ -540,7 +549,7 @@ function oribi_sync_fetch_theme_files(): array {
|
||||
|
||||
foreach ( $theme_entries as $entry ) {
|
||||
// Derive relative path by stripping the 'theme/' prefix
|
||||
$relative = substr( $entry['path'], strlen( 'theme/' ) );
|
||||
$relative = oribi_sync_strip_prefix( $entry['path'], 'theme' );
|
||||
$content = oribi_sync_fetch_file( $api_base, $branch, $entry['path'], $provider, $pat );
|
||||
|
||||
if ( is_wp_error( $content ) ) {
|
||||
|
||||
Reference in New Issue
Block a user