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:
@@ -193,15 +193,28 @@ class VC_Structure {
|
||||
|
||||
/**
|
||||
* Explicit per-slug rules (no catch-alls), regions first, then cities.
|
||||
* Only regions synced to a term (term_id set) are routed, so the unsaved
|
||||
* presets never claim /europe/ etc. over existing pages. Archives get a
|
||||
* /page/N/ rule because core's redirect_canonical turns ?paged=N into it.
|
||||
*/
|
||||
public static function rewrite_rules( array $structure ) {
|
||||
$rules = array();
|
||||
foreach ( $structure as $region ) {
|
||||
$rules[ '^' . $region['slug'] . '/?$' ] = 'index.php?viator_destination=' . $region['slug'];
|
||||
$synced = array_values(
|
||||
array_filter(
|
||||
$structure,
|
||||
function ( $region ) {
|
||||
return (int) $region['term_id'] > 0;
|
||||
}
|
||||
)
|
||||
);
|
||||
$rules = array();
|
||||
foreach ( $synced as $region ) {
|
||||
$rules[ '^' . $region['slug'] . '/page/([0-9]+)/?$' ] = 'index.php?viator_destination=' . $region['slug'] . '&paged=$matches[1]';
|
||||
$rules[ '^' . $region['slug'] . '/?$' ] = 'index.php?viator_destination=' . $region['slug'];
|
||||
}
|
||||
foreach ( self::cities( $structure ) as $city ) {
|
||||
$rules[ '^' . $city['slug'] . '/?$' ] = 'index.php?viator_destination=' . $city['slug'];
|
||||
$rules[ '^' . $city['slug'] . '/([^/]+)/?$' ] = 'index.php?viator_tour=$matches[1]';
|
||||
foreach ( self::cities( $synced ) as $city ) {
|
||||
$rules[ '^' . $city['slug'] . '/page/([0-9]+)/?$' ] = 'index.php?viator_destination=' . $city['slug'] . '&paged=$matches[1]';
|
||||
$rules[ '^' . $city['slug'] . '/?$' ] = 'index.php?viator_destination=' . $city['slug'];
|
||||
$rules[ '^' . $city['slug'] . '/([^/]+)/?$' ] = 'index.php?viator_tour=$matches[1]';
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user