fix: paginated region/city pages, no routes before first save, safer structure save
- Add /{slug}/page/N/ rules and keep the page number through 301s
- Route only regions synced to a term, so unsaved presets never claim /europe/ etc.
- Flush rewrites on the request after activation so structure routes survive
- Suggest the existing term slug for new cities (keeps live /tour-destination/ URLs)
- Refuse saves without the editor sentinel; confirm before saving an empty structure
- Show term-sync failures to the admin instead of reporting success
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,33 @@ class VC_Settings {
|
||||
}
|
||||
}
|
||||
|
||||
// Suggested URL slug for the Viator Structure screen: keep an existing
|
||||
// term's slug so live /tour-destination/{slug}/ links still resolve
|
||||
// (and 301), otherwise WordPress's own slug for the name.
|
||||
$existing = array();
|
||||
if ( $results ) {
|
||||
$terms = get_terms(
|
||||
array(
|
||||
'taxonomy' => 'viator_destination',
|
||||
'hide_empty' => false,
|
||||
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery
|
||||
array(
|
||||
'key' => '_vc_viator_destination_id',
|
||||
'value' => array_column( $results, 'id' ),
|
||||
'compare' => 'IN',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
foreach ( is_wp_error( $terms ) ? array() : $terms as $term ) {
|
||||
$existing[ (string) get_term_meta( $term->term_id, '_vc_viator_destination_id', true ) ] = $term->slug;
|
||||
}
|
||||
}
|
||||
foreach ( $results as &$result ) {
|
||||
$result['slug'] = isset( $existing[ $result['id'] ] ) ? $existing[ $result['id'] ] : sanitize_title( $result['name'] );
|
||||
}
|
||||
unset( $result );
|
||||
|
||||
wp_send_json_success( array( 'results' => $results ) );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user