$extra Overrides (prop, transform, options, required…). * @return array */ private static function f( string $key, string $label, array $extra = array() ): array { return array_merge( array( 'key' => $key, 'label' => $label, 'type' => 'text', 'hint' => '', 'options' => array(), 'prop' => $key, 'transform' => 'string', 'required' => false, 'recommended' => false, ), $extra ); } /** * Reusable field groups. * * @return array> */ private static function offer_fields( bool $required = false ): array { return array( self::f( 'price', __( 'Price', 'ai-rank-suite' ), array( 'prop' => 'offers.price', 'hint' => '19.90', 'required' => $required, 'recommended' => ! $required, ) ), self::f( 'currency', __( 'Currency', 'ai-rank-suite' ), array( 'prop' => 'offers.priceCurrency', 'hint' => 'EUR', ) ), self::f( 'availability', __( 'Availability', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'offers.availability', 'transform' => 'schema_url', 'options' => array( 'InStock', 'OutOfStock', 'PreOrder', 'BackOrder', 'SoldOut', 'Discontinued' ), ) ), self::f( 'price_valid', __( 'Price valid until', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'offers.priceValidUntil', 'transform' => 'date', ) ), ); } /** * @return array> */ private static function rating_fields(): array { return array( self::f( 'rating', __( 'Average rating', 'ai-rank-suite' ), array( 'prop' => 'aggregateRating.ratingValue', 'hint' => __( '1–5. Only use real review data — invented ratings get manual actions.', 'ai-rank-suite' ), ) ), self::f( 'review_count', __( 'Number of reviews', 'ai-rank-suite' ), array( 'prop' => 'aggregateRating.reviewCount' ) ), ); } /** * @return array> */ private static function org_field( string $key = 'provider', string $label = '' ): array { return array( self::f( $key, '' !== $label ? $label : __( 'Provider', 'ai-rank-suite' ), array( 'prop' => $key, 'transform' => 'organization', 'hint' => __( 'Leave empty to use your organization', 'ai-rank-suite' ), ) ), ); } /** * @return array> */ private static function address_fields(): array { return array( self::f( 'street', __( 'Street', 'ai-rank-suite' ), array( 'prop' => 'address.streetAddress' ) ), self::f( 'postal_code', __( 'Postal code', 'ai-rank-suite' ), array( 'prop' => 'address.postalCode' ) ), self::f( 'city', __( 'City', 'ai-rank-suite' ), array( 'prop' => 'address.addressLocality' ) ), self::f( 'region', __( 'Region', 'ai-rank-suite' ), array( 'prop' => 'address.addressRegion' ) ), self::f( 'country', __( 'Country code', 'ai-rank-suite' ), array( 'prop' => 'address.addressCountry' ) ), self::f( 'phone', __( 'Phone', 'ai-rank-suite' ), array( 'prop' => 'telephone' ) ), ); } /** * Types that share a definition, generated to keep the registry readable. * * @param array $names Type names. * @param array> $fields Shared fields. * @return array> */ private static function variants( array $names, string $group, array $fields, string $base = 'thing' ): array { $out = array(); foreach ( $names as $name ) { $out[ $name ] = array( 'label' => $name, 'group' => $group, 'base' => $base, 'fields' => $fields, ); } return $out; } /** * The full registry. * * @return array> */ public static function all(): array { static $cache = null; if ( null !== $cache ) { return $cache; } $g_article = __( 'Article', 'ai-rank-suite' ); $g_commerce = __( 'Commerce', 'ai-rank-suite' ); $g_local = __( 'Business & local', 'ai-rank-suite' ); $g_content = __( 'Content & events', 'ai-rank-suite' ); $g_media = __( 'Media', 'ai-rank-suite' ); $g_people = __( 'People', 'ai-rank-suite' ); $g_web = __( 'Web pages', 'ai-rank-suite' ); $types = array( 'auto' => array( 'label' => __( 'Automatic (Article / WebPage)', 'ai-rank-suite' ), 'group' => __( 'Default', 'ai-rank-suite' ), 'base' => 'article', 'fields' => array(), ), ); // --- Articles ----------------------------------------------------- $article_fields = array( self::f( 'headline', __( 'Headline', 'ai-rank-suite' ), array( 'prop' => 'headline', 'hint' => '%title%', 'recommended' => true ) ), self::f( 'author', __( 'Author', 'ai-rank-suite' ), array( 'prop' => 'author', 'transform' => 'person', 'hint' => '%author%', 'recommended' => true ) ), self::f( 'section', __( 'Section', 'ai-rank-suite' ), array( 'prop' => 'articleSection' ) ), self::f( 'word_count', __( 'Word count', 'ai-rank-suite' ), array( 'prop' => 'wordCount', 'transform' => 'number' ) ), ); $types += self::variants( array( 'Article', 'NewsArticle', 'BlogPosting', 'TechArticle', 'ScholarlyArticle', 'Report', 'OpinionNewsArticle', 'ReviewNewsArticle', 'BackgroundNewsArticle', 'AdvertiserContentArticle' ), $g_article, $article_fields, 'article' ); // --- Commerce ----------------------------------------------------- $types['Product'] = array( 'label' => __( 'Product', 'ai-rank-suite' ), 'group' => $g_commerce, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'brand', __( 'Brand', 'ai-rank-suite' ), array( 'prop' => 'brand', 'transform' => 'brand', 'recommended' => true ) ), self::f( 'sku', __( 'SKU', 'ai-rank-suite' ), array( 'prop' => 'sku', 'recommended' => true ) ), self::f( 'gtin', __( 'GTIN / EAN', 'ai-rank-suite' ), array( 'prop' => 'gtin' ) ), self::f( 'mpn', __( 'MPN', 'ai-rank-suite' ), array( 'prop' => 'mpn' ) ), self::f( 'color', __( 'Color', 'ai-rank-suite' ), array( 'prop' => 'color' ) ), self::f( 'material', __( 'Material', 'ai-rank-suite' ), array( 'prop' => 'material' ) ), self::f( 'condition', __( 'Condition', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'offers.itemCondition', 'transform' => 'schema_url', 'options' => array( 'NewCondition', 'UsedCondition', 'RefurbishedCondition', 'DamagedCondition' ), ) ), ), self::offer_fields( true ), self::rating_fields() ), ); $types['ProductGroup'] = array( 'label' => __( 'Product group (variants)', 'ai-rank-suite' ), 'group' => $g_commerce, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'brand', __( 'Brand', 'ai-rank-suite' ), array( 'prop' => 'brand', 'transform' => 'brand' ) ), self::f( 'group_id', __( 'Product group ID', 'ai-rank-suite' ), array( 'prop' => 'productGroupID', 'required' => true ) ), self::f( 'varies_by', __( 'Varies by', 'ai-rank-suite' ), array( 'prop' => 'variesBy', 'transform' => 'list', 'type' => 'lines', 'hint' => __( 'One property per line: color, size…', 'ai-rank-suite' ) ) ), ), self::offer_fields() ), ); $app_fields = array_merge( array( self::f( 'category', __( 'Application category', 'ai-rank-suite' ), array( 'prop' => 'applicationCategory', 'hint' => 'BusinessApplication', 'required' => true ) ), self::f( 'os', __( 'Operating system', 'ai-rank-suite' ), array( 'prop' => 'operatingSystem', 'hint' => 'Web, iOS, Android', 'recommended' => true ) ), self::f( 'version', __( 'Version', 'ai-rank-suite' ), array( 'prop' => 'softwareVersion' ) ), ), self::offer_fields(), self::rating_fields() ); $types += self::variants( array( 'SoftwareApplication', 'MobileApplication', 'WebApplication', 'VideoGame' ), $g_commerce, $app_fields ); $types['Service'] = array( 'label' => __( 'Service', 'ai-rank-suite' ), 'group' => $g_commerce, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'service_type', __( 'Service type', 'ai-rank-suite' ), array( 'prop' => 'serviceType', 'recommended' => true ) ), self::f( 'area_served', __( 'Area served', 'ai-rank-suite' ), array( 'prop' => 'areaServed' ) ), ), self::org_field( 'provider' ), self::offer_fields(), self::rating_fields() ), ); $types['Vehicle'] = array( 'label' => __( 'Vehicle', 'ai-rank-suite' ), 'group' => $g_commerce, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'brand', __( 'Make', 'ai-rank-suite' ), array( 'prop' => 'brand', 'transform' => 'brand' ) ), self::f( 'model', __( 'Model', 'ai-rank-suite' ), array( 'prop' => 'model' ) ), self::f( 'year', __( 'Model year', 'ai-rank-suite' ), array( 'prop' => 'vehicleModelDate' ) ), self::f( 'mileage', __( 'Mileage (km)', 'ai-rank-suite' ), array( 'prop' => 'mileageFromOdometer.value', 'transform' => 'number' ) ), self::f( 'fuel', __( 'Fuel type', 'ai-rank-suite' ), array( 'prop' => 'fuelType' ) ), ), self::offer_fields() ), ); // --- Business & local --------------------------------------------- $local_fields = array_merge( self::address_fields(), array( self::f( 'price_range', __( 'Price range', 'ai-rank-suite' ), array( 'prop' => 'priceRange', 'hint' => '€€', 'recommended' => true ) ), self::f( 'opening_hours', __( 'Opening hours', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'openingHours', 'transform' => 'list', 'hint' => "Mo-Fr 09:00-17:00\nSa 10:00-14:00" ) ), self::f( 'latitude', __( 'Latitude', 'ai-rank-suite' ), array( 'prop' => 'geo.latitude' ) ), self::f( 'longitude', __( 'Longitude', 'ai-rank-suite' ), array( 'prop' => 'geo.longitude' ) ), ), self::rating_fields() ); $types += self::variants( array( 'LocalBusiness', 'Restaurant', 'Store', 'Hotel', 'Dentist', 'Physician', 'MedicalClinic', 'Attorney', 'LegalService', 'AccountingService', 'RealEstateAgent', 'AutoRepair', 'ProfessionalService', 'BeautySalon', 'HairSalon', 'ExerciseGym', 'ChildCare', 'Electrician', 'Plumber', 'GeneralContractor', 'TravelAgency', 'InsuranceAgency' ), $g_local, $local_fields, 'thing' ); $org_fields = array_merge( array( self::f( 'legal_name', __( 'Legal name', 'ai-rank-suite' ), array( 'prop' => 'legalName' ) ), self::f( 'founding_date', __( 'Founded', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'foundingDate', 'transform' => 'date' ) ), self::f( 'vat_id', __( 'VAT ID', 'ai-rank-suite' ), array( 'prop' => 'vatID' ) ), self::f( 'email', __( 'Email', 'ai-rank-suite' ), array( 'prop' => 'email' ) ), self::f( 'same_as', __( 'Profile URLs', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'sameAs', 'transform' => 'list', 'hint' => __( 'One URL per line', 'ai-rank-suite' ), 'recommended' => true ) ), ), self::address_fields() ); $types += self::variants( array( 'Organization', 'Corporation', 'NGO', 'EducationalOrganization', 'GovernmentOrganization', 'SportsTeam', 'PerformingGroup' ), $g_local, $org_fields ); $types['JobPosting'] = array( 'label' => __( 'Job posting', 'ai-rank-suite' ), 'group' => $g_local, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'title', __( 'Job title', 'ai-rank-suite' ), array( 'prop' => 'title', 'hint' => '%title%', 'required' => true ) ), self::f( 'employment_type', __( 'Employment type', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'employmentType', 'options' => array( 'FULL_TIME', 'PART_TIME', 'CONTRACTOR', 'TEMPORARY', 'INTERN', 'VOLUNTEER', 'OTHER' ), 'recommended' => true ) ), self::f( 'valid_through', __( 'Apply until', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'validThrough', 'transform' => 'date', 'required' => true ) ), self::f( 'remote', __( 'Remote', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'jobLocationType', 'options' => array( 'TELECOMMUTE' ) ) ), self::f( 'location', __( 'Location', 'ai-rank-suite' ), array( 'prop' => 'jobLocation.address', 'required' => true ) ), self::f( 'salary_min', __( 'Salary from', 'ai-rank-suite' ), array( 'prop' => 'baseSalary.value.minValue', 'transform' => 'number' ) ), self::f( 'salary_max', __( 'Salary to', 'ai-rank-suite' ), array( 'prop' => 'baseSalary.value.maxValue', 'transform' => 'number' ) ), self::f( 'salary_currency', __( 'Currency', 'ai-rank-suite' ), array( 'prop' => 'baseSalary.currency', 'hint' => 'EUR' ) ), self::f( 'salary_unit', __( 'Salary per', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'baseSalary.value.unitText', 'options' => array( 'HOUR', 'DAY', 'WEEK', 'MONTH', 'YEAR' ) ) ), // The rest of what Google's job posting report asks for. self::f( 'identifier', __( 'Job ID', 'ai-rank-suite' ), array( 'prop' => 'identifier', 'transform' => 'identifier', 'hint' => __( 'Your reference number for this vacancy', 'ai-rank-suite' ), 'recommended' => true ) ), self::f( 'applicant_country', __( 'Applicants must live in (remote jobs)', 'ai-rank-suite' ), array( 'prop' => 'applicantLocationRequirements', 'transform' => 'country', 'hint' => __( 'Country name, for TELECOMMUTE jobs', 'ai-rank-suite' ) ) ), self::f( 'direct_apply', __( 'Apply directly on this page', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'directApply', 'transform' => 'bool', 'options' => array( 'true', 'false' ), 'recommended' => true ) ), ), self::org_field( 'hiringOrganization', __( 'Hiring organization', 'ai-rank-suite' ) ) ), ); // --- Content & events --------------------------------------------- $types['Recipe'] = array( 'label' => __( 'Recipe', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'article', 'fields' => array_merge( array( self::f( 'prep_time', __( 'Prep time', 'ai-rank-suite' ), array( 'prop' => 'prepTime', 'transform' => 'duration', 'hint' => '20 min' ) ), self::f( 'cook_time', __( 'Cook time', 'ai-rank-suite' ), array( 'prop' => 'cookTime', 'transform' => 'duration', 'hint' => '35 min' ) ), self::f( 'total_time', __( 'Total time', 'ai-rank-suite' ), array( 'prop' => 'totalTime', 'transform' => 'duration' ) ), self::f( 'yield', __( 'Yield', 'ai-rank-suite' ), array( 'prop' => 'recipeYield', 'recommended' => true ) ), self::f( 'category', __( 'Category', 'ai-rank-suite' ), array( 'prop' => 'recipeCategory' ) ), self::f( 'cuisine', __( 'Cuisine', 'ai-rank-suite' ), array( 'prop' => 'recipeCuisine' ) ), self::f( 'calories', __( 'Calories', 'ai-rank-suite' ), array( 'prop' => 'nutrition.calories', 'hint' => '350 kcal' ) ), self::f( 'ingredients', __( 'Ingredients', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'recipeIngredient', 'transform' => 'list', 'required' => true, 'hint' => __( 'One per line', 'ai-rank-suite' ) ) ), self::f( 'instructions', __( 'Instructions', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'recipeInstructions', 'transform' => 'steps', 'required' => true, 'hint' => __( 'One step per line', 'ai-rank-suite' ) ) ), ), self::rating_fields() ), ); $types['HowTo'] = array( 'label' => __( 'How-to guide', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'article', 'fields' => array( self::f( 'total_time', __( 'Total time', 'ai-rank-suite' ), array( 'prop' => 'totalTime', 'transform' => 'duration', 'hint' => '1 h', 'recommended' => true ) ), self::f( 'cost', __( 'Estimated cost', 'ai-rank-suite' ), array( 'prop' => 'estimatedCost.value' ) ), self::f( 'cost_currency', __( 'Currency', 'ai-rank-suite' ), array( 'prop' => 'estimatedCost.currency', 'hint' => 'EUR' ) ), self::f( 'supplies', __( 'Supplies', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'supply', 'transform' => 'named_list' ) ), self::f( 'tools', __( 'Tools', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'tool', 'transform' => 'named_list' ) ), self::f( 'steps', __( 'Steps', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'step', 'transform' => 'steps', 'required' => true ) ), ), ); $types['Course'] = array( 'label' => __( 'Course', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'thing', 'fields' => array_merge( self::org_field( 'provider', __( 'Provider', 'ai-rank-suite' ) ), array( self::f( 'mode', __( 'Delivery mode', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'hasCourseInstance.courseMode', 'options' => array( 'Online', 'Onsite', 'Blended' ), 'recommended' => true ) ), self::f( 'duration', __( 'Duration', 'ai-rank-suite' ), array( 'prop' => 'hasCourseInstance.courseWorkload', 'transform' => 'duration', 'hint' => '4 weeks' ) ), self::f( 'language', __( 'Language', 'ai-rank-suite' ), array( 'prop' => 'inLanguage' ) ), ), self::offer_fields(), self::rating_fields() ), ); $types['Event'] = array( 'label' => __( 'Event', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'start_date', __( 'Start', 'ai-rank-suite' ), array( 'type' => 'datetime-local', 'prop' => 'startDate', 'transform' => 'date', 'required' => true ) ), self::f( 'end_date', __( 'End', 'ai-rank-suite' ), array( 'type' => 'datetime-local', 'prop' => 'endDate', 'transform' => 'date', 'recommended' => true ) ), self::f( 'mode', __( 'Attendance', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'eventAttendanceMode', 'transform' => 'attendance', 'options' => array( 'Offline', 'Online', 'Mixed' ) ) ), self::f( 'status', __( 'Status', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'eventStatus', 'transform' => 'event_status', 'options' => array( 'Scheduled', 'Cancelled', 'Postponed', 'Rescheduled', 'MovedOnline' ) ) ), self::f( 'venue', __( 'Venue name', 'ai-rank-suite' ), array( 'prop' => 'location.name', 'required' => true ) ), self::f( 'venue_address', __( 'Venue address', 'ai-rank-suite' ), array( 'prop' => 'location.address' ) ), self::f( 'performer', __( 'Performer', 'ai-rank-suite' ), array( 'prop' => 'performer', 'transform' => 'person' ) ), ), self::offer_fields(), self::org_field( 'organizer', __( 'Organizer', 'ai-rank-suite' ) ) ), ); $types['FAQPage'] = array( 'label' => __( 'FAQ page', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'thing', 'fields' => array( self::f( 'faqs', __( 'Questions & answers', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'mainEntity', 'transform' => 'faq', 'required' => true, 'hint' => __( 'One per line as: Question? | Answer', 'ai-rank-suite' ) ) ), ), ); $types['QAPage'] = array( 'label' => __( 'Q&A page', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'thing', 'fields' => array( self::f( 'question', __( 'Question', 'ai-rank-suite' ), array( 'prop' => 'mainEntity.name', 'required' => true, 'hint' => '%title%' ) ), self::f( 'answer', __( 'Accepted answer', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'mainEntity.acceptedAnswer.text', 'required' => true ) ), ), ); $types['ClaimReview'] = array( 'label' => __( 'Fact check', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'thing', 'fields' => array( self::f( 'claim', __( 'Claim reviewed', 'ai-rank-suite' ), array( 'prop' => 'claimReviewed', 'required' => true ) ), self::f( 'rating_value', __( 'Rating (1–5)', 'ai-rank-suite' ), array( 'prop' => 'reviewRating.ratingValue', 'required' => true ) ), self::f( 'rating_name', __( 'Verdict', 'ai-rank-suite' ), array( 'prop' => 'reviewRating.alternateName', 'hint' => __( 'True, Mostly false…', 'ai-rank-suite' ) ) ), self::f( 'claim_url', __( 'Source of the claim', 'ai-rank-suite' ), array( 'prop' => 'itemReviewed.url', 'transform' => 'url' ) ), ), ); $types['Dataset'] = array( 'label' => __( 'Dataset', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'thing', 'fields' => array( self::f( 'license', __( 'License URL', 'ai-rank-suite' ), array( 'prop' => 'license', 'transform' => 'url', 'recommended' => true ) ), self::f( 'creator', __( 'Creator', 'ai-rank-suite' ), array( 'prop' => 'creator', 'transform' => 'organization' ) ), self::f( 'keywords', __( 'Keywords', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'keywords', 'transform' => 'list' ) ), self::f( 'distribution', __( 'Download URL', 'ai-rank-suite' ), array( 'prop' => 'distribution.contentUrl', 'transform' => 'url' ) ), ), ); $types['Review'] = array( 'label' => __( 'Review', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'item_name', __( 'Reviewed item', 'ai-rank-suite' ), array( 'prop' => 'itemReviewed.name', 'required' => true ) ), self::f( 'item_type', __( 'Item type', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'itemReviewed.@type', 'options' => array( 'Product', 'Book', 'Movie', 'Restaurant', 'SoftwareApplication', 'Service', 'LocalBusiness' ) ) ), self::f( 'rating_value', __( 'Rating', 'ai-rank-suite' ), array( 'prop' => 'reviewRating.ratingValue', 'required' => true ) ), self::f( 'best_rating', __( 'Best possible rating', 'ai-rank-suite' ), array( 'prop' => 'reviewRating.bestRating', 'hint' => '5' ) ), ), self::org_field( 'author', __( 'Author', 'ai-rank-suite' ) ) ), ); $types['SpecialAnnouncement'] = array( 'label' => __( 'Special announcement', 'ai-rank-suite' ), 'group' => $g_content, 'base' => 'article', 'fields' => array( self::f( 'date_posted', __( 'Posted', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'datePosted', 'transform' => 'date', 'required' => true ) ), self::f( 'expires', __( 'Expires', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'expires', 'transform' => 'date', 'recommended' => true ) ), self::f( 'category', __( 'Category URL', 'ai-rank-suite' ), array( 'prop' => 'category', 'transform' => 'url' ) ), self::f( 'info_url', __( 'More information URL', 'ai-rank-suite' ), array( 'prop' => 'url', 'transform' => 'url' ) ), ), ); // --- Media --------------------------------------------------------- $types['VideoObject'] = array( 'label' => __( 'Video', 'ai-rank-suite' ), 'group' => $g_media, 'base' => 'thing', 'fields' => array( self::f( 'upload_date', __( 'Upload date', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'uploadDate', 'transform' => 'date', 'required' => true ) ), self::f( 'duration', __( 'Duration', 'ai-rank-suite' ), array( 'prop' => 'duration', 'transform' => 'duration', 'hint' => '5 min 30 s', 'recommended' => true ) ), self::f( 'thumbnail', __( 'Thumbnail URL', 'ai-rank-suite' ), array( 'prop' => 'thumbnailUrl', 'transform' => 'url', 'hint' => '%image%', 'required' => true ) ), self::f( 'embed_url', __( 'Embed URL', 'ai-rank-suite' ), array( 'prop' => 'embedUrl', 'transform' => 'url', 'hint' => __( 'Detected from the content when empty', 'ai-rank-suite' ) ) ), self::f( 'content_url', __( 'Direct file URL', 'ai-rank-suite' ), array( 'prop' => 'contentUrl', 'transform' => 'url' ) ), ), ); $types['AudioObject'] = array( 'label' => __( 'Audio', 'ai-rank-suite' ), 'group' => $g_media, 'base' => 'thing', 'fields' => array( self::f( 'content_url', __( 'Audio file URL', 'ai-rank-suite' ), array( 'prop' => 'contentUrl', 'transform' => 'url', 'required' => true ) ), self::f( 'duration', __( 'Duration', 'ai-rank-suite' ), array( 'prop' => 'duration', 'transform' => 'duration' ) ), self::f( 'encoding', __( 'Format', 'ai-rank-suite' ), array( 'prop' => 'encodingFormat', 'hint' => 'audio/mpeg' ) ), ), ); $types['PodcastEpisode'] = array( 'label' => __( 'Podcast episode', 'ai-rank-suite' ), 'group' => $g_media, 'base' => 'thing', 'fields' => array( self::f( 'series', __( 'Podcast series', 'ai-rank-suite' ), array( 'prop' => 'partOfSeries.name', 'required' => true ) ), self::f( 'episode', __( 'Episode number', 'ai-rank-suite' ), array( 'prop' => 'episodeNumber', 'transform' => 'number' ) ), self::f( 'audio', __( 'Audio file URL', 'ai-rank-suite' ), array( 'prop' => 'associatedMedia.contentUrl', 'transform' => 'url', 'required' => true ) ), self::f( 'duration', __( 'Duration', 'ai-rank-suite' ), array( 'prop' => 'timeRequired', 'transform' => 'duration' ) ), ), ); $types['Book'] = array( 'label' => __( 'Book', 'ai-rank-suite' ), 'group' => $g_media, 'base' => 'thing', 'fields' => array_merge( array( self::f( 'author', __( 'Author', 'ai-rank-suite' ), array( 'prop' => 'author', 'transform' => 'person', 'required' => true ) ), self::f( 'isbn', __( 'ISBN', 'ai-rank-suite' ), array( 'prop' => 'isbn', 'recommended' => true ) ), self::f( 'publisher', __( 'Publisher', 'ai-rank-suite' ), array( 'prop' => 'publisher', 'transform' => 'organization' ) ), self::f( 'published', __( 'Publication date', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'datePublished', 'transform' => 'date' ) ), self::f( 'format', __( 'Format', 'ai-rank-suite' ), array( 'type' => 'select', 'prop' => 'bookFormat', 'transform' => 'schema_url', 'options' => array( 'Hardcover', 'Paperback', 'EBook', 'AudiobookFormat' ) ) ), self::f( 'pages', __( 'Number of pages', 'ai-rank-suite' ), array( 'prop' => 'numberOfPages', 'transform' => 'number' ) ), ), self::rating_fields() ), ); $media_fields = array_merge( array( self::f( 'director', __( 'Director / creator', 'ai-rank-suite' ), array( 'prop' => 'director', 'transform' => 'person' ) ), self::f( 'released', __( 'Release date', 'ai-rank-suite' ), array( 'type' => 'date', 'prop' => 'dateCreated', 'transform' => 'date' ) ), self::f( 'duration', __( 'Duration', 'ai-rank-suite' ), array( 'prop' => 'duration', 'transform' => 'duration' ) ), self::f( 'genre', __( 'Genre', 'ai-rank-suite' ), array( 'prop' => 'genre' ) ), ), self::rating_fields() ); $types += self::variants( array( 'Movie', 'TVSeries', 'MusicAlbum', 'MusicRecording' ), $g_media, $media_fields ); // --- People --------------------------------------------------------- $types['Person'] = array( 'label' => __( 'Person', 'ai-rank-suite' ), 'group' => $g_people, 'base' => 'thing', 'fields' => array( self::f( 'job_title', __( 'Job title', 'ai-rank-suite' ), array( 'prop' => 'jobTitle', 'recommended' => true ) ), self::f( 'works_for', __( 'Works for', 'ai-rank-suite' ), array( 'prop' => 'worksFor', 'transform' => 'organization' ) ), self::f( 'email', __( 'Email', 'ai-rank-suite' ), array( 'prop' => 'email' ) ), self::f( 'telephone', __( 'Phone', 'ai-rank-suite' ), array( 'prop' => 'telephone' ) ), self::f( 'knows_about', __( 'Areas of expertise', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'knowsAbout', 'transform' => 'list', 'hint' => __( 'One per line — strong entity signal for AI answers', 'ai-rank-suite' ), 'recommended' => true ) ), self::f( 'same_as', __( 'Profile URLs', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'sameAs', 'transform' => 'list', 'recommended' => true ) ), ), ); $types['ProfilePage'] = array( 'label' => __( 'Profile page', 'ai-rank-suite' ), 'group' => $g_people, 'base' => 'thing', 'fields' => array( self::f( 'person', __( 'Person or brand', 'ai-rank-suite' ), array( 'prop' => 'mainEntity.name', 'required' => true, 'hint' => '%title%' ) ), self::f( 'same_as', __( 'Profile URLs', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'mainEntity.sameAs', 'transform' => 'list' ) ), ), ); // --- Web pages ------------------------------------------------------- $web_fields = array( self::f( 'primary_image', __( 'Primary image URL', 'ai-rank-suite' ), array( 'prop' => 'primaryImageOfPage', 'transform' => 'url', 'hint' => '%image%' ) ), self::f( 'speakable', __( 'Speakable selectors', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'speakable.cssSelector', 'transform' => 'list', 'hint' => __( 'CSS selectors voice assistants may read aloud', 'ai-rank-suite' ) ) ), ); $types += self::variants( array( 'WebPage', 'AboutPage', 'ContactPage', 'CollectionPage', 'CheckoutPage', 'ItemPage', 'MedicalWebPage' ), $g_web, $web_fields ); $types['ItemList'] = array( 'label' => __( 'Item list / carousel', 'ai-rank-suite' ), 'group' => $g_web, 'base' => 'thing', 'fields' => array( self::f( 'items', __( 'List items', 'ai-rank-suite' ), array( 'type' => 'lines', 'prop' => 'itemListElement', 'transform' => 'item_list', 'required' => true, 'hint' => __( 'One per line as: Name | URL', 'ai-rank-suite' ) ) ), ), ); /** * Filter the schema type registry. * * @param array $types Registry keyed by schema.org type. */ $cache = (array) apply_filters( 'airanksuite/schema/types', $types ); return $cache; } /** * Template variables available in every field. * * @return array */ public static function variables(): array { return array( '%title%' => __( 'Page title', 'ai-rank-suite' ), '%excerpt%' => __( 'Excerpt or meta description', 'ai-rank-suite' ), '%permalink%' => __( 'Page URL', 'ai-rank-suite' ), '%image%' => __( 'Featured image URL', 'ai-rank-suite' ), '%author%' => __( 'Author name', 'ai-rank-suite' ), '%date%' => __( 'Publish date', 'ai-rank-suite' ), '%modified%' => __( 'Last modified date', 'ai-rank-suite' ), '%sitename%' => __( 'Site name', 'ai-rank-suite' ), '%category%' => __( 'Primary category', 'ai-rank-suite' ), '%price%' => __( 'Product price (WooCommerce)', 'ai-rank-suite' ), '%sku%' => __( 'Product SKU (WooCommerce)', 'ai-rank-suite' ), ); } /** * Types grouped for the picker. * * @return array>> */ public static function grouped(): array { $out = array(); foreach ( self::all() as $key => $type ) { $out[ $type['group'] ][] = array( 'value' => $key, 'label' => (string) $type['label'], ); } return $out; } public static function exists( string $type ): bool { return isset( self::all()[ $type ] ); } /** * Field definitions for a type. * * @return array> */ public static function fields( string $type ): array { $all = self::all(); return isset( $all[ $type ] ) ? (array) $all[ $type ]['fields'] : array(); } /** * Find a YouTube or Vimeo embed inside the post content. */ /** * The whole VideoObject a detected embed implies — not just its URL. * * The embed was already found for the video sitemap; a page with a video * and no VideoObject is a page Google lists without the thumbnail and the * duration every competitor's page gets. Everything here comes from the * post itself or from the embed id: no API call, no key, nothing to break * when a quota runs out. * * @return array|null */ public static function detect_video_node( WP_Post $post ): ?array { $embed = self::detect_video( $post ); if ( null === $embed ) { return null; } $node = array( '@type' => 'VideoObject', '@id' => get_permalink( $post ) . '#video', 'name' => wp_strip_all_tags( get_the_title( $post ) ), 'embedUrl' => $embed, 'uploadDate' => (string) get_the_date( 'c', $post ), ); $description = trim( wp_strip_all_tags( (string) $post->post_excerpt ) ); if ( '' === $description ) { $description = trim( wp_strip_all_tags( (string) wp_trim_words( (string) $post->post_content, 40 ) ) ); } if ( '' !== $description ) { $node['description'] = $description; } // YouTube's thumbnail URL is derived from the id, so it needs no API. // Vimeo's is not; there the page's own featured image is the honest // answer, and no thumbnail at all beats a guessed one. if ( preg_match( '#youtube\.com/embed/([A-Za-z0-9_-]{6,})#i', $embed, $m ) ) { $node['thumbnailUrl'] = 'https://i.ytimg.com/vi/' . $m[1] . '/hqdefault.jpg'; } elseif ( has_post_thumbnail( $post ) ) { $thumb = (string) get_the_post_thumbnail_url( $post, 'full' ); if ( '' !== $thumb ) { $node['thumbnailUrl'] = $thumb; } } return $node; } public static function detect_video( WP_Post $post ): ?string { $content = (string) $post->post_content; if ( preg_match( '#(?:youtube\.com/(?:watch\?v=|embed/)|youtu\.be/)([A-Za-z0-9_-]{6,})#i', $content, $m ) ) { return 'https://www.youtube.com/embed/' . $m[1]; } if ( preg_match( '#vimeo\.com/(?:video/)?([0-9]+)#i', $content, $m ) ) { return 'https://player.vimeo.com/video/' . $m[1]; } return null; } }