@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return bool True if it has schema, false if not. |
20 | 20 | */ |
21 | - public static function is_type( $post_type = null, $comparison_type = null ) { |
|
22 | - if ( is_null( $comparison_type ) ) { |
|
21 | + public static function is_type($post_type = null, $comparison_type = null) { |
|
22 | + if (is_null($comparison_type)) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - if ( is_null( $post_type ) ) { |
|
25 | + if (is_null($post_type)) { |
|
26 | 26 | $post_type = get_post_type(); |
27 | 27 | } |
28 | 28 | /** |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @api string[] $post_types The post types for which we output Review. |
32 | 32 | */ |
33 | - $post_types = apply_filters( 'wpseo_schema_' . $comparison_type . '_post_types', array( $comparison_type ) ); |
|
34 | - return in_array( $post_type, $post_types ); |
|
33 | + $post_types = apply_filters('wpseo_schema_' . $comparison_type . '_post_types', array($comparison_type)); |
|
34 | + return in_array($post_type, $post_types); |
|
35 | 35 | } |
36 | 36 | /** |
37 | 37 | * Retrieve a users Schema ID. |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return string The user's schema ID. |
44 | 44 | */ |
45 | - public static function get_places_schema_id( $place_id, $type, $context ) { |
|
46 | - $url = $context->site_url . '#/schema/' . strtolower( $type ) . '/' . wp_hash( $place_id . get_the_title( $place_id ) ); |
|
47 | - return trailingslashit( $url ); |
|
45 | + public static function get_places_schema_id($place_id, $type, $context) { |
|
46 | + $url = $context->site_url . '#/schema/' . strtolower($type) . '/' . wp_hash($place_id . get_the_title($place_id)); |
|
47 | + return trailingslashit($url); |
|
48 | 48 | } |
49 | 49 | /** |
50 | 50 | * Retrieve a users Schema ID. |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string The user's schema ID. |
56 | 56 | */ |
57 | - public static function get_subtrip_schema_id( $name, $context ) { |
|
58 | - $url = $context->site_url . '#/subtrip/' . wp_hash( $name . $context->id ); |
|
59 | - return trailingslashit( $url ); |
|
57 | + public static function get_subtrip_schema_id($name, $context) { |
|
58 | + $url = $context->site_url . '#/subtrip/' . wp_hash($name . $context->id); |
|
59 | + return trailingslashit($url); |
|
60 | 60 | } |
61 | 61 | /** |
62 | 62 | * Retrieve an offer Schema ID. |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return string The user's schema ID. |
69 | 69 | */ |
70 | - public static function get_offer_schema_id( $id, $context, $local = false ) { |
|
71 | - if ( false === $local ) { |
|
70 | + public static function get_offer_schema_id($id, $context, $local = false) { |
|
71 | + if (false === $local) { |
|
72 | 72 | $url = $context->site_url; |
73 | 73 | } else { |
74 | - $url = get_permalink( $context->id ); |
|
74 | + $url = get_permalink($context->id); |
|
75 | 75 | } |
76 | 76 | $url .= '#/schema/offer/'; |
77 | - $url .= wp_hash( $id . get_the_title( $id ) ); |
|
78 | - return trailingslashit( $url ); |
|
77 | + $url .= wp_hash($id . get_the_title($id)); |
|
78 | + return trailingslashit($url); |
|
79 | 79 | } |
80 | 80 | /** |
81 | 81 | * Retrieve an review Schema ID. |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return string The user's schema ID. |
88 | 88 | */ |
89 | - public static function get_review_schema_id( $id, $context, $local = false ) { |
|
90 | - if ( false === $local ) { |
|
89 | + public static function get_review_schema_id($id, $context, $local = false) { |
|
90 | + if (false === $local) { |
|
91 | 91 | $url = $context->site_url; |
92 | 92 | } else { |
93 | - $url = get_permalink( $context->id ); |
|
93 | + $url = get_permalink($context->id); |
|
94 | 94 | } |
95 | 95 | $url .= '#/schema/review/'; |
96 | - $url .= wp_hash( $id . get_the_title( $id ) ); |
|
97 | - return trailingslashit( $url ); |
|
96 | + $url .= wp_hash($id . get_the_title($id)); |
|
97 | + return trailingslashit($url); |
|
98 | 98 | } |
99 | 99 | /** |
100 | 100 | * Retrieve an Article Schema ID. |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return string The user's schema ID. |
107 | 107 | */ |
108 | - public static function get_article_schema_id( $id, $context, $local = false ) { |
|
109 | - if ( false === $local ) { |
|
110 | - $url = get_permalink( $id ) . \WPSEO_Schema_IDs::ARTICLE_HASH; |
|
108 | + public static function get_article_schema_id($id, $context, $local = false) { |
|
109 | + if (false === $local) { |
|
110 | + $url = get_permalink($id) . \WPSEO_Schema_IDs::ARTICLE_HASH; |
|
111 | 111 | } else { |
112 | - $url = get_permalink( $context->id ) . '#/schema/article/' . wp_hash( $id . get_the_title( $id ) ); |
|
112 | + $url = get_permalink($context->id) . '#/schema/article/' . wp_hash($id . get_the_title($id)); |
|
113 | 113 | } |
114 | - return trailingslashit( $url ); |
|
114 | + return trailingslashit($url); |
|
115 | 115 | } |
116 | 116 | /** |
117 | 117 | * Retrieve a users Schema ID. |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return string The user's schema ID. |
123 | 123 | */ |
124 | - public static function get_author_schema_id( $name, $email, $context ) { |
|
125 | - return $context->site_url . \WPSEO_Schema_IDs::PERSON_HASH . wp_hash( $name . $email ); |
|
124 | + public static function get_author_schema_id($name, $email, $context) { |
|
125 | + return $context->site_url . \WPSEO_Schema_IDs::PERSON_HASH . wp_hash($name . $email); |
|
126 | 126 | } |
127 | 127 | /** |
128 | 128 | * Generates the place graph piece for the subtrip / Itinerary arrays. |
@@ -135,16 +135,16 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return mixed array $data Place data. |
137 | 137 | */ |
138 | - public static function add_place( $data, $type, $post_id, $context, $contained_in = false ) { |
|
139 | - $at_id = self::get_places_schema_id( $post_id, $type, $context ); |
|
138 | + public static function add_place($data, $type, $post_id, $context, $contained_in = false) { |
|
139 | + $at_id = self::get_places_schema_id($post_id, $type, $context); |
|
140 | 140 | $place = array( |
141 | 141 | '@type' => $type, |
142 | 142 | '@id' => $at_id, |
143 | - 'name' => get_the_title( $post_id ), |
|
144 | - 'description' => get_the_excerpt( $post_id ), |
|
145 | - 'url' => get_permalink( $post_id ), |
|
143 | + 'name' => get_the_title($post_id), |
|
144 | + 'description' => get_the_excerpt($post_id), |
|
145 | + 'url' => get_permalink($post_id), |
|
146 | 146 | ); |
147 | - if ( false !== $contained_in ) { |
|
147 | + if (false !== $contained_in) { |
|
148 | 148 | $place['containedInPlace'] = array( |
149 | 149 | '@type' => 'Country', |
150 | 150 | '@id' => $contained_in, |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @return array $data The Review data. |
163 | 163 | */ |
164 | - public static function add_image( $data, $context ) { |
|
165 | - if ( $context->has_image ) { |
|
164 | + public static function add_image($data, $context) { |
|
165 | + if ($context->has_image) { |
|
166 | 166 | $data['image'] = array( |
167 | 167 | '@id' => $context->canonical . \WPSEO_Schema_IDs::PRIMARY_IMAGE_HASH, |
168 | 168 | ); |
@@ -176,18 +176,18 @@ discard block |
||
176 | 176 | * @param string $type The schema type. |
177 | 177 | * @return array $schema An array of the schema markup. |
178 | 178 | */ |
179 | - public static function get_item_reviewed( $items = array(), $type = '' ) { |
|
179 | + public static function get_item_reviewed($items = array(), $type = '') { |
|
180 | 180 | $schema = array(); |
181 | - if ( false !== $items && ! empty( $items ) && '' !== $type ) { |
|
182 | - array_unique( $items ); |
|
183 | - foreach ( $items as $item ) { |
|
184 | - $title = get_the_title( $item ); |
|
185 | - if ( '' !== $title ) { |
|
181 | + if (false !== $items && ! empty($items) && '' !== $type) { |
|
182 | + array_unique($items); |
|
183 | + foreach ($items as $item) { |
|
184 | + $title = get_the_title($item); |
|
185 | + if ('' !== $title) { |
|
186 | 186 | $item_schema = array( |
187 | 187 | '@type' => $type, |
188 | 188 | 'name' => $title, |
189 | 189 | ); |
190 | - $schema[] = $item_schema; |
|
190 | + $schema[] = $item_schema; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | } |
@@ -203,18 +203,18 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return mixed array $data Review data. |
205 | 205 | */ |
206 | - public static function add_terms( $data, $post_id, $key, $taxonomy ) { |
|
207 | - $terms = get_the_terms( $post_id, $taxonomy ); |
|
208 | - if ( is_array( $terms ) ) { |
|
206 | + public static function add_terms($data, $post_id, $key, $taxonomy) { |
|
207 | + $terms = get_the_terms($post_id, $taxonomy); |
|
208 | + if (is_array($terms)) { |
|
209 | 209 | $keywords = array(); |
210 | - foreach ( $terms as $term ) { |
|
210 | + foreach ($terms as $term) { |
|
211 | 211 | // We are checking against the WordPress internal translation. |
212 | 212 | // @codingStandardsIgnoreLine |
213 | - if ( $term->name !== __( 'Uncategorized' ) ) { |
|
213 | + if ($term->name !== __('Uncategorized')) { |
|
214 | 214 | $keywords[] = $term->name; |
215 | 215 | } |
216 | 216 | } |
217 | - $data[ $key ] = implode( ',', $keywords ); |
|
217 | + $data[$key] = implode(',', $keywords); |
|
218 | 218 | } |
219 | 219 | return $data; |
220 | 220 | } |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @param \WPSEO_Schema_Context $context A value object with context variables. |
53 | 53 | */ |
54 | - public function __construct( WPSEO_Schema_Context $context ) { |
|
54 | + public function __construct(WPSEO_Schema_Context $context) { |
|
55 | 55 | $this->context = $context; |
56 | 56 | $this->place_ids = array(); |
57 | - $this->post = get_post( $this->context->id ); |
|
58 | - $this->post_url = get_permalink( $this->context->id ); |
|
57 | + $this->post = get_post($this->context->id); |
|
58 | + $this->post_url = get_permalink($this->context->id); |
|
59 | 59 | $this->is_top_level = false; |
60 | - if ( is_object( $this->post ) && isset( $this->post->post_parent ) && ( false === $this->post->post_parent || 0 === $this->post->post_parent || '' === $this->post->post_parent ) ) { |
|
60 | + if (is_object($this->post) && isset($this->post->post_parent) && (false === $this->post->post_parent || 0 === $this->post->post_parent || '' === $this->post->post_parent)) { |
|
61 | 61 | $this->is_top_level = true; |
62 | 62 | } |
63 | 63 | } |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | * @return bool |
68 | 68 | */ |
69 | 69 | public function is_needed() { |
70 | - if ( ! is_singular() ) { |
|
70 | + if ( ! is_singular()) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | - if ( false === $this->context->site_represents ) { |
|
73 | + if (false === $this->context->site_represents) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | - return LSX_Schema_Utils::is_type( get_post_type(), $this->post_type ); |
|
76 | + return LSX_Schema_Utils::is_type(get_post_type(), $this->post_type); |
|
77 | 77 | } |
78 | 78 | /** |
79 | 79 | * Returns Review data. |
@@ -92,32 +92,32 @@ discard block |
||
92 | 92 | * @param boolean $include_aggregate |
93 | 93 | * @return array $data |
94 | 94 | */ |
95 | - public function add_reviews( $data, $data_key = 'reviews', $include_aggregate = true ) { |
|
96 | - $reviews = get_post_meta( $this->context->id, 'review_to_' . $this->post_type, false ); |
|
95 | + public function add_reviews($data, $data_key = 'reviews', $include_aggregate = true) { |
|
96 | + $reviews = get_post_meta($this->context->id, 'review_to_' . $this->post_type, false); |
|
97 | 97 | $reviews_array = array(); |
98 | - if ( ! empty( $reviews ) ) { |
|
98 | + if ( ! empty($reviews)) { |
|
99 | 99 | $aggregate_value = 1; |
100 | 100 | $review_count = 0; |
101 | - foreach ( $reviews as $review_id ) { |
|
102 | - $rating = get_post_meta( $review_id, 'rating', true ); |
|
103 | - $author = get_post_meta( $review_id, 'reviewer_name', true ); |
|
104 | - $description = wp_strip_all_tags( get_the_excerpt( $review_id ) ); |
|
101 | + foreach ($reviews as $review_id) { |
|
102 | + $rating = get_post_meta($review_id, 'rating', true); |
|
103 | + $author = get_post_meta($review_id, 'reviewer_name', true); |
|
104 | + $description = wp_strip_all_tags(get_the_excerpt($review_id)); |
|
105 | 105 | $review_args = array( |
106 | 106 | 'author' => $author, |
107 | 107 | 'reviewBody' => $description, |
108 | 108 | ); |
109 | 109 | // Add in the review rating. |
110 | - if ( false !== $rating && '' !== $rating && '0' !== $rating && 0 !== $rating ) { |
|
110 | + if (false !== $rating && '' !== $rating && '0' !== $rating && 0 !== $rating) { |
|
111 | 111 | $review_args['reviewRating'] = array( |
112 | 112 | '@type' => 'Rating', |
113 | 113 | 'ratingValue' => $rating, |
114 | 114 | ); |
115 | 115 | } |
116 | - $reviews_array = LSX_Schema_Utils::add_review( $reviews_array, $review_id, $this->context, $review_args ); |
|
116 | + $reviews_array = LSX_Schema_Utils::add_review($reviews_array, $review_id, $this->context, $review_args); |
|
117 | 117 | $review_count++; |
118 | 118 | } |
119 | - if ( ! empty( $reviews_array ) ) { |
|
120 | - if ( true === $include_aggregate ) { |
|
119 | + if ( ! empty($reviews_array)) { |
|
120 | + if (true === $include_aggregate) { |
|
121 | 121 | $data['aggregateRating'] = array( |
122 | 122 | '@type' => 'AggregateRating', |
123 | 123 | 'ratingValue' => (string) $aggregate_value, |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'worstRating' => '1', |
127 | 127 | ); |
128 | 128 | } |
129 | - $data[ $data_key ] = $reviews_array; |
|
129 | + $data[$data_key] = $reviews_array; |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | return $data; |
@@ -138,30 +138,30 @@ discard block |
||
138 | 138 | * @param string $data_key |
139 | 139 | * @return array $data |
140 | 140 | */ |
141 | - public function add_articles( $data, $data_key = 'subjectOf' ) { |
|
142 | - $posts = get_post_meta( $this->context->id, 'post_to_' . $this->post_type, false ); |
|
141 | + public function add_articles($data, $data_key = 'subjectOf') { |
|
142 | + $posts = get_post_meta($this->context->id, 'post_to_' . $this->post_type, false); |
|
143 | 143 | $posts_array = array(); |
144 | - if ( ! empty( $posts ) ) { |
|
145 | - foreach ( $posts as $post_id ) { |
|
144 | + if ( ! empty($posts)) { |
|
145 | + foreach ($posts as $post_id) { |
|
146 | 146 | $post_args = array( |
147 | - 'articleBody' => wp_strip_all_tags( get_the_excerpt( $post_id ) ), |
|
148 | - 'headline' => get_the_title( $post_id ), |
|
147 | + 'articleBody' => wp_strip_all_tags(get_the_excerpt($post_id)), |
|
148 | + 'headline' => get_the_title($post_id), |
|
149 | 149 | ); |
150 | - $section = get_the_term_list( $post_id, 'category' ); |
|
151 | - if ( ! is_wp_error( $section ) && '' !== $section && false !== $section ) { |
|
152 | - $post_args['articleSection'] = wp_strip_all_tags( $section ); |
|
150 | + $section = get_the_term_list($post_id, 'category'); |
|
151 | + if ( ! is_wp_error($section) && '' !== $section && false !== $section) { |
|
152 | + $post_args['articleSection'] = wp_strip_all_tags($section); |
|
153 | 153 | } |
154 | - if ( $this->context->site_represents_reference ) { |
|
154 | + if ($this->context->site_represents_reference) { |
|
155 | 155 | $post_args['publisher'] = $this->context->site_represents_reference; |
156 | 156 | } |
157 | - $image_url = get_the_post_thumbnail_url( $post_id, 'lsx-thumbnail-wide' ); |
|
158 | - if ( false !== $image_url ) { |
|
157 | + $image_url = get_the_post_thumbnail_url($post_id, 'lsx-thumbnail-wide'); |
|
158 | + if (false !== $image_url) { |
|
159 | 159 | $post_args['image'] = $image_url; |
160 | 160 | } |
161 | - $posts_array = LSX_Schema_Utils::add_article( $posts_array, $post_id, $this->context, $post_args ); |
|
161 | + $posts_array = LSX_Schema_Utils::add_article($posts_array, $post_id, $this->context, $post_args); |
|
162 | 162 | } |
163 | - if ( ! empty( $posts_array ) ) { |
|
164 | - $data[ $data_key ] = $posts_array; |
|
163 | + if ( ! empty($posts_array)) { |
|
164 | + $data[$data_key] = $posts_array; |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | return $data; |
@@ -173,19 +173,19 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return array $data |
175 | 175 | */ |
176 | - public function add_connections( $data ) { |
|
176 | + public function add_connections($data) { |
|
177 | 177 | $connections_array = array(); |
178 | - if ( $this->is_top_level ) { |
|
179 | - $connections_array = $this->add_regions( $connections_array ); |
|
180 | - $connections_array = $this->add_accommodation( $connections_array ); |
|
181 | - if ( ! empty( $connections_array ) ) { |
|
178 | + if ($this->is_top_level) { |
|
179 | + $connections_array = $this->add_regions($connections_array); |
|
180 | + $connections_array = $this->add_accommodation($connections_array); |
|
181 | + if ( ! empty($connections_array)) { |
|
182 | 182 | $data['containsPlace'] = $connections_array; |
183 | 183 | } |
184 | 184 | } else { |
185 | - $connections_array = $this->add_countries( $connections_array ); |
|
185 | + $connections_array = $this->add_countries($connections_array); |
|
186 | 186 | $data['containedInPlace'] = $connections_array; |
187 | 187 | $connections_array = array(); |
188 | - $connections_array = $this->add_accommodation( $connections_array ); |
|
188 | + $connections_array = $this->add_accommodation($connections_array); |
|
189 | 189 | $data['containsPlace'] = $connections_array; |
190 | 190 | } |
191 | 191 | return $data; |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return array $data Review data. |
201 | 201 | */ |
202 | - public function add_taxonomy_terms( $data, $data_key, $taxonomy ) { |
|
202 | + public function add_taxonomy_terms($data, $data_key, $taxonomy) { |
|
203 | 203 | /** |
204 | 204 | * Filter: 'lsx_schema_' . $this->post_type . '_' . $data_key . '_taxonomy' - Allow changing the taxonomy used to assign keywords to a post type Review data. |
205 | 205 | * |
206 | 206 | * @api string $taxonomy The chosen taxonomy. |
207 | 207 | */ |
208 | - $taxonomy = apply_filters( 'lsx_schema_' . $this->post_type . '_' . $data_key . '_taxonomy', $taxonomy ); |
|
209 | - return LSX_Schema_Utils::add_terms( $data, $this->context->id, $data_key, $taxonomy ); |
|
208 | + $taxonomy = apply_filters('lsx_schema_' . $this->post_type . '_' . $data_key . '_taxonomy', $taxonomy); |
|
209 | + return LSX_Schema_Utils::add_terms($data, $this->context->id, $data_key, $taxonomy); |
|
210 | 210 | } |
211 | 211 | /** |
212 | 212 | * Adds the custom field value for the supplied key |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return array $data Review data. |
220 | 220 | */ |
221 | - public function add_custom_field( $data, $data_key, $meta_key, $single = true ) { |
|
222 | - $value = get_post_meta( $this->context->id, $meta_key, $single ); |
|
223 | - if ( '' !== $value && false !== $value ) { |
|
224 | - $data[ $data_key ] = $value; |
|
221 | + public function add_custom_field($data, $data_key, $meta_key, $single = true) { |
|
222 | + $value = get_post_meta($this->context->id, $meta_key, $single); |
|
223 | + if ('' !== $value && false !== $value) { |
|
224 | + $data[$data_key] = $value; |
|
225 | 225 | } |
226 | 226 | return $data; |
227 | 227 | } |