@@ -19,256 +19,256 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Term_JsonLd_Adapter { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The {@link Wordlift_Entity_Uri_Service} instance. |
|
| 24 | - * |
|
| 25 | - * @since 3.20.0 |
|
| 26 | - * @access private |
|
| 27 | - * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
| 28 | - */ |
|
| 29 | - private $entity_uri_service; |
|
| 30 | - |
|
| 31 | - private static $instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Wordlift_Term_JsonLd_Adapter constructor. |
|
| 35 | - * |
|
| 36 | - * @param \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
| 37 | - * @param \Wordlift_Jsonld_Service $jsonld_service The {@link Wordlift_Jsonld_Service} instance. |
|
| 38 | - * |
|
| 39 | - * @since 3.20.0 |
|
| 40 | - * |
|
| 41 | - */ |
|
| 42 | - public function __construct( $entity_uri_service ) { |
|
| 43 | - |
|
| 44 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 45 | - |
|
| 46 | - $this->entity_uri_service = $entity_uri_service; |
|
| 47 | - |
|
| 48 | - self::$instance = $this; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public static function get_instance() { |
|
| 52 | - |
|
| 53 | - return self::$instance; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Adds carousel json ld data to term page if the conditions match |
|
| 58 | - * |
|
| 59 | - * @return array|boolean |
|
| 60 | - */ |
|
| 61 | - public function get_carousel_jsonld( $id = null ) { |
|
| 62 | - $posts = $this->get_posts( $id ); |
|
| 63 | - $post_jsonld = array(); |
|
| 64 | - if ( ! is_array( $posts ) || count( $posts ) < 2 ) { |
|
| 65 | - // Bail out if no posts are present. |
|
| 66 | - return false; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if ( ! is_null( $id ) ) { |
|
| 70 | - $term = get_term( $id ); |
|
| 71 | - $post_jsonld['description'] = strip_tags( strip_shortcodes( $term->description ) ); |
|
| 72 | - $thumbnail_id = get_term_meta( $id, 'thumbnail_id', true ); |
|
| 73 | - if ( ! empty( $thumbnail_id ) ) { |
|
| 74 | - $post_jsonld['image'] = wp_get_attachment_url( $thumbnail_id ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // More than 2 items are present, so construct the post_jsonld data |
|
| 79 | - $post_jsonld['@context'] = 'https://schema.org'; |
|
| 80 | - $post_jsonld['@type'] = 'ItemList'; |
|
| 81 | - $post_jsonld['url'] = $this->get_term_url( $id ); |
|
| 82 | - $post_jsonld['itemListElement'] = array(); |
|
| 83 | - $position = 1; |
|
| 84 | - |
|
| 85 | - foreach ( $posts as $post_id ) { |
|
| 86 | - $result = array( |
|
| 87 | - '@type' => 'ListItem', |
|
| 88 | - 'position' => $position, |
|
| 89 | - /** |
|
| 90 | - * We can't use `item` here unless we change the URL for the item to point to the current page. |
|
| 91 | - * |
|
| 92 | - * See https://developers.google.com/search/docs/data-types/carousel |
|
| 93 | - */ |
|
| 94 | - 'url' => apply_filters( 'wl_carousel_post_list_item_url', get_permalink( $post_id ), $post_id ), |
|
| 95 | - ); |
|
| 96 | - array_push( $post_jsonld['itemListElement'], $result ); |
|
| 97 | - $position += 1; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $post_jsonld; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - private function get_posts( $id ) { |
|
| 104 | - global $wp_query; |
|
| 105 | - |
|
| 106 | - if ( ! is_null( $wp_query->posts ) ) { |
|
| 107 | - return array_map( function ( $post ) { |
|
| 108 | - return $post->ID; |
|
| 109 | - }, $wp_query->posts ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if ( is_null( $id ) ) { |
|
| 113 | - return null; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $term = get_term( $id ); |
|
| 117 | - |
|
| 118 | - return get_objects_in_term( $id, $term->taxonomy ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Hook to `wp_head` to print the JSON-LD. |
|
| 123 | - * |
|
| 124 | - * @since 3.20.0 |
|
| 125 | - */ |
|
| 126 | - public function wp_head() { |
|
| 127 | - $query_object = get_queried_object(); |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - // Check if it is a term page. |
|
| 131 | - if ( ! $query_object instanceof WP_Term ) { |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Bail out if `wl_jsonld_enabled` isn't enabled. |
|
| 136 | - if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - $term_id = $query_object->term_id; |
|
| 141 | - |
|
| 142 | - $jsonld = $this->get( $term_id, Jsonld_Context_Enum::PAGE ); |
|
| 143 | - |
|
| 144 | - // Bail out if the JSON-LD is empty. |
|
| 145 | - if ( empty( $jsonld ) ) { |
|
| 146 | - return; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $jsonld_string = wp_json_encode( $jsonld ); |
|
| 150 | - |
|
| 151 | - echo "<script type=\"application/ld+json\" id=\"wl-jsonld-term\">$jsonld_string</script>"; |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - public function get( $id, $context ) { |
|
| 156 | - /** |
|
| 157 | - * Support for carousel rich snippet, get jsonld data present |
|
| 158 | - * for all the posts shown in the term page, and add the jsonld data |
|
| 159 | - * to list |
|
| 160 | - * |
|
| 161 | - * see here: https://developers.google.com/search/docs/data-types/carousel |
|
| 162 | - * |
|
| 163 | - * @since 3.26.0 |
|
| 164 | - */ |
|
| 165 | - $jsonld_array = array(); |
|
| 166 | - |
|
| 167 | - if ( Jsonld_Context_Enum::PAGE === $context ) { |
|
| 168 | - $carousel_data = $this->get_carousel_jsonld( $id ); |
|
| 169 | - if ( $carousel_data ) { |
|
| 170 | - $jsonld_array[] = $carousel_data; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $entities_jsonld_array = $this->get_entity_jsonld( $id, $context ); |
|
| 175 | - |
|
| 176 | - $result = array( |
|
| 177 | - 'jsonld' => array_merge( $jsonld_array, $entities_jsonld_array ), |
|
| 178 | - 'references' => array() |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @since 3.26.3 |
|
| 184 | - * Filter: wl_term_jsonld_array |
|
| 185 | - * @var $id int Term id |
|
| 186 | - * @var $jsonld_array array An array containing jsonld for term and entities. |
|
| 187 | - */ |
|
| 188 | - $arr = apply_filters( 'wl_term_jsonld_array', $result, $id ); |
|
| 189 | - /** |
|
| 190 | - * @since 3.32.0 |
|
| 191 | - * Expand the references returned by this filter. |
|
| 192 | - */ |
|
| 193 | - $references = $this->expand_references( $arr['references'] ); |
|
| 194 | - |
|
| 195 | - $jsonld_array = array_merge( $arr['jsonld'], $references ); |
|
| 196 | - |
|
| 197 | - return $jsonld_array; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - private function get_term_url( $id ) { |
|
| 201 | - if ( is_null( $id ) ) { |
|
| 202 | - return $_SERVER['REQUEST_URI']; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true ); |
|
| 206 | - if ( ! empty( $maybe_url ) ) { |
|
| 207 | - return $maybe_url; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return get_term_link( $id ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Return jsonld for entities bound to terms. |
|
| 215 | - * |
|
| 216 | - * @param int $term_id Term ID. |
|
| 217 | - * @param int $context A context for the JSON-LD generation, valid values in Jsonld_Context_Enum. |
|
| 218 | - * |
|
| 219 | - * @return array |
|
| 220 | - */ |
|
| 221 | - private function get_entity_jsonld( $term_id, $context ) { |
|
| 222 | - $jsonld_service = Wordlift_Jsonld_Service::get_instance(); |
|
| 223 | - // The `_wl_entity_id` are URIs. |
|
| 224 | - $entity_ids = get_term_meta( $term_id, '_wl_entity_id' ); |
|
| 225 | - $entity_uri_service = $this->entity_uri_service; |
|
| 226 | - |
|
| 227 | - $local_entity_ids = array_filter( $entity_ids, function ( $uri ) use ( $entity_uri_service ) { |
|
| 228 | - return $entity_uri_service->is_internal( $uri ); |
|
| 229 | - } ); |
|
| 230 | - |
|
| 231 | - // Bail out if there are no entities. |
|
| 232 | - if ( empty( $local_entity_ids ) ) { |
|
| 233 | - return array(); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $post = $this->entity_uri_service->get_entity( array_shift( $local_entity_ids ) ); |
|
| 237 | - $jsonld = $jsonld_service->get_jsonld( false, $post->ID, $context ); |
|
| 238 | - // Reset the `url` to the term page. |
|
| 239 | - $jsonld[0]['url'] = get_term_link( $term_id ); |
|
| 240 | - |
|
| 241 | - return $jsonld; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param $references |
|
| 247 | - * |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - private function expand_references( $references ) { |
|
| 251 | - $jsonld_service = Wordlift_Jsonld_Service::get_instance(); |
|
| 252 | - // @TODO: we are assuming all the references are posts |
|
| 253 | - // in this method, since now terms are getting converted to |
|
| 254 | - // entities, this might not be true in all cases. |
|
| 255 | - if ( ! is_array( $references ) ) { |
|
| 256 | - return array(); |
|
| 257 | - } |
|
| 258 | - $references_jsonld = array(); |
|
| 259 | - // Expand the references. |
|
| 260 | - foreach ( $references as $reference ) { |
|
| 261 | - |
|
| 262 | - $post_id = $reference; |
|
| 263 | - if ( $reference instanceof Reference) { |
|
| 264 | - $post_id = $reference->get_id(); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - $references_jsonld[] = $jsonld_service->get_jsonld( false, $post_id ); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return $references_jsonld; |
|
| 271 | - |
|
| 272 | - } |
|
| 22 | + /** |
|
| 23 | + * The {@link Wordlift_Entity_Uri_Service} instance. |
|
| 24 | + * |
|
| 25 | + * @since 3.20.0 |
|
| 26 | + * @access private |
|
| 27 | + * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
| 28 | + */ |
|
| 29 | + private $entity_uri_service; |
|
| 30 | + |
|
| 31 | + private static $instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Wordlift_Term_JsonLd_Adapter constructor. |
|
| 35 | + * |
|
| 36 | + * @param \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
| 37 | + * @param \Wordlift_Jsonld_Service $jsonld_service The {@link Wordlift_Jsonld_Service} instance. |
|
| 38 | + * |
|
| 39 | + * @since 3.20.0 |
|
| 40 | + * |
|
| 41 | + */ |
|
| 42 | + public function __construct( $entity_uri_service ) { |
|
| 43 | + |
|
| 44 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 45 | + |
|
| 46 | + $this->entity_uri_service = $entity_uri_service; |
|
| 47 | + |
|
| 48 | + self::$instance = $this; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public static function get_instance() { |
|
| 52 | + |
|
| 53 | + return self::$instance; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Adds carousel json ld data to term page if the conditions match |
|
| 58 | + * |
|
| 59 | + * @return array|boolean |
|
| 60 | + */ |
|
| 61 | + public function get_carousel_jsonld( $id = null ) { |
|
| 62 | + $posts = $this->get_posts( $id ); |
|
| 63 | + $post_jsonld = array(); |
|
| 64 | + if ( ! is_array( $posts ) || count( $posts ) < 2 ) { |
|
| 65 | + // Bail out if no posts are present. |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if ( ! is_null( $id ) ) { |
|
| 70 | + $term = get_term( $id ); |
|
| 71 | + $post_jsonld['description'] = strip_tags( strip_shortcodes( $term->description ) ); |
|
| 72 | + $thumbnail_id = get_term_meta( $id, 'thumbnail_id', true ); |
|
| 73 | + if ( ! empty( $thumbnail_id ) ) { |
|
| 74 | + $post_jsonld['image'] = wp_get_attachment_url( $thumbnail_id ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // More than 2 items are present, so construct the post_jsonld data |
|
| 79 | + $post_jsonld['@context'] = 'https://schema.org'; |
|
| 80 | + $post_jsonld['@type'] = 'ItemList'; |
|
| 81 | + $post_jsonld['url'] = $this->get_term_url( $id ); |
|
| 82 | + $post_jsonld['itemListElement'] = array(); |
|
| 83 | + $position = 1; |
|
| 84 | + |
|
| 85 | + foreach ( $posts as $post_id ) { |
|
| 86 | + $result = array( |
|
| 87 | + '@type' => 'ListItem', |
|
| 88 | + 'position' => $position, |
|
| 89 | + /** |
|
| 90 | + * We can't use `item` here unless we change the URL for the item to point to the current page. |
|
| 91 | + * |
|
| 92 | + * See https://developers.google.com/search/docs/data-types/carousel |
|
| 93 | + */ |
|
| 94 | + 'url' => apply_filters( 'wl_carousel_post_list_item_url', get_permalink( $post_id ), $post_id ), |
|
| 95 | + ); |
|
| 96 | + array_push( $post_jsonld['itemListElement'], $result ); |
|
| 97 | + $position += 1; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $post_jsonld; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + private function get_posts( $id ) { |
|
| 104 | + global $wp_query; |
|
| 105 | + |
|
| 106 | + if ( ! is_null( $wp_query->posts ) ) { |
|
| 107 | + return array_map( function ( $post ) { |
|
| 108 | + return $post->ID; |
|
| 109 | + }, $wp_query->posts ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if ( is_null( $id ) ) { |
|
| 113 | + return null; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $term = get_term( $id ); |
|
| 117 | + |
|
| 118 | + return get_objects_in_term( $id, $term->taxonomy ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Hook to `wp_head` to print the JSON-LD. |
|
| 123 | + * |
|
| 124 | + * @since 3.20.0 |
|
| 125 | + */ |
|
| 126 | + public function wp_head() { |
|
| 127 | + $query_object = get_queried_object(); |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + // Check if it is a term page. |
|
| 131 | + if ( ! $query_object instanceof WP_Term ) { |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Bail out if `wl_jsonld_enabled` isn't enabled. |
|
| 136 | + if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + $term_id = $query_object->term_id; |
|
| 141 | + |
|
| 142 | + $jsonld = $this->get( $term_id, Jsonld_Context_Enum::PAGE ); |
|
| 143 | + |
|
| 144 | + // Bail out if the JSON-LD is empty. |
|
| 145 | + if ( empty( $jsonld ) ) { |
|
| 146 | + return; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $jsonld_string = wp_json_encode( $jsonld ); |
|
| 150 | + |
|
| 151 | + echo "<script type=\"application/ld+json\" id=\"wl-jsonld-term\">$jsonld_string</script>"; |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + public function get( $id, $context ) { |
|
| 156 | + /** |
|
| 157 | + * Support for carousel rich snippet, get jsonld data present |
|
| 158 | + * for all the posts shown in the term page, and add the jsonld data |
|
| 159 | + * to list |
|
| 160 | + * |
|
| 161 | + * see here: https://developers.google.com/search/docs/data-types/carousel |
|
| 162 | + * |
|
| 163 | + * @since 3.26.0 |
|
| 164 | + */ |
|
| 165 | + $jsonld_array = array(); |
|
| 166 | + |
|
| 167 | + if ( Jsonld_Context_Enum::PAGE === $context ) { |
|
| 168 | + $carousel_data = $this->get_carousel_jsonld( $id ); |
|
| 169 | + if ( $carousel_data ) { |
|
| 170 | + $jsonld_array[] = $carousel_data; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $entities_jsonld_array = $this->get_entity_jsonld( $id, $context ); |
|
| 175 | + |
|
| 176 | + $result = array( |
|
| 177 | + 'jsonld' => array_merge( $jsonld_array, $entities_jsonld_array ), |
|
| 178 | + 'references' => array() |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @since 3.26.3 |
|
| 184 | + * Filter: wl_term_jsonld_array |
|
| 185 | + * @var $id int Term id |
|
| 186 | + * @var $jsonld_array array An array containing jsonld for term and entities. |
|
| 187 | + */ |
|
| 188 | + $arr = apply_filters( 'wl_term_jsonld_array', $result, $id ); |
|
| 189 | + /** |
|
| 190 | + * @since 3.32.0 |
|
| 191 | + * Expand the references returned by this filter. |
|
| 192 | + */ |
|
| 193 | + $references = $this->expand_references( $arr['references'] ); |
|
| 194 | + |
|
| 195 | + $jsonld_array = array_merge( $arr['jsonld'], $references ); |
|
| 196 | + |
|
| 197 | + return $jsonld_array; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + private function get_term_url( $id ) { |
|
| 201 | + if ( is_null( $id ) ) { |
|
| 202 | + return $_SERVER['REQUEST_URI']; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true ); |
|
| 206 | + if ( ! empty( $maybe_url ) ) { |
|
| 207 | + return $maybe_url; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return get_term_link( $id ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Return jsonld for entities bound to terms. |
|
| 215 | + * |
|
| 216 | + * @param int $term_id Term ID. |
|
| 217 | + * @param int $context A context for the JSON-LD generation, valid values in Jsonld_Context_Enum. |
|
| 218 | + * |
|
| 219 | + * @return array |
|
| 220 | + */ |
|
| 221 | + private function get_entity_jsonld( $term_id, $context ) { |
|
| 222 | + $jsonld_service = Wordlift_Jsonld_Service::get_instance(); |
|
| 223 | + // The `_wl_entity_id` are URIs. |
|
| 224 | + $entity_ids = get_term_meta( $term_id, '_wl_entity_id' ); |
|
| 225 | + $entity_uri_service = $this->entity_uri_service; |
|
| 226 | + |
|
| 227 | + $local_entity_ids = array_filter( $entity_ids, function ( $uri ) use ( $entity_uri_service ) { |
|
| 228 | + return $entity_uri_service->is_internal( $uri ); |
|
| 229 | + } ); |
|
| 230 | + |
|
| 231 | + // Bail out if there are no entities. |
|
| 232 | + if ( empty( $local_entity_ids ) ) { |
|
| 233 | + return array(); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $post = $this->entity_uri_service->get_entity( array_shift( $local_entity_ids ) ); |
|
| 237 | + $jsonld = $jsonld_service->get_jsonld( false, $post->ID, $context ); |
|
| 238 | + // Reset the `url` to the term page. |
|
| 239 | + $jsonld[0]['url'] = get_term_link( $term_id ); |
|
| 240 | + |
|
| 241 | + return $jsonld; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param $references |
|
| 247 | + * |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + private function expand_references( $references ) { |
|
| 251 | + $jsonld_service = Wordlift_Jsonld_Service::get_instance(); |
|
| 252 | + // @TODO: we are assuming all the references are posts |
|
| 253 | + // in this method, since now terms are getting converted to |
|
| 254 | + // entities, this might not be true in all cases. |
|
| 255 | + if ( ! is_array( $references ) ) { |
|
| 256 | + return array(); |
|
| 257 | + } |
|
| 258 | + $references_jsonld = array(); |
|
| 259 | + // Expand the references. |
|
| 260 | + foreach ( $references as $reference ) { |
|
| 261 | + |
|
| 262 | + $post_id = $reference; |
|
| 263 | + if ( $reference instanceof Reference) { |
|
| 264 | + $post_id = $reference->get_id(); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + $references_jsonld[] = $jsonld_service->get_jsonld( false, $post_id ); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return $references_jsonld; |
|
| 271 | + |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | 274 | } |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | * @since 3.20.0 |
| 40 | 40 | * |
| 41 | 41 | */ |
| 42 | - public function __construct( $entity_uri_service ) { |
|
| 42 | + public function __construct($entity_uri_service) { |
|
| 43 | 43 | |
| 44 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 44 | + add_action('wp_head', array($this, 'wp_head')); |
|
| 45 | 45 | |
| 46 | 46 | $this->entity_uri_service = $entity_uri_service; |
| 47 | 47 | |
@@ -58,31 +58,31 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return array|boolean |
| 60 | 60 | */ |
| 61 | - public function get_carousel_jsonld( $id = null ) { |
|
| 62 | - $posts = $this->get_posts( $id ); |
|
| 61 | + public function get_carousel_jsonld($id = null) { |
|
| 62 | + $posts = $this->get_posts($id); |
|
| 63 | 63 | $post_jsonld = array(); |
| 64 | - if ( ! is_array( $posts ) || count( $posts ) < 2 ) { |
|
| 64 | + if ( ! is_array($posts) || count($posts) < 2) { |
|
| 65 | 65 | // Bail out if no posts are present. |
| 66 | 66 | return false; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ( ! is_null( $id ) ) { |
|
| 70 | - $term = get_term( $id ); |
|
| 71 | - $post_jsonld['description'] = strip_tags( strip_shortcodes( $term->description ) ); |
|
| 72 | - $thumbnail_id = get_term_meta( $id, 'thumbnail_id', true ); |
|
| 73 | - if ( ! empty( $thumbnail_id ) ) { |
|
| 74 | - $post_jsonld['image'] = wp_get_attachment_url( $thumbnail_id ); |
|
| 69 | + if ( ! is_null($id)) { |
|
| 70 | + $term = get_term($id); |
|
| 71 | + $post_jsonld['description'] = strip_tags(strip_shortcodes($term->description)); |
|
| 72 | + $thumbnail_id = get_term_meta($id, 'thumbnail_id', true); |
|
| 73 | + if ( ! empty($thumbnail_id)) { |
|
| 74 | + $post_jsonld['image'] = wp_get_attachment_url($thumbnail_id); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // More than 2 items are present, so construct the post_jsonld data |
| 79 | 79 | $post_jsonld['@context'] = 'https://schema.org'; |
| 80 | 80 | $post_jsonld['@type'] = 'ItemList'; |
| 81 | - $post_jsonld['url'] = $this->get_term_url( $id ); |
|
| 81 | + $post_jsonld['url'] = $this->get_term_url($id); |
|
| 82 | 82 | $post_jsonld['itemListElement'] = array(); |
| 83 | 83 | $position = 1; |
| 84 | 84 | |
| 85 | - foreach ( $posts as $post_id ) { |
|
| 85 | + foreach ($posts as $post_id) { |
|
| 86 | 86 | $result = array( |
| 87 | 87 | '@type' => 'ListItem', |
| 88 | 88 | 'position' => $position, |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * See https://developers.google.com/search/docs/data-types/carousel |
| 93 | 93 | */ |
| 94 | - 'url' => apply_filters( 'wl_carousel_post_list_item_url', get_permalink( $post_id ), $post_id ), |
|
| 94 | + 'url' => apply_filters('wl_carousel_post_list_item_url', get_permalink($post_id), $post_id), |
|
| 95 | 95 | ); |
| 96 | - array_push( $post_jsonld['itemListElement'], $result ); |
|
| 96 | + array_push($post_jsonld['itemListElement'], $result); |
|
| 97 | 97 | $position += 1; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $post_jsonld; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - private function get_posts( $id ) { |
|
| 103 | + private function get_posts($id) { |
|
| 104 | 104 | global $wp_query; |
| 105 | 105 | |
| 106 | - if ( ! is_null( $wp_query->posts ) ) { |
|
| 107 | - return array_map( function ( $post ) { |
|
| 106 | + if ( ! is_null($wp_query->posts)) { |
|
| 107 | + return array_map(function($post) { |
|
| 108 | 108 | return $post->ID; |
| 109 | - }, $wp_query->posts ); |
|
| 109 | + }, $wp_query->posts); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( is_null( $id ) ) { |
|
| 112 | + if (is_null($id)) { |
|
| 113 | 113 | return null; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - $term = get_term( $id ); |
|
| 116 | + $term = get_term($id); |
|
| 117 | 117 | |
| 118 | - return get_objects_in_term( $id, $term->taxonomy ); |
|
| 118 | + return get_objects_in_term($id, $term->taxonomy); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | |
| 130 | 130 | // Check if it is a term page. |
| 131 | - if ( ! $query_object instanceof WP_Term ) { |
|
| 131 | + if ( ! $query_object instanceof WP_Term) { |
|
| 132 | 132 | return; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Bail out if `wl_jsonld_enabled` isn't enabled. |
| 136 | - if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) { |
|
| 136 | + if ( ! apply_filters('wl_jsonld_enabled', true)) { |
|
| 137 | 137 | return; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $term_id = $query_object->term_id; |
| 141 | 141 | |
| 142 | - $jsonld = $this->get( $term_id, Jsonld_Context_Enum::PAGE ); |
|
| 142 | + $jsonld = $this->get($term_id, Jsonld_Context_Enum::PAGE); |
|
| 143 | 143 | |
| 144 | 144 | // Bail out if the JSON-LD is empty. |
| 145 | - if ( empty( $jsonld ) ) { |
|
| 145 | + if (empty($jsonld)) { |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $jsonld_string = wp_json_encode( $jsonld ); |
|
| 149 | + $jsonld_string = wp_json_encode($jsonld); |
|
| 150 | 150 | |
| 151 | 151 | echo "<script type=\"application/ld+json\" id=\"wl-jsonld-term\">$jsonld_string</script>"; |
| 152 | 152 | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - public function get( $id, $context ) { |
|
| 155 | + public function get($id, $context) { |
|
| 156 | 156 | /** |
| 157 | 157 | * Support for carousel rich snippet, get jsonld data present |
| 158 | 158 | * for all the posts shown in the term page, and add the jsonld data |
@@ -162,19 +162,19 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @since 3.26.0 |
| 164 | 164 | */ |
| 165 | - $jsonld_array = array(); |
|
| 165 | + $jsonld_array = array(); |
|
| 166 | 166 | |
| 167 | - if ( Jsonld_Context_Enum::PAGE === $context ) { |
|
| 168 | - $carousel_data = $this->get_carousel_jsonld( $id ); |
|
| 169 | - if ( $carousel_data ) { |
|
| 167 | + if (Jsonld_Context_Enum::PAGE === $context) { |
|
| 168 | + $carousel_data = $this->get_carousel_jsonld($id); |
|
| 169 | + if ($carousel_data) { |
|
| 170 | 170 | $jsonld_array[] = $carousel_data; |
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - $entities_jsonld_array = $this->get_entity_jsonld( $id, $context ); |
|
| 174 | + $entities_jsonld_array = $this->get_entity_jsonld($id, $context); |
|
| 175 | 175 | |
| 176 | 176 | $result = array( |
| 177 | - 'jsonld' => array_merge( $jsonld_array, $entities_jsonld_array ), |
|
| 177 | + 'jsonld' => array_merge($jsonld_array, $entities_jsonld_array), |
|
| 178 | 178 | 'references' => array() |
| 179 | 179 | ); |
| 180 | 180 | |
@@ -185,29 +185,29 @@ discard block |
||
| 185 | 185 | * @var $id int Term id |
| 186 | 186 | * @var $jsonld_array array An array containing jsonld for term and entities. |
| 187 | 187 | */ |
| 188 | - $arr = apply_filters( 'wl_term_jsonld_array', $result, $id ); |
|
| 188 | + $arr = apply_filters('wl_term_jsonld_array', $result, $id); |
|
| 189 | 189 | /** |
| 190 | 190 | * @since 3.32.0 |
| 191 | 191 | * Expand the references returned by this filter. |
| 192 | 192 | */ |
| 193 | - $references = $this->expand_references( $arr['references'] ); |
|
| 193 | + $references = $this->expand_references($arr['references']); |
|
| 194 | 194 | |
| 195 | - $jsonld_array = array_merge( $arr['jsonld'], $references ); |
|
| 195 | + $jsonld_array = array_merge($arr['jsonld'], $references); |
|
| 196 | 196 | |
| 197 | 197 | return $jsonld_array; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - private function get_term_url( $id ) { |
|
| 201 | - if ( is_null( $id ) ) { |
|
| 200 | + private function get_term_url($id) { |
|
| 201 | + if (is_null($id)) { |
|
| 202 | 202 | return $_SERVER['REQUEST_URI']; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - $maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true ); |
|
| 206 | - if ( ! empty( $maybe_url ) ) { |
|
| 205 | + $maybe_url = get_term_meta($id, Wordlift_Url_Property_Service::META_KEY, true); |
|
| 206 | + if ( ! empty($maybe_url)) { |
|
| 207 | 207 | return $maybe_url; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - return get_term_link( $id ); |
|
| 210 | + return get_term_link($id); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -218,25 +218,25 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @return array |
| 220 | 220 | */ |
| 221 | - private function get_entity_jsonld( $term_id, $context ) { |
|
| 221 | + private function get_entity_jsonld($term_id, $context) { |
|
| 222 | 222 | $jsonld_service = Wordlift_Jsonld_Service::get_instance(); |
| 223 | 223 | // The `_wl_entity_id` are URIs. |
| 224 | - $entity_ids = get_term_meta( $term_id, '_wl_entity_id' ); |
|
| 224 | + $entity_ids = get_term_meta($term_id, '_wl_entity_id'); |
|
| 225 | 225 | $entity_uri_service = $this->entity_uri_service; |
| 226 | 226 | |
| 227 | - $local_entity_ids = array_filter( $entity_ids, function ( $uri ) use ( $entity_uri_service ) { |
|
| 228 | - return $entity_uri_service->is_internal( $uri ); |
|
| 227 | + $local_entity_ids = array_filter($entity_ids, function($uri) use ($entity_uri_service) { |
|
| 228 | + return $entity_uri_service->is_internal($uri); |
|
| 229 | 229 | } ); |
| 230 | 230 | |
| 231 | 231 | // Bail out if there are no entities. |
| 232 | - if ( empty( $local_entity_ids ) ) { |
|
| 232 | + if (empty($local_entity_ids)) { |
|
| 233 | 233 | return array(); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $post = $this->entity_uri_service->get_entity( array_shift( $local_entity_ids ) ); |
|
| 237 | - $jsonld = $jsonld_service->get_jsonld( false, $post->ID, $context ); |
|
| 236 | + $post = $this->entity_uri_service->get_entity(array_shift($local_entity_ids)); |
|
| 237 | + $jsonld = $jsonld_service->get_jsonld(false, $post->ID, $context); |
|
| 238 | 238 | // Reset the `url` to the term page. |
| 239 | - $jsonld[0]['url'] = get_term_link( $term_id ); |
|
| 239 | + $jsonld[0]['url'] = get_term_link($term_id); |
|
| 240 | 240 | |
| 241 | 241 | return $jsonld; |
| 242 | 242 | } |
@@ -247,24 +247,24 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | - private function expand_references( $references ) { |
|
| 250 | + private function expand_references($references) { |
|
| 251 | 251 | $jsonld_service = Wordlift_Jsonld_Service::get_instance(); |
| 252 | 252 | // @TODO: we are assuming all the references are posts |
| 253 | 253 | // in this method, since now terms are getting converted to |
| 254 | 254 | // entities, this might not be true in all cases. |
| 255 | - if ( ! is_array( $references ) ) { |
|
| 255 | + if ( ! is_array($references)) { |
|
| 256 | 256 | return array(); |
| 257 | 257 | } |
| 258 | 258 | $references_jsonld = array(); |
| 259 | 259 | // Expand the references. |
| 260 | - foreach ( $references as $reference ) { |
|
| 260 | + foreach ($references as $reference) { |
|
| 261 | 261 | |
| 262 | 262 | $post_id = $reference; |
| 263 | - if ( $reference instanceof Reference) { |
|
| 263 | + if ($reference instanceof Reference) { |
|
| 264 | 264 | $post_id = $reference->get_id(); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $references_jsonld[] = $jsonld_service->get_jsonld( false, $post_id ); |
|
| 267 | + $references_jsonld[] = $jsonld_service->get_jsonld(false, $post_id); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | return $references_jsonld; |
@@ -16,87 +16,87 @@ |
||
| 16 | 16 | * @package Wordlift\Term |
| 17 | 17 | */ |
| 18 | 18 | class Type_Service extends Singleton { |
| 19 | - /** |
|
| 20 | - * @var \Wordlift_Schema_Service |
|
| 21 | - */ |
|
| 22 | - private $schema_service; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @return Type_Service |
|
| 26 | - */ |
|
| 27 | - public static function get_instance() { |
|
| 28 | - return parent::get_instance(); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function __construct() { |
|
| 32 | - parent::__construct(); |
|
| 33 | - $this->schema_service = \Wordlift_Schema_Service::get_instance(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function get_entity_types_labels( $term_id ) { |
|
| 37 | - $entity_types = $this->get_entity_types( $term_id ); |
|
| 38 | - return array_map( function ( $entity_type ) { |
|
| 39 | - return $entity_type->name; |
|
| 40 | - }, $entity_types ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Returns the entity types selected for the term. |
|
| 45 | - * |
|
| 46 | - * @param $term_id int |
|
| 47 | - * |
|
| 48 | - * @return \WP_Term[] |
|
| 49 | - */ |
|
| 50 | - public function get_entity_types( $term_id ) { |
|
| 51 | - |
|
| 52 | - $entity_type_slugs = get_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 53 | - |
|
| 54 | - $types = array_filter( array_map( function ( $type_slug ) { |
|
| 55 | - $term = get_term_by( 'slug', $type_slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 56 | - if ( ! $term ) { |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return $term; |
|
| 61 | - }, $entity_type_slugs ) ); |
|
| 62 | - |
|
| 63 | - $types = array_filter( $types ); |
|
| 64 | - |
|
| 65 | - if ( 0 !== count( $types ) ) { |
|
| 66 | - return $types; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return array( get_term_by( 'slug', 'thing', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param $term_id int |
|
| 75 | - * |
|
| 76 | - * @return array|null |
|
| 77 | - */ |
|
| 78 | - public function get_schema( $term_id ) { |
|
| 79 | - $entity_types = $this->get_entity_types( $term_id ); |
|
| 80 | - foreach ( $entity_types as $entity_type ) { |
|
| 81 | - $schema = $this->schema_service->get_schema( $entity_type->slug ); |
|
| 82 | - if ( ! $schema ) { |
|
| 83 | - break; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return $this->schema_service->get_schema( 'thing' ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Removes all the existing entity types and set the entity types for the term. |
|
| 92 | - * @param $term_id int |
|
| 93 | - * @param $entity_types array |
|
| 94 | - */ |
|
| 95 | - public function set_entity_types( $term_id, $entity_types ) { |
|
| 96 | - delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 97 | - foreach ( $entity_types as $entity_type ) { |
|
| 98 | - add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $entity_type ); |
|
| 99 | - } |
|
| 100 | - } |
|
| 19 | + /** |
|
| 20 | + * @var \Wordlift_Schema_Service |
|
| 21 | + */ |
|
| 22 | + private $schema_service; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @return Type_Service |
|
| 26 | + */ |
|
| 27 | + public static function get_instance() { |
|
| 28 | + return parent::get_instance(); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function __construct() { |
|
| 32 | + parent::__construct(); |
|
| 33 | + $this->schema_service = \Wordlift_Schema_Service::get_instance(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function get_entity_types_labels( $term_id ) { |
|
| 37 | + $entity_types = $this->get_entity_types( $term_id ); |
|
| 38 | + return array_map( function ( $entity_type ) { |
|
| 39 | + return $entity_type->name; |
|
| 40 | + }, $entity_types ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Returns the entity types selected for the term. |
|
| 45 | + * |
|
| 46 | + * @param $term_id int |
|
| 47 | + * |
|
| 48 | + * @return \WP_Term[] |
|
| 49 | + */ |
|
| 50 | + public function get_entity_types( $term_id ) { |
|
| 51 | + |
|
| 52 | + $entity_type_slugs = get_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 53 | + |
|
| 54 | + $types = array_filter( array_map( function ( $type_slug ) { |
|
| 55 | + $term = get_term_by( 'slug', $type_slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 56 | + if ( ! $term ) { |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return $term; |
|
| 61 | + }, $entity_type_slugs ) ); |
|
| 62 | + |
|
| 63 | + $types = array_filter( $types ); |
|
| 64 | + |
|
| 65 | + if ( 0 !== count( $types ) ) { |
|
| 66 | + return $types; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return array( get_term_by( 'slug', 'thing', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param $term_id int |
|
| 75 | + * |
|
| 76 | + * @return array|null |
|
| 77 | + */ |
|
| 78 | + public function get_schema( $term_id ) { |
|
| 79 | + $entity_types = $this->get_entity_types( $term_id ); |
|
| 80 | + foreach ( $entity_types as $entity_type ) { |
|
| 81 | + $schema = $this->schema_service->get_schema( $entity_type->slug ); |
|
| 82 | + if ( ! $schema ) { |
|
| 83 | + break; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return $this->schema_service->get_schema( 'thing' ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Removes all the existing entity types and set the entity types for the term. |
|
| 92 | + * @param $term_id int |
|
| 93 | + * @param $entity_types array |
|
| 94 | + */ |
|
| 95 | + public function set_entity_types( $term_id, $entity_types ) { |
|
| 96 | + delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 97 | + foreach ( $entity_types as $entity_type ) { |
|
| 98 | + add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $entity_type ); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | \ No newline at end of file |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | $this->schema_service = \Wordlift_Schema_Service::get_instance(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function get_entity_types_labels( $term_id ) { |
|
| 37 | - $entity_types = $this->get_entity_types( $term_id ); |
|
| 38 | - return array_map( function ( $entity_type ) { |
|
| 36 | + public function get_entity_types_labels($term_id) { |
|
| 37 | + $entity_types = $this->get_entity_types($term_id); |
|
| 38 | + return array_map(function($entity_type) { |
|
| 39 | 39 | return $entity_type->name; |
| 40 | - }, $entity_types ); |
|
| 40 | + }, $entity_types); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return \WP_Term[] |
| 49 | 49 | */ |
| 50 | - public function get_entity_types( $term_id ) { |
|
| 50 | + public function get_entity_types($term_id) { |
|
| 51 | 51 | |
| 52 | - $entity_type_slugs = get_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 52 | + $entity_type_slugs = get_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 53 | 53 | |
| 54 | - $types = array_filter( array_map( function ( $type_slug ) { |
|
| 55 | - $term = get_term_by( 'slug', $type_slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 56 | - if ( ! $term ) { |
|
| 54 | + $types = array_filter(array_map(function($type_slug) { |
|
| 55 | + $term = get_term_by('slug', $type_slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 56 | + if ( ! $term) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return $term; |
| 61 | - }, $entity_type_slugs ) ); |
|
| 61 | + }, $entity_type_slugs)); |
|
| 62 | 62 | |
| 63 | - $types = array_filter( $types ); |
|
| 63 | + $types = array_filter($types); |
|
| 64 | 64 | |
| 65 | - if ( 0 !== count( $types ) ) { |
|
| 65 | + if (0 !== count($types)) { |
|
| 66 | 66 | return $types; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - return array( get_term_by( 'slug', 'thing', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ); |
|
| 69 | + return array(get_term_by('slug', 'thing', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -75,16 +75,16 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return array|null |
| 77 | 77 | */ |
| 78 | - public function get_schema( $term_id ) { |
|
| 79 | - $entity_types = $this->get_entity_types( $term_id ); |
|
| 80 | - foreach ( $entity_types as $entity_type ) { |
|
| 81 | - $schema = $this->schema_service->get_schema( $entity_type->slug ); |
|
| 82 | - if ( ! $schema ) { |
|
| 78 | + public function get_schema($term_id) { |
|
| 79 | + $entity_types = $this->get_entity_types($term_id); |
|
| 80 | + foreach ($entity_types as $entity_type) { |
|
| 81 | + $schema = $this->schema_service->get_schema($entity_type->slug); |
|
| 82 | + if ( ! $schema) { |
|
| 83 | 83 | break; |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return $this->schema_service->get_schema( 'thing' ); |
|
| 87 | + return $this->schema_service->get_schema('thing'); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -92,10 +92,10 @@ discard block |
||
| 92 | 92 | * @param $term_id int |
| 93 | 93 | * @param $entity_types array |
| 94 | 94 | */ |
| 95 | - public function set_entity_types( $term_id, $entity_types ) { |
|
| 96 | - delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 97 | - foreach ( $entity_types as $entity_type ) { |
|
| 98 | - add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $entity_type ); |
|
| 95 | + public function set_entity_types($term_id, $entity_types) { |
|
| 96 | + delete_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 97 | + foreach ($entity_types as $entity_type) { |
|
| 98 | + add_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $entity_type); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
@@ -12,145 +12,145 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Jsonld_Generator { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var \Wordlift_Entity_Type_Service |
|
| 17 | - */ |
|
| 18 | - private $entity_type_service; |
|
| 19 | - /** |
|
| 20 | - * @var \Wordlift_Property_Getter |
|
| 21 | - */ |
|
| 22 | - private $property_getter; |
|
| 23 | - /** |
|
| 24 | - * @var Type_Service |
|
| 25 | - */ |
|
| 26 | - private $term_entity_type_service; |
|
| 27 | - /** |
|
| 28 | - * @var \Wordlift_Entity_Service |
|
| 29 | - */ |
|
| 30 | - private $entity_service; |
|
| 31 | - |
|
| 32 | - public function __construct( $entity_type_service, $property_getter ) { |
|
| 33 | - $this->entity_type_service = $entity_type_service; |
|
| 34 | - $this->property_getter = $property_getter; |
|
| 35 | - $this->term_entity_type_service = Type_Service::get_instance(); |
|
| 36 | - $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function init() { |
|
| 40 | - add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function wl_term_jsonld_array( $data, $term_id ) { |
|
| 44 | - $jsonld = $data['jsonld']; |
|
| 45 | - $references = $data['references']; |
|
| 46 | - |
|
| 47 | - $term_jsonld_data = $this->get_jsonld_data_for_term( $term_id ); |
|
| 48 | - |
|
| 49 | - // Return early if we dont have the entity data |
|
| 50 | - // for the term. |
|
| 51 | - if ( ! $term_jsonld_data ) { |
|
| 52 | - return $data; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $term_jsonld = $term_jsonld_data['jsonld']; |
|
| 56 | - |
|
| 57 | - $references = array_merge( $references, $term_jsonld_data['references'] ); |
|
| 58 | - |
|
| 59 | - array_unshift( $jsonld, $term_jsonld ); |
|
| 60 | - |
|
| 61 | - return array( |
|
| 62 | - 'jsonld' => $jsonld, |
|
| 63 | - 'references' => $references |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - private function get_jsonld_data_for_term( $term_id ) { |
|
| 68 | - |
|
| 69 | - $id = wl_get_term_entity_uri( $term_id ); |
|
| 70 | - |
|
| 71 | - // If we dont have a dataset URI, then dont publish the term data |
|
| 72 | - // on this page. |
|
| 73 | - if ( ! $id ) { |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $references = array(); |
|
| 78 | - $term = get_term( $term_id ); |
|
| 79 | - $permalink = get_term_link( $term ); |
|
| 80 | - |
|
| 81 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id ); |
|
| 82 | - $term = get_term( $term_id ); |
|
| 83 | - $jsonld = array( |
|
| 84 | - '@context' => 'http://schema.org', |
|
| 85 | - 'name' => $term->name, |
|
| 86 | - '@type' => $this->term_entity_type_service->get_entity_types_labels( $term_id ), |
|
| 87 | - '@id' => $id, |
|
| 88 | - 'description' => $term->description, |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - if ( ! $custom_fields || ! is_array( $custom_fields ) ) { |
|
| 92 | - return $jsonld; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - foreach ( $custom_fields as $key => $value ) { |
|
| 96 | - $name = $this->relative_to_schema_context( $value['predicate'] ); |
|
| 97 | - $value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM ); |
|
| 98 | - $value = $this->process_value( $value, $references ); |
|
| 99 | - if ( ! $value ) { |
|
| 100 | - continue; |
|
| 101 | - } |
|
| 102 | - $jsonld[ $name ] = $value; |
|
| 103 | - |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ( $permalink ) { |
|
| 107 | - $jsonld['url'] = $permalink; |
|
| 108 | - $jsonld['mainEntityOfPage'] = $permalink; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return apply_filters( 'wl_no_vocabulary_term_jsonld_array', array( |
|
| 112 | - 'jsonld' => $jsonld, |
|
| 113 | - 'references' => $references |
|
| 114 | - ), $term_id ); |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - private function relative_to_schema_context( $predicate ) { |
|
| 121 | - return str_replace( 'http://schema.org/', '', $predicate ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - private function process_value( $value, &$references ) { |
|
| 125 | - |
|
| 126 | - if ( ! $value ) { |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 15 | + /** |
|
| 16 | + * @var \Wordlift_Entity_Type_Service |
|
| 17 | + */ |
|
| 18 | + private $entity_type_service; |
|
| 19 | + /** |
|
| 20 | + * @var \Wordlift_Property_Getter |
|
| 21 | + */ |
|
| 22 | + private $property_getter; |
|
| 23 | + /** |
|
| 24 | + * @var Type_Service |
|
| 25 | + */ |
|
| 26 | + private $term_entity_type_service; |
|
| 27 | + /** |
|
| 28 | + * @var \Wordlift_Entity_Service |
|
| 29 | + */ |
|
| 30 | + private $entity_service; |
|
| 31 | + |
|
| 32 | + public function __construct( $entity_type_service, $property_getter ) { |
|
| 33 | + $this->entity_type_service = $entity_type_service; |
|
| 34 | + $this->property_getter = $property_getter; |
|
| 35 | + $this->term_entity_type_service = Type_Service::get_instance(); |
|
| 36 | + $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function init() { |
|
| 40 | + add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function wl_term_jsonld_array( $data, $term_id ) { |
|
| 44 | + $jsonld = $data['jsonld']; |
|
| 45 | + $references = $data['references']; |
|
| 46 | + |
|
| 47 | + $term_jsonld_data = $this->get_jsonld_data_for_term( $term_id ); |
|
| 48 | + |
|
| 49 | + // Return early if we dont have the entity data |
|
| 50 | + // for the term. |
|
| 51 | + if ( ! $term_jsonld_data ) { |
|
| 52 | + return $data; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $term_jsonld = $term_jsonld_data['jsonld']; |
|
| 56 | + |
|
| 57 | + $references = array_merge( $references, $term_jsonld_data['references'] ); |
|
| 58 | + |
|
| 59 | + array_unshift( $jsonld, $term_jsonld ); |
|
| 60 | + |
|
| 61 | + return array( |
|
| 62 | + 'jsonld' => $jsonld, |
|
| 63 | + 'references' => $references |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + private function get_jsonld_data_for_term( $term_id ) { |
|
| 68 | + |
|
| 69 | + $id = wl_get_term_entity_uri( $term_id ); |
|
| 70 | + |
|
| 71 | + // If we dont have a dataset URI, then dont publish the term data |
|
| 72 | + // on this page. |
|
| 73 | + if ( ! $id ) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $references = array(); |
|
| 78 | + $term = get_term( $term_id ); |
|
| 79 | + $permalink = get_term_link( $term ); |
|
| 80 | + |
|
| 81 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id ); |
|
| 82 | + $term = get_term( $term_id ); |
|
| 83 | + $jsonld = array( |
|
| 84 | + '@context' => 'http://schema.org', |
|
| 85 | + 'name' => $term->name, |
|
| 86 | + '@type' => $this->term_entity_type_service->get_entity_types_labels( $term_id ), |
|
| 87 | + '@id' => $id, |
|
| 88 | + 'description' => $term->description, |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + if ( ! $custom_fields || ! is_array( $custom_fields ) ) { |
|
| 92 | + return $jsonld; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + foreach ( $custom_fields as $key => $value ) { |
|
| 96 | + $name = $this->relative_to_schema_context( $value['predicate'] ); |
|
| 97 | + $value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM ); |
|
| 98 | + $value = $this->process_value( $value, $references ); |
|
| 99 | + if ( ! $value ) { |
|
| 100 | + continue; |
|
| 101 | + } |
|
| 102 | + $jsonld[ $name ] = $value; |
|
| 103 | + |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ( $permalink ) { |
|
| 107 | + $jsonld['url'] = $permalink; |
|
| 108 | + $jsonld['mainEntityOfPage'] = $permalink; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return apply_filters( 'wl_no_vocabulary_term_jsonld_array', array( |
|
| 112 | + 'jsonld' => $jsonld, |
|
| 113 | + 'references' => $references |
|
| 114 | + ), $term_id ); |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + private function relative_to_schema_context( $predicate ) { |
|
| 121 | + return str_replace( 'http://schema.org/', '', $predicate ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + private function process_value( $value, &$references ) { |
|
| 125 | + |
|
| 126 | + if ( ! $value ) { |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - if ( is_array( $value ) |
|
| 131 | - && count( $value ) > 0 |
|
| 132 | - && $value[0] instanceof \Wordlift_Property_Entity_Reference ) { |
|
| 130 | + if ( is_array( $value ) |
|
| 131 | + && count( $value ) > 0 |
|
| 132 | + && $value[0] instanceof \Wordlift_Property_Entity_Reference ) { |
|
| 133 | 133 | |
| 134 | - // All of the references from the custom fields are post references. |
|
| 135 | - $references = array_merge( $references, array_map( function ( $property_entity_reference ) { |
|
| 136 | - /** |
|
| 137 | - * @var $property_entity_reference \Wordlift_Property_Entity_Reference |
|
| 138 | - */ |
|
| 139 | - return new Post_Reference( $property_entity_reference->get_id() ); |
|
| 140 | - }, $value ) ); |
|
| 134 | + // All of the references from the custom fields are post references. |
|
| 135 | + $references = array_merge( $references, array_map( function ( $property_entity_reference ) { |
|
| 136 | + /** |
|
| 137 | + * @var $property_entity_reference \Wordlift_Property_Entity_Reference |
|
| 138 | + */ |
|
| 139 | + return new Post_Reference( $property_entity_reference->get_id() ); |
|
| 140 | + }, $value ) ); |
|
| 141 | 141 | |
| 142 | - $that = $this; |
|
| 142 | + $that = $this; |
|
| 143 | 143 | |
| 144 | - return array_map( function ( $reference ) use ( $that ) { |
|
| 145 | - /** |
|
| 146 | - * @var $reference \Wordlift_Property_Entity_Reference |
|
| 147 | - */ |
|
| 148 | - return array( '@id' => $that->entity_service->get_uri( $reference->get_id() ) ); |
|
| 149 | - }, $value ); |
|
| 144 | + return array_map( function ( $reference ) use ( $that ) { |
|
| 145 | + /** |
|
| 146 | + * @var $reference \Wordlift_Property_Entity_Reference |
|
| 147 | + */ |
|
| 148 | + return array( '@id' => $that->entity_service->get_uri( $reference->get_id() ) ); |
|
| 149 | + }, $value ); |
|
| 150 | 150 | |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $value; |
|
| 154 | - } |
|
| 153 | + return $value; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | private $entity_service; |
| 31 | 31 | |
| 32 | - public function __construct( $entity_type_service, $property_getter ) { |
|
| 32 | + public function __construct($entity_type_service, $property_getter) { |
|
| 33 | 33 | $this->entity_type_service = $entity_type_service; |
| 34 | 34 | $this->property_getter = $property_getter; |
| 35 | 35 | $this->term_entity_type_service = Type_Service::get_instance(); |
@@ -37,26 +37,26 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function init() { |
| 40 | - add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 ); |
|
| 40 | + add_filter('wl_term_jsonld_array', array($this, 'wl_term_jsonld_array'), 10, 2); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function wl_term_jsonld_array( $data, $term_id ) { |
|
| 43 | + public function wl_term_jsonld_array($data, $term_id) { |
|
| 44 | 44 | $jsonld = $data['jsonld']; |
| 45 | 45 | $references = $data['references']; |
| 46 | 46 | |
| 47 | - $term_jsonld_data = $this->get_jsonld_data_for_term( $term_id ); |
|
| 47 | + $term_jsonld_data = $this->get_jsonld_data_for_term($term_id); |
|
| 48 | 48 | |
| 49 | 49 | // Return early if we dont have the entity data |
| 50 | 50 | // for the term. |
| 51 | - if ( ! $term_jsonld_data ) { |
|
| 51 | + if ( ! $term_jsonld_data) { |
|
| 52 | 52 | return $data; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $term_jsonld = $term_jsonld_data['jsonld']; |
| 56 | 56 | |
| 57 | - $references = array_merge( $references, $term_jsonld_data['references'] ); |
|
| 57 | + $references = array_merge($references, $term_jsonld_data['references']); |
|
| 58 | 58 | |
| 59 | - array_unshift( $jsonld, $term_jsonld ); |
|
| 59 | + array_unshift($jsonld, $term_jsonld); |
|
| 60 | 60 | |
| 61 | 61 | return array( |
| 62 | 62 | 'jsonld' => $jsonld, |
@@ -64,89 +64,89 @@ discard block |
||
| 64 | 64 | ); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - private function get_jsonld_data_for_term( $term_id ) { |
|
| 67 | + private function get_jsonld_data_for_term($term_id) { |
|
| 68 | 68 | |
| 69 | - $id = wl_get_term_entity_uri( $term_id ); |
|
| 69 | + $id = wl_get_term_entity_uri($term_id); |
|
| 70 | 70 | |
| 71 | 71 | // If we dont have a dataset URI, then dont publish the term data |
| 72 | 72 | // on this page. |
| 73 | - if ( ! $id ) { |
|
| 73 | + if ( ! $id) { |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $references = array(); |
| 78 | - $term = get_term( $term_id ); |
|
| 79 | - $permalink = get_term_link( $term ); |
|
| 78 | + $term = get_term($term_id); |
|
| 79 | + $permalink = get_term_link($term); |
|
| 80 | 80 | |
| 81 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id ); |
|
| 82 | - $term = get_term( $term_id ); |
|
| 81 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_term($term_id); |
|
| 82 | + $term = get_term($term_id); |
|
| 83 | 83 | $jsonld = array( |
| 84 | 84 | '@context' => 'http://schema.org', |
| 85 | 85 | 'name' => $term->name, |
| 86 | - '@type' => $this->term_entity_type_service->get_entity_types_labels( $term_id ), |
|
| 86 | + '@type' => $this->term_entity_type_service->get_entity_types_labels($term_id), |
|
| 87 | 87 | '@id' => $id, |
| 88 | 88 | 'description' => $term->description, |
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - if ( ! $custom_fields || ! is_array( $custom_fields ) ) { |
|
| 91 | + if ( ! $custom_fields || ! is_array($custom_fields)) { |
|
| 92 | 92 | return $jsonld; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - foreach ( $custom_fields as $key => $value ) { |
|
| 96 | - $name = $this->relative_to_schema_context( $value['predicate'] ); |
|
| 97 | - $value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM ); |
|
| 98 | - $value = $this->process_value( $value, $references ); |
|
| 99 | - if ( ! $value ) { |
|
| 95 | + foreach ($custom_fields as $key => $value) { |
|
| 96 | + $name = $this->relative_to_schema_context($value['predicate']); |
|
| 97 | + $value = $this->property_getter->get($term_id, $key, Object_Type_Enum::TERM); |
|
| 98 | + $value = $this->process_value($value, $references); |
|
| 99 | + if ( ! $value) { |
|
| 100 | 100 | continue; |
| 101 | 101 | } |
| 102 | - $jsonld[ $name ] = $value; |
|
| 102 | + $jsonld[$name] = $value; |
|
| 103 | 103 | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( $permalink ) { |
|
| 106 | + if ($permalink) { |
|
| 107 | 107 | $jsonld['url'] = $permalink; |
| 108 | 108 | $jsonld['mainEntityOfPage'] = $permalink; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return apply_filters( 'wl_no_vocabulary_term_jsonld_array', array( |
|
| 111 | + return apply_filters('wl_no_vocabulary_term_jsonld_array', array( |
|
| 112 | 112 | 'jsonld' => $jsonld, |
| 113 | 113 | 'references' => $references |
| 114 | - ), $term_id ); |
|
| 114 | + ), $term_id); |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
| 120 | - private function relative_to_schema_context( $predicate ) { |
|
| 121 | - return str_replace( 'http://schema.org/', '', $predicate ); |
|
| 120 | + private function relative_to_schema_context($predicate) { |
|
| 121 | + return str_replace('http://schema.org/', '', $predicate); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - private function process_value( $value, &$references ) { |
|
| 124 | + private function process_value($value, &$references) { |
|
| 125 | 125 | |
| 126 | - if ( ! $value ) { |
|
| 126 | + if ( ! $value) { |
|
| 127 | 127 | return false; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if ( is_array( $value ) |
|
| 131 | - && count( $value ) > 0 |
|
| 132 | - && $value[0] instanceof \Wordlift_Property_Entity_Reference ) { |
|
| 130 | + if (is_array($value) |
|
| 131 | + && count($value) > 0 |
|
| 132 | + && $value[0] instanceof \Wordlift_Property_Entity_Reference) { |
|
| 133 | 133 | |
| 134 | 134 | // All of the references from the custom fields are post references. |
| 135 | - $references = array_merge( $references, array_map( function ( $property_entity_reference ) { |
|
| 135 | + $references = array_merge($references, array_map(function($property_entity_reference) { |
|
| 136 | 136 | /** |
| 137 | 137 | * @var $property_entity_reference \Wordlift_Property_Entity_Reference |
| 138 | 138 | */ |
| 139 | - return new Post_Reference( $property_entity_reference->get_id() ); |
|
| 140 | - }, $value ) ); |
|
| 139 | + return new Post_Reference($property_entity_reference->get_id()); |
|
| 140 | + }, $value)); |
|
| 141 | 141 | |
| 142 | 142 | $that = $this; |
| 143 | 143 | |
| 144 | - return array_map( function ( $reference ) use ( $that ) { |
|
| 144 | + return array_map(function($reference) use ($that) { |
|
| 145 | 145 | /** |
| 146 | 146 | * @var $reference \Wordlift_Property_Entity_Reference |
| 147 | 147 | */ |
| 148 | - return array( '@id' => $that->entity_service->get_uri( $reference->get_id() ) ); |
|
| 149 | - }, $value ); |
|
| 148 | + return array('@id' => $that->entity_service->get_uri($reference->get_id())); |
|
| 149 | + }, $value); |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |