lightspeeddevelopment /
to-specials
| 1 | <?php |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 2 | /** |
||
| 3 | * LSX_TO_Specials_Schema |
||
| 4 | * |
||
| 5 | * @package LSX_TO_Specials_Schema |
||
| 6 | * @author LightSpeed |
||
| 7 | * @license GPL-3.0+ |
||
| 8 | * @link |
||
| 9 | * @copyright 2018 LightSpeedDevelopment |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Main plugin class. |
||
| 14 | * |
||
| 15 | * @package LSX_Specials_Schema |
||
| 16 | * @author LightSpeed |
||
| 17 | */ |
||
| 18 | |||
| 19 | class LSX_TO_Specials_Schema extends LSX_TO_Specials { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor |
||
| 23 | */ |
||
| 24 | public function __construct() { |
||
| 25 | $this->set_vars(); |
||
| 26 | add_action( 'wp_head', array( $this, 'specials_single_schema' ), 1499 ); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Creates the schema for the specials post type |
||
| 31 | * |
||
| 32 | * @since 1.0.0 |
||
| 33 | * @return object A single instance of this class. |
||
| 34 | */ |
||
| 35 | public function specials_single_schema() { |
||
| 36 | if ( is_singular( 'special' ) ) { |
||
| 37 | |||
| 38 | $destination_list_special = get_post_meta( get_the_ID(), 'destination_to_special', false ); |
||
| 39 | $destination_list_schema = array(); |
||
| 40 | $url_option = get_the_permalink(); |
||
| 41 | $special_title = get_the_title(); |
||
| 42 | $primary_url = get_the_permalink(); |
||
| 43 | $special_content = wp_strip_all_tags( get_the_content() ); |
||
| 44 | $thumb_url = get_the_post_thumbnail_url( get_the_ID(), 'full' ); |
||
| 45 | $price = get_post_meta( get_the_ID(), 'price', false ); |
||
| 46 | $start_validity = get_post_meta( get_the_ID(), 'booking_validity_start', false ); |
||
| 47 | $end_validity = get_post_meta( get_the_ID(), 'booking_validity_end', false ); |
||
| 48 | |||
| 49 | |||
| 50 | if ( ! empty( $destination_list_special ) ) { |
||
| 51 | foreach( $destination_list_special as $single_destination ) { |
||
|
0 ignored issues
–
show
|
|||
| 52 | $url_option = get_the_permalink() . '#destination-' . $i; |
||
| 53 | $destination_name = get_the_title($single_destination); |
||
| 54 | $schema_day = array( |
||
| 55 | "@type" => "PostalAddress", |
||
|
0 ignored issues
–
show
|
|||
| 56 | "addressLocality" => $destination_name, |
||
|
0 ignored issues
–
show
|
|||
| 57 | ); |
||
|
0 ignored issues
–
show
|
|||
| 58 | $destination_list_schema[] = $schema_day; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | $meta = array( |
||
| 62 | array( |
||
| 63 | "@context" => "http://schema.org", |
||
|
0 ignored issues
–
show
|
|||
| 64 | "@type" => array("Trip", "ProfessionalService", "Offer"), |
||
|
0 ignored issues
–
show
|
|||
| 65 | "offers" => array( |
||
|
0 ignored issues
–
show
|
|||
| 66 | "@type" => "Offer", |
||
|
0 ignored issues
–
show
|
|||
| 67 | "price" => $price, |
||
|
0 ignored issues
–
show
|
|||
| 68 | "availabilityStarts" => $start_validity, |
||
|
0 ignored issues
–
show
|
|||
| 69 | "availabilityEnds" => $end_validity, |
||
|
0 ignored issues
–
show
|
|||
| 70 | ), |
||
| 71 | "address" => $destination_list_schema, |
||
|
0 ignored issues
–
show
|
|||
| 72 | "telephone" => "0216713090", |
||
|
0 ignored issues
–
show
|
|||
| 73 | "priceRange" => $price, |
||
|
0 ignored issues
–
show
|
|||
| 74 | "description" => $special_content, |
||
| 75 | "image" => $thumb_url, |
||
|
0 ignored issues
–
show
|
|||
| 76 | "name" => $special_title, |
||
|
0 ignored issues
–
show
|
|||
| 77 | "provider" => "Southern Destinations", |
||
|
0 ignored issues
–
show
|
|||
| 78 | "url" => $primary_url, |
||
|
0 ignored issues
–
show
|
|||
| 79 | ), |
||
| 80 | ); |
||
| 81 | $output = wp_json_encode( $meta, JSON_UNESCAPED_SLASHES ); |
||
| 82 | ?> |
||
| 83 | <script type="application/ld+json"> |
||
| 84 | <?php echo wp_kses_post( $output ); ?> |
||
| 85 | </script> |
||
| 86 | <?php |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | new LSX_TO_Specials_Schema(); |
||
| 92 |