'', 'company_name_label' => __( 'Company/Brand Name', 'v4studio' ), 'logo_dark' => 0, 'logo_dark_label' => __( 'Logo Dark', 'v4studio' ), 'logo_light' => 0, 'logo_light_label' => __( 'Logo Light', 'v4studio' ), 'phone' => '', 'phone_label' => __( 'Phone', 'v4studio' ), 'mobile' => '', 'mobile_label' => __( 'Mobile Number', 'v4studio' ), 'email' => '', 'email_label' => __( 'Email', 'v4studio' ), 'fax' => '', 'fax_label' => __( 'Fax', 'v4studio' ), 'address' => '', 'address_label' => __( 'Address', 'v4studio' ), 'facebook' => '', 'facebook_label' => __( 'Facebook', 'v4studio' ), 'instagram' => '', 'instagram_label' => __( 'Instagram', 'v4studio' ), 'twitter_x' => '', 'twitter_x_label' => __( 'Twitter (X)', 'v4studio' ), 'linkedin' => '', 'linkedin_label' => __( 'LinkedIn', 'v4studio' ), 'pinterest' => '', 'pinterest_label' => __( 'Pinterest', 'v4studio' ), 'youtube' => '', 'youtube_label' => __( 'YouTube', 'v4studio' ), 'tiktok' => '', 'tiktok_label' => __( 'TikTok', 'v4studio' ), 'whatsapp' => '', 'whatsapp_label' => __( 'WhatsApp', 'v4studio' ), 'other_website' => '', 'other_website_label' => __( 'Other Website', 'v4studio' ), ]; } /** * THE canonical seeded Brand Data -- the values a new installation starts with. * * Separate from defaults() on purpose, and the distinction is load-bearing. defaults() is the * CATALOGUE: the field list with EMPTY values, used as the merge base by get() and by the * sanitiser. If the real values lived there, a user who deliberately cleared a field would * have it silently repopulated on the very next read, because get() merges the catalogue * underneath whatever is stored. Emptiness has to stay expressible. * * So this is the SEED: written into storage once at first install, and rewritten by an * explicit reset. Every consumer -- installation, reset, tests, import/export expectations -- * reads it from here. There is no second copy. * * Atomic Brand is fictional sample content, and every value here reads as one: a 555 number, an * example.com address. The links are EMPTY (1.1.0): a sample social link published a footer * icon pointing at example.com, and an empty link hides its element instead (Elementor_Dynamic_Tags). * * Logos are absent here because they are attachment IDs, which do not exist until a site does. * Brand_Data_Logos resolves them at seed time; see seed_record(). * * @return array */ public static function seed_values(): array { return [ 'company_name' => 'Atomic Brand', 'phone' => '+1 (206) 555-0147', 'email' => 'hello@example.com', 'mobile' => '+1 (206) 555-0182', 'fax' => '+1 (206) 555-0196', 'address' => '123 Example Street, Suite 400, Seattle, WA 98101, United States', ]; } /** * The fields that still hold a value V4 Studio shipped as a sample: the seed's own values, and the * example.com link 1.0 seeded into every link field. Compared trimmed and case-blind. * * @return string[] Field keys, in catalogue order. */ public static function sample_fields( array $record ): array { $samples = self::seed_values(); $fields = []; foreach ( array_keys( self::defaults() ) as $key ) { $value = strtolower( trim( (string) ( $record[ $key ] ?? '' ) ) ); if ( '' === $value || str_ends_with( $key, '_label' ) || in_array( $key, self::media_keys(), true ) ) { continue; } $shipped = isset( $samples[ $key ] ) && strtolower( trim( $samples[ $key ] ) ) === $value; $legacy = ( in_array( $key, self::link_keys(), true ) || 'whatsapp' === $key ) && in_array( rtrim( $value, '/' ), [ 'https://example.com', 'http://example.com' ], true ); if ( $shipped || $legacy ) { $fields[] = $key; } } return $fields; } /** * The seed as it is actually stored: catalogue shape, real values, logo attachments resolved. * * Labels come from the catalogue, so a field's label and its value cannot drift apart, and the * result is a complete, sanitised record ready to write. Both the installer and the reset use * this one method, which is what keeps them from disagreeing. * * @return array */ public static function seed_record(): array { $logos = Brand_Data_Logos::ensure_attachments(); $record = array_merge( self::defaults(), self::seed_values() ); foreach ( [ 'logo_dark', 'logo_light' ] as $key ) { if ( ! empty( $logos[ $key ] ) ) { $record[ $key ] = (int) $logos[ $key ]; } } return self::sanitize( $record ); } /** * Fields whose label is editable by the user. */ public static function label_keys(): array { return [ 'company_name', 'logo_dark', 'logo_light', 'phone', 'mobile', 'email', 'fax', 'address', 'facebook', 'instagram', 'twitter_x', 'linkedin', 'pinterest', 'youtube', 'tiktok', 'whatsapp', 'other_website', ]; } /** * Fields whose value is a URL and is sanitised as one. * * `whatsapp` is absent on purpose: it accepts either a bare number or a URL, and * the sanitiser decides per value. */ public static function link_keys(): array { return [ 'facebook', 'instagram', 'twitter_x', 'linkedin', 'pinterest', 'youtube', 'tiktok', 'other_website', ]; } /** * Fields holding an attachment ID rather than a string. */ public static function media_keys(): array { return [ 'logo_dark', 'logo_light' ]; } /** * Sanitise a raw Brand Data payload against the catalogue. */ public static function sanitize( array $data ): array { return Brand_Data_Sanitizer::sanitize_dynamic_data( $data, self::defaults(), self::label_keys(), self::link_keys() ); } /** * Public read API: the stored Brand Data, with every catalogue key present. * * Missing and unknown keys are reconciled against the catalogue so callers never * have to null-check an individual field. */ public static function get(): array { $settings = Base_Plugin::get_settings(); $stored = is_array( $settings[ self::SETTINGS_KEY ] ?? null ) ? $settings[ self::SETTINGS_KEY ] : []; return array_intersect_key( array_merge( self::defaults(), $stored ), self::defaults() ); } /** * Public read API: one Brand Data field, or the catalogue default when unset. */ public static function get_value( string $key ) { $data = self::get(); return $data[ $key ] ?? null; } }