Refactor Oribi Sync settings: remove pages folder option and enhance case-insensitive directory handling
This commit is contained in:
@@ -35,12 +35,9 @@ add_action( 'admin_post_oribi_sync_save_settings', function () {
|
||||
$provider = sanitize_text_field( wp_unslash( $_POST['oribi_sync_provider'] ?? '' ) );
|
||||
$pat = wp_unslash( $_POST['oribi_sync_pat'] ?? '' );
|
||||
|
||||
$pages_folder = sanitize_text_field( wp_unslash( $_POST['oribi_sync_pages_folder'] ?? '' ) );
|
||||
|
||||
update_option( 'oribi_sync_repo', $repo, 'no' );
|
||||
update_option( 'oribi_sync_branch', $branch, 'no' );
|
||||
update_option( 'oribi_sync_provider', $provider, 'no' );
|
||||
update_option( 'oribi_sync_pages_folder', $pages_folder, 'no' );
|
||||
|
||||
// Only update PAT if a new one was provided (non-empty)
|
||||
if ( ! empty( $pat ) ) {
|
||||
@@ -135,7 +132,6 @@ function oribi_sync_settings_page() {
|
||||
$repo = get_option( 'oribi_sync_repo', '' );
|
||||
$branch = get_option( 'oribi_sync_branch', 'main' );
|
||||
$provider = get_option( 'oribi_sync_provider', '' );
|
||||
$pages_folder = get_option( 'oribi_sync_pages_folder', '' );
|
||||
$has_pat = ! empty( get_option( 'oribi_sync_pat', '' ) );
|
||||
$last_run = get_option( 'oribi_sync_last_run', '' );
|
||||
$log = get_option( 'oribi_sync_log', [] );
|
||||
@@ -251,22 +247,6 @@ function oribi_sync_settings_page() {
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="oribi_sync_pages_folder">Pages Folder</label></th>
|
||||
<td>
|
||||
<select name="oribi_sync_pages_folder" id="oribi_sync_pages_folder" class="regular-text">
|
||||
<option value="">— Select —</option>
|
||||
<?php if ( ! empty( $pages_folder ) ): ?>
|
||||
<option value="<?php echo esc_attr( $pages_folder ); ?>" selected>
|
||||
<?php echo esc_html( $pages_folder ); ?>
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
<button type="button" id="oribi-load-folders" class="button">Load</button>
|
||||
<span id="oribi-folders-status" class="oribi-sync-muted"></span>
|
||||
<p class="description">Sub-folder inside <code>Pages/</code> to sync from.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button( 'Save Settings' ); ?>
|
||||
@@ -386,42 +366,6 @@ function oribi_sync_settings_page() {
|
||||
</details>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var btn = document.getElementById('oribi-load-folders');
|
||||
var select = document.getElementById('oribi_sync_pages_folder');
|
||||
var status = document.getElementById('oribi-folders-status');
|
||||
if ( ! btn || ! select ) return;
|
||||
|
||||
btn.addEventListener('click', function () {
|
||||
status.textContent = 'Loading…';
|
||||
btn.disabled = true;
|
||||
|
||||
fetch('<?php echo esc_js( rest_url( 'oribi-sync/v1/repo-folders' ) ); ?>', {
|
||||
method: 'GET',
|
||||
headers: { 'X-WP-Nonce': '<?php echo esc_js( wp_create_nonce( 'wp_rest' ) ); ?>' }
|
||||
})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
if ( data.error ) { status.textContent = '✗ ' + data.error; btn.disabled = false; return; }
|
||||
var currentVal = select.value;
|
||||
while ( select.options.length > 1 ) select.remove(1);
|
||||
if ( ! data.folders || ! data.folders.length ) { status.textContent = 'No folders found.'; btn.disabled = false; return; }
|
||||
data.folders.forEach(function (f) {
|
||||
var o = document.createElement('option');
|
||||
o.value = f; o.textContent = f;
|
||||
if ( f === currentVal ) o.selected = true;
|
||||
select.appendChild(o);
|
||||
});
|
||||
if ( currentVal && select.querySelector('option[value="' + currentVal + '"]') ) select.value = currentVal;
|
||||
status.textContent = data.folders.length + ' folder(s).';
|
||||
btn.disabled = false;
|
||||
})
|
||||
.catch(function () { status.textContent = '✗ Request failed.'; btn.disabled = false; });
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user