Forked from adczk/smartcrawl-add-custom-property-to-schema-preset.php
Created
May 31, 2024 13:45
-
-
Save Miragetek/e46e5a560121f67601785ef2988cb80a to your computer and use it in GitHub Desktop.
Add a custom schema property with defined values to schema built using existing preset in Types Builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: SmartCraw - add custom property to preset schema | |
* Plugin URI: https://gist.github.com/adczk | |
* Description: Add a custom schema property with defined values to schema built using existing preset in Types Builder | |
* Author: adczk | |
* | |
* Author URI: https://gist.github.com/adczk | |
* License: GPLv2 or later | |
* | |
* Use as MU plugin; config in code comments | |
* | |
*/ | |
add_filter( 'wds_schema_printer_schema_data', 'wpmu_custom_wds_schema_printer_schema_data', 11, 2 ); | |
function wpmu_custom_wds_schema_printer_schema_data( $data, $entity ) { | |
$addto = 'AmusementPark'; // set type to which custom property must be added | |
$custom_property_name = 'department'; // set custom property name | |
// below set custom property data; this is example only; it needs to be PHP array format. | |
$custom_property = array( | |
"@type" => "EntertainmentBusiness", | |
"name" => "The Mystery Rooms - Melbourne", | |
"description" => "Providing immersive escape room games with actors in Melbourne.", | |
"url" => "https://themysteryrooms.com.au/escaperoommelbourne/", | |
"@id" =>"https://themysteryrooms.com.au/escaperoommelbourne/", | |
"image" => "https://themysteryrooms.com.au/wp-content/uploads/2020/12/Mlogo150px.png", | |
"telephone" => "+61390873223", | |
"email" => "[email protected]", | |
"priceRange" => "$$", | |
"address" => array( | |
"@type" => "PostalAddress", | |
"streetAddress" => "303 Napier Street", | |
"addressLocality" => "Fitzroy", | |
"addressRegion" => "VIC", | |
"postalCode" =>"3065", | |
"addressCountry" => "AU" | |
), | |
"location" => array( | |
"@type" => "Place", | |
"geo" => array( | |
"@type" => "GeoCoordinates", | |
"latitude" => "-37.798895", | |
"longitude" => "144.980489" | |
) | |
), | |
"areaServed" => array( | |
"@type" => "City", | |
"name" => array( | |
"Melbourne" | |
) | |
), | |
"openingHoursSpecification" => array( | |
"@type" => "OpeningHoursSpecification", | |
"dayOfWeek" => array( | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Sunday" | |
), | |
"opens" => "10:00", | |
"closes" => "22:00" | |
), | |
"@type" => "OpeningHoursSpecification", | |
"dayOfWeek" => array ( | |
"Friday", | |
"Saturday" | |
), | |
"opens" => "10:00", | |
"closes" => "22:00" | |
); | |
########## CONFIG END; DO NOT EDIT BELOW ################# | |
foreach( $data as $key=>$item ) { | |
if ( $data[$key]['@type'] == $addto ) { | |
$data[$key][$custom_property_name] = $custom_property; | |
} | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment