feat: starter guides for all 15 structure cities

Writes guides for the nine cities with no old page and adds Best time to
visit to all. The import now fills only empty fields and re-runs once, so
sites that already imported get the new values without losing edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 10:10:01 +03:30
parent 2ded000a27
commit 25debff066
4 changed files with 184 additions and 13 deletions

View File

@@ -13,8 +13,12 @@ defined( 'ABSPATH' ) || exit;
class VC_City_Guide {
const META = '_vc_guide';
/** Slugs from data/city-guides.php already imported (or skipped because the guide had text). */
const IMPORTED_OPTION = 'vc_city_guides_imported';
/**
* Slugs from data/city-guides.php already imported. "_v2" re-runs the
* import once for sites that imported before "Best time to visit" was
* added to the data.
*/
const IMPORTED_OPTION = 'vc_city_guides_imported_v2';
public static function init() {
add_action( 'viator_destination_edit_form_fields', array( __CLASS__, 'edit_fields' ), 20 );
@@ -88,6 +92,18 @@ class VC_City_Guide {
return true;
}
/**
* $guide with its empty fields taken from $defaults. Pure.
*/
public static function fill_empty( array $guide, array $defaults ) {
foreach ( $defaults as $key => $value ) {
if ( empty( $guide[ $key ] ) ) {
$guide[ $key ] = $value;
}
}
return $guide;
}
/**
* Months for each season. Pure.
*/
@@ -211,8 +227,9 @@ class VC_City_Guide {
}
/**
* Fill empty guides from the text recovered from the old site. Each slug is
* handled once; cities that don't exist yet are retried at most hourly.
* Fill the empty fields of each city's guide from data/city-guides.php;
* text already entered is never replaced. Each slug is handled once;
* cities that don't exist yet are retried at most hourly.
*/
public static function import_bundled() {
if ( ! current_user_can( 'manage_categories' ) || get_transient( 'vc_city_guides_check' ) ) {
@@ -226,9 +243,7 @@ class VC_City_Guide {
if ( ! $term ) {
continue;
}
if ( self::is_empty( self::get( $term->term_id ) ) ) {
update_term_meta( $term->term_id, self::META, self::sanitize( $data[ $slug ] ) );
}
update_term_meta( $term->term_id, self::META, self::fill_empty( self::get( $term->term_id ), self::sanitize( $data[ $slug ] ) ) );
$done[] = $slug;
}
update_option( self::IMPORTED_OPTION, array_values( array_unique( $done ) ), false );