findByOrigin( self::BRAND_ORIGIN ) ) { return; } $candidate = BrandProfileSchema::emptyProfile(); $candidate['description'] = $raw; $normalized = BrandProfileSchema::normalize( $candidate ); $full_sanitized = (string) $normalized['profile']['description']; if ( mb_strlen( $full_sanitized, 'UTF-8' ) > BrandProfileSchema::DESCRIPTION_MAX_LEN ) { $candidate['description'] = mb_substr( $full_sanitized, 0, BrandProfileSchema::DESCRIPTION_MAX_LEN, 'UTF-8' ); $normalized = BrandProfileSchema::normalize( $candidate ); } $profile_id = $brand_profiles->create( array( 'name' => __( 'Store brand voice', 'ai-product-tools' ), 'profile' => $normalized['profile'], 'origin' => self::BRAND_ORIGIN, ) ); if ( $profile_id <= 0 ) { throw new RuntimeException( 'Could not create the starting brand profile.' ); } } }