'https://ai-domain-data.org/spec/v0.1', 'name' => self::get_name(), 'description' => self::get_description(), 'website' => self::get_website(), 'contact' => self::get_contact(), ); // Add optional fields if set. $logo = get_option( 'aidd_logo', '' ); if ( ! empty( $logo ) ) { $profile['logo'] = esc_url_raw( $logo ); } $entity_type = get_option( 'aidd_entity_type', '' ); if ( ! empty( $entity_type ) ) { $profile['entity_type'] = sanitize_text_field( $entity_type ); } $jsonld = get_option( 'aidd_jsonld', '' ); if ( ! empty( $jsonld ) ) { $decoded = json_decode( $jsonld, true ); if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded ) ) { $profile['jsonld'] = $decoded; } } return $profile; } /** * Get the site name with fallbacks. * * @return string */ private static function get_name() { $name = get_option( 'aidd_name', '' ); if ( empty( $name ) ) { $name = get_bloginfo( 'name' ); } if ( empty( $name ) ) { $name = get_option( 'blogname', '' ); } return sanitize_text_field( $name ); } /** * Get the site description with fallbacks. * * @return string */ private static function get_description() { $description = get_option( 'aidd_description', '' ); if ( empty( $description ) ) { $description = get_bloginfo( 'description' ); } if ( empty( $description ) ) { $description = get_option( 'blogdescription', '' ); } return sanitize_text_field( $description ); } /** * Get the website URL with fallbacks. * * @return string */ private static function get_website() { $website = get_option( 'aidd_website', '' ); if ( empty( $website ) ) { $website = home_url(); } // Ensure it's a full URL. if ( ! preg_match( '#^https?://#', $website ) ) { $website = 'https://' . $website; } return esc_url_raw( $website ); } /** * Get the contact information with fallbacks. * * @return string */ private static function get_contact() { $contact = get_option( 'aidd_contact', '' ); if ( empty( $contact ) ) { $contact = get_option( 'admin_email', '' ); } return sanitize_text_field( $contact ); } }