@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @since 3.10.0 |
| 48 | 48 | */ |
| 49 | - public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) { |
|
| 50 | - parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() ); |
|
| 49 | + public function __construct($entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false) { |
|
| 50 | + parent::__construct($entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create()); |
|
| 51 | 51 | $this->disable_convert_filters = $disable_convert_filters; |
| 52 | 52 | // Set a reference to the logger. |
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Post_To_Jsonld_Converter'); |
|
| 54 | 54 | |
| 55 | 55 | self::$instance = $this; |
| 56 | 56 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function new_instance_with_filters_disabled() { |
| 65 | - return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true ); |
|
| 65 | + return new static($this->entity_type_service, $this->user_service, $this->attachment_service, true); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -76,30 +76,30 @@ discard block |
||
| 76 | 76 | * @return array A JSON-LD array. |
| 77 | 77 | * @since 3.10.0 |
| 78 | 78 | */ |
| 79 | - public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) { |
|
| 79 | + public function convert($post_id, &$references = array(), &$references_infos = array(), $relations = null) { |
|
| 80 | 80 | |
| 81 | 81 | // Get the post instance. |
| 82 | - $post = get_post( $post_id ); |
|
| 83 | - if ( null === $post ) { |
|
| 82 | + $post = get_post($post_id); |
|
| 83 | + if (null === $post) { |
|
| 84 | 84 | // Post not found. |
| 85 | 85 | return null; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Get the base JSON-LD and the list of entities referenced by this entity. |
| 89 | - $jsonld = parent::convert( $post_id, $references, $references_infos, $relations ); |
|
| 89 | + $jsonld = parent::convert($post_id, $references, $references_infos, $relations); |
|
| 90 | 90 | |
| 91 | 91 | // Set WebPage by default. |
| 92 | - if ( empty( $jsonld['@type'] ) ) { |
|
| 92 | + if (empty($jsonld['@type'])) { |
|
| 93 | 93 | $jsonld['@type'] = 'WebPage'; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Get the entity name. |
| 97 | 97 | $jsonld['headline'] = $post->post_title; |
| 98 | 98 | |
| 99 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id ); |
|
| 99 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_post($post_id); |
|
| 100 | 100 | |
| 101 | - if ( isset( $custom_fields ) ) { |
|
| 102 | - $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos ); |
|
| 101 | + if (isset($custom_fields)) { |
|
| 102 | + $this->process_type_custom_fields($jsonld, $custom_fields, $post, $references, $references_infos); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Set the published and modified dates. |
@@ -112,19 +112,19 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | try { |
| 114 | 114 | $default_timezone = date_default_timezone_get(); |
| 115 | - $timezone = get_option( 'timezone_string' ); |
|
| 116 | - if ( ! empty( $timezone ) ) { |
|
| 117 | - date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 118 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
| 119 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
| 120 | - date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 115 | + $timezone = get_option('timezone_string'); |
|
| 116 | + if ( ! empty($timezone)) { |
|
| 117 | + date_default_timezone_set($timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 118 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i:sP', false, $post); |
|
| 119 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i:sP', false, $post); |
|
| 120 | + date_default_timezone_set($default_timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 121 | 121 | } else { |
| 122 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 123 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 122 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false); |
|
| 123 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i', true, $post, false); |
|
| 124 | 124 | } |
| 125 | - } catch ( Exception $e ) { |
|
| 126 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 127 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 125 | + } catch (Exception $e) { |
|
| 126 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false); |
|
| 127 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i', true, $post, false); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Get the word count for the post. |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @since 3.20.0 |
| 137 | 137 | */ |
| 138 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
| 139 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
| 138 | + if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) { |
|
| 139 | + $post_adapter = new Wordlift_Post_Adapter($post_id); |
|
| 140 | 140 | $jsonld['wordCount'] = $post_adapter->word_count(); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @since 3.27.2 |
| 149 | 149 | */ |
| 150 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
| 151 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
| 150 | + if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) { |
|
| 151 | + $post_adapter = new Wordlift_Post_Adapter($post_id); |
|
| 152 | 152 | $keywords = $post_adapter->keywords(); |
| 153 | 153 | $article_section = $post_adapter->article_section(); |
| 154 | 154 | $comment_count = $post_adapter->comment_count(); |
| 155 | 155 | $locale = $post_adapter->locale(); |
| 156 | 156 | |
| 157 | - if ( isset( $keywords ) ) { |
|
| 157 | + if (isset($keywords)) { |
|
| 158 | 158 | $jsonld['keywords'] = $keywords; |
| 159 | 159 | } |
| 160 | - if ( ! empty( $article_section ) ) { |
|
| 160 | + if ( ! empty($article_section)) { |
|
| 161 | 161 | $jsonld['articleSection'] = $article_section; |
| 162 | 162 | } |
| 163 | 163 | $jsonld['commentCount'] = $comment_count; |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Set the publisher. |
| 168 | - $this->set_publisher( $jsonld ); |
|
| 168 | + $this->set_publisher($jsonld); |
|
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | 171 | * Call the `wl_post_jsonld_author` filter. |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $ret_val = apply_filters( |
| 189 | 189 | 'wl_jsonld_author', |
| 190 | 190 | array( |
| 191 | - 'author' => $this->get_author( $post->post_author, $references ), |
|
| 191 | + 'author' => $this->get_author($post->post_author, $references), |
|
| 192 | 192 | 'references' => $references, |
| 193 | 193 | ), |
| 194 | 194 | $post_id |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | $references = $ret_val['references']; |
| 200 | 200 | |
| 201 | 201 | // Return the JSON-LD if filters are disabled by the client. |
| 202 | - if ( $this->disable_convert_filters ) { |
|
| 202 | + if ($this->disable_convert_filters) { |
|
| 203 | 203 | return $jsonld; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @api |
| 246 | 246 | */ |
| 247 | - return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references ); |
|
| 247 | + return apply_filters('wl_post_jsonld', $jsonld, $post_id, $references); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -259,18 +259,18 @@ discard block |
||
| 259 | 259 | * @return string|array A JSON-LD structure. |
| 260 | 260 | * @since 3.14.0 |
| 261 | 261 | */ |
| 262 | - public function get_author( $author_id, &$references ) { |
|
| 262 | + public function get_author($author_id, &$references) { |
|
| 263 | 263 | |
| 264 | 264 | // Get the entity bound to this user. |
| 265 | - $entity_id = $this->user_service->get_entity( $author_id ); |
|
| 265 | + $entity_id = $this->user_service->get_entity($author_id); |
|
| 266 | 266 | |
| 267 | 267 | // If there's no entity bound return a simple author structure. |
| 268 | - if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) { |
|
| 268 | + if (empty($entity_id) || 'publish' !== get_post_status($entity_id)) { |
|
| 269 | 269 | |
| 270 | - $author = get_the_author_meta( 'display_name', $author_id ); |
|
| 271 | - $author_first_name = get_the_author_meta( 'first_name', $author_id ); |
|
| 272 | - $author_last_name = get_the_author_meta( 'last_name', $author_id ); |
|
| 273 | - $author_uri = $this->user_service->get_uri( $author_id ); |
|
| 270 | + $author = get_the_author_meta('display_name', $author_id); |
|
| 271 | + $author_first_name = get_the_author_meta('first_name', $author_id); |
|
| 272 | + $author_last_name = get_the_author_meta('last_name', $author_id); |
|
| 273 | + $author_uri = $this->user_service->get_uri($author_id); |
|
| 274 | 274 | |
| 275 | 275 | return array( |
| 276 | 276 | '@type' => 'Person', |
@@ -278,12 +278,12 @@ discard block |
||
| 278 | 278 | 'name' => $author, |
| 279 | 279 | 'givenName' => $author_first_name, |
| 280 | 280 | 'familyName' => $author_last_name, |
| 281 | - 'url' => get_author_posts_url( $author_id ), |
|
| 281 | + 'url' => get_author_posts_url($author_id), |
|
| 282 | 282 | ); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // Add the author to the references. |
| 286 | - $author_uri = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id ); |
|
| 286 | + $author_uri = Wordlift_Entity_Service::get_instance()->get_uri($entity_id); |
|
| 287 | 287 | $references[] = $entity_id; |
| 288 | 288 | |
| 289 | 289 | // Return the JSON-LD for the referenced entity. |
@@ -299,41 +299,41 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @since 3.10.0 |
| 301 | 301 | */ |
| 302 | - protected function set_publisher( &$params ) { |
|
| 302 | + protected function set_publisher(&$params) { |
|
| 303 | 303 | |
| 304 | 304 | // If the publisher id isn't set don't do anything. |
| 305 | 305 | $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id(); |
| 306 | - if ( empty( $publisher_id ) ) { |
|
| 306 | + if (empty($publisher_id)) { |
|
| 307 | 307 | return; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Get the post instance. |
| 311 | - $post = get_post( $publisher_id ); |
|
| 312 | - if ( ! is_a( $post, '\WP_Post' ) ) { |
|
| 311 | + $post = get_post($publisher_id); |
|
| 312 | + if ( ! is_a($post, '\WP_Post')) { |
|
| 313 | 313 | // Publisher not found. |
| 314 | 314 | return; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // Get the item id. |
| 318 | - $id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id ); |
|
| 318 | + $id = Wordlift_Entity_Service::get_instance()->get_uri($publisher_id); |
|
| 319 | 319 | |
| 320 | 320 | // Get the type. |
| 321 | - $type = $this->entity_type_service->get( $publisher_id ); |
|
| 321 | + $type = $this->entity_type_service->get($publisher_id); |
|
| 322 | 322 | |
| 323 | 323 | // Get the name. |
| 324 | 324 | $name = $post->post_title; |
| 325 | 325 | |
| 326 | 326 | // Set the publisher data. |
| 327 | 327 | $params['publisher'] = array( |
| 328 | - '@type' => $this->relative_to_context( $type['uri'] ), |
|
| 328 | + '@type' => $this->relative_to_context($type['uri']), |
|
| 329 | 329 | '@id' => $id, |
| 330 | 330 | 'name' => $name, |
| 331 | 331 | ); |
| 332 | 332 | |
| 333 | 333 | // Add the sameAs values associated with the publisher. |
| 334 | 334 | $storage_factory = Wordlift_Storage_Factory::get_instance(); |
| 335 | - $sameas = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id ); |
|
| 336 | - if ( ! empty( $sameas ) ) { |
|
| 335 | + $sameas = $storage_factory->post_meta(Wordlift_Schema_Service::FIELD_SAME_AS)->get($publisher_id); |
|
| 336 | + if ( ! empty($sameas)) { |
|
| 337 | 337 | $params['publisher']['sameAs'] = $sameas; |
| 338 | 338 | } |
| 339 | 339 | |
@@ -341,15 +341,15 @@ discard block |
||
| 341 | 341 | // support the logo property. |
| 342 | 342 | // |
| 343 | 343 | // See http://schema.org/logo. |
| 344 | - if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) { |
|
| 344 | + if (1 !== preg_match('~Organization$~', $type['uri'])) { |
|
| 345 | 345 | return; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // Get the publisher logo. |
| 349 | - $publisher_logo = $this->get_publisher_logo( $post->ID ); |
|
| 349 | + $publisher_logo = $this->get_publisher_logo($post->ID); |
|
| 350 | 350 | |
| 351 | 351 | // Bail out if the publisher logo isn't set. |
| 352 | - if ( false === $publisher_logo ) { |
|
| 352 | + if (false === $publisher_logo) { |
|
| 353 | 353 | return; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -383,14 +383,14 @@ discard block |
||
| 383 | 383 | * @since 3.19.2 |
| 384 | 384 | * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue. |
| 385 | 385 | */ |
| 386 | - private function get_publisher_logo( $post_id ) { |
|
| 386 | + private function get_publisher_logo($post_id) { |
|
| 387 | 387 | |
| 388 | 388 | // Get the featured image for the post. |
| 389 | - $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
| 389 | + $thumbnail_id = get_post_thumbnail_id($post_id); |
|
| 390 | 390 | |
| 391 | 391 | // Bail out if thumbnail not available. |
| 392 | - if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) { |
|
| 393 | - $this->log->info( "Featured image not set for post $post_id." ); |
|
| 392 | + if (empty($thumbnail_id) || 0 === $thumbnail_id) { |
|
| 393 | + $this->log->info("Featured image not set for post $post_id."); |
|
| 394 | 394 | |
| 395 | 395 | return false; |
| 396 | 396 | } |
@@ -399,24 +399,24 @@ discard block |
||
| 399 | 399 | $uploads_dir = wp_upload_dir(); |
| 400 | 400 | |
| 401 | 401 | // Get the attachment metadata. |
| 402 | - $metadata = wp_get_attachment_metadata( $thumbnail_id ); |
|
| 402 | + $metadata = wp_get_attachment_metadata($thumbnail_id); |
|
| 403 | 403 | |
| 404 | 404 | // Bail out if the file isn't set. |
| 405 | - if ( ! isset( $metadata['file'] ) ) { |
|
| 406 | - $this->log->warn( "Featured image file not found for post $post_id." ); |
|
| 405 | + if ( ! isset($metadata['file'])) { |
|
| 406 | + $this->log->warn("Featured image file not found for post $post_id."); |
|
| 407 | 407 | |
| 408 | 408 | return false; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // Retrieve the relative filename, e.g. "2018/05/logo_publisher.png" |
| 412 | - $path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file']; |
|
| 412 | + $path = $uploads_dir['basedir'].DIRECTORY_SEPARATOR.$metadata['file']; |
|
| 413 | 413 | |
| 414 | 414 | // Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149 |
| 415 | - if ( ! file_exists( $path ) ) { |
|
| 416 | - $this->log->warn( "Featured image file $path doesn't exist for post $post_id." ); |
|
| 415 | + if ( ! file_exists($path)) { |
|
| 416 | + $this->log->warn("Featured image file $path doesn't exist for post $post_id."); |
|
| 417 | 417 | |
| 418 | - $attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' ); |
|
| 419 | - if ( $attachment_image_src ) { |
|
| 418 | + $attachment_image_src = wp_get_attachment_image_src($thumbnail_id, ''); |
|
| 419 | + if ($attachment_image_src) { |
|
| 420 | 420 | return array( |
| 421 | 421 | 'url' => $attachment_image_src[0], |
| 422 | 422 | 'width' => $attachment_image_src[1], |
@@ -430,27 +430,27 @@ discard block |
||
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | // Try to get the image editor and bail out if the editor cannot be instantiated. |
| 433 | - $original_file_editor = wp_get_image_editor( $path ); |
|
| 434 | - if ( is_wp_error( $original_file_editor ) ) { |
|
| 435 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." ); |
|
| 433 | + $original_file_editor = wp_get_image_editor($path); |
|
| 434 | + if (is_wp_error($original_file_editor)) { |
|
| 435 | + $this->log->warn("Cannot instantiate WP Image Editor on file $path for post $post_id."); |
|
| 436 | 436 | |
| 437 | 437 | return false; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | // Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling |
| 441 | 441 | // and we don't actually know the end values. |
| 442 | - $publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' ); |
|
| 442 | + $publisher_logo_path = $original_file_editor->generate_filename('-publisher-logo'); |
|
| 443 | 443 | |
| 444 | 444 | // If the file doesn't exist yet, create it. |
| 445 | - if ( ! file_exists( $publisher_logo_path ) ) { |
|
| 446 | - $original_file_editor->resize( 600, 60 ); |
|
| 447 | - $original_file_editor->save( $publisher_logo_path ); |
|
| 445 | + if ( ! file_exists($publisher_logo_path)) { |
|
| 446 | + $original_file_editor->resize(600, 60); |
|
| 447 | + $original_file_editor->save($publisher_logo_path); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Try to get the image editor and bail out if the editor cannot be instantiated. |
| 451 | - $publisher_logo_editor = wp_get_image_editor( $publisher_logo_path ); |
|
| 452 | - if ( is_wp_error( $publisher_logo_editor ) ) { |
|
| 453 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." ); |
|
| 451 | + $publisher_logo_editor = wp_get_image_editor($publisher_logo_path); |
|
| 452 | + if (is_wp_error($publisher_logo_editor)) { |
|
| 453 | + $this->log->warn("Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id."); |
|
| 454 | 454 | |
| 455 | 455 | return false; |
| 456 | 456 | } |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | |
| 461 | 461 | // Finally return the array with data. |
| 462 | 462 | return array( |
| 463 | - 'url' => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ), |
|
| 463 | + 'url' => $uploads_dir['baseurl'].substr($publisher_logo_path, strlen($uploads_dir['basedir'])), |
|
| 464 | 464 | 'width' => $size['width'], |
| 465 | 465 | 'height' => $size['height'], |
| 466 | 466 | ); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter |
| 49 | 49 | * @param $cached_postid_to_jsonld_converter |
| 50 | 50 | */ |
| 51 | - public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) { |
|
| 51 | + public function __construct($post_to_jsonld_converter, $cached_postid_to_jsonld_converter) { |
|
| 52 | 52 | |
| 53 | 53 | $this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled(); |
| 54 | 54 | |
@@ -67,16 +67,16 @@ discard block |
||
| 67 | 67 | $this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance(); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function after_get_jsonld( $jsonld, $post_id, $context ) { |
|
| 70 | + public function after_get_jsonld($jsonld, $post_id, $context) { |
|
| 71 | 71 | |
| 72 | 72 | // Invalid data structure |
| 73 | - if ( ! is_array( $jsonld ) || ! isset( $jsonld[0] ) || ! is_array( $jsonld[0] ) ) { |
|
| 73 | + if ( ! is_array($jsonld) || ! isset($jsonld[0]) || ! is_array($jsonld[0])) { |
|
| 74 | 74 | return $jsonld; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ( Jsonld_Context_Enum::PAGE !== $context |
|
| 77 | + if (Jsonld_Context_Enum::PAGE !== $context |
|
| 78 | 78 | // Returns true for "1", "true", "on" and "yes". Returns false otherwise. |
| 79 | - && ! filter_input( INPUT_GET, 'article_wrapper', FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 79 | + && ! filter_input(INPUT_GET, 'article_wrapper', FILTER_VALIDATE_BOOLEAN)) { |
|
| 80 | 80 | return $jsonld; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be |
| 87 | 87 | // in the schema.org context, i.e. `Article`, not `http://schema.org/Article`. |
| 88 | - if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) { |
|
| 88 | + if ( ! isset($post_jsonld['@id']) || ! isset($post_jsonld['@type']) || $this->is_article($post_jsonld['@type'])) { |
|
| 89 | 89 | return $jsonld; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -93,24 +93,24 @@ discard block |
||
| 93 | 93 | $reference_infos = array(); |
| 94 | 94 | |
| 95 | 95 | // Convert the post as Article. |
| 96 | - $article_jsonld = $this->post_to_jsonld_converter->convert( $post_id, $references, $reference_infos, new Relations() ); |
|
| 96 | + $article_jsonld = $this->post_to_jsonld_converter->convert($post_id, $references, $reference_infos, new Relations()); |
|
| 97 | 97 | |
| 98 | - $article_jsonld['@id'] = $post_jsonld['@id'] . '#article'; |
|
| 98 | + $article_jsonld['@id'] = $post_jsonld['@id'].'#article'; |
|
| 99 | 99 | // Reset the type, since by default the type assigned via the Entity Type taxonomy is used. |
| 100 | 100 | $article_jsonld['@type'] = 'Article'; |
| 101 | - $article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] ); |
|
| 101 | + $article_jsonld['about'] = array('@id' => $post_jsonld['@id']); |
|
| 102 | 102 | |
| 103 | 103 | // Copy over the URLs. |
| 104 | - if ( isset( $post_jsonld['url'] ) ) { |
|
| 104 | + if (isset($post_jsonld['url'])) { |
|
| 105 | 105 | $article_jsonld['url'] = $post_jsonld['url']; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - array_unshift( $jsonld, $article_jsonld ); |
|
| 108 | + array_unshift($jsonld, $article_jsonld); |
|
| 109 | 109 | |
| 110 | - $author_jsonld = $this->get_author_linked_entity( $article_jsonld ); |
|
| 110 | + $author_jsonld = $this->get_author_linked_entity($article_jsonld); |
|
| 111 | 111 | |
| 112 | 112 | // Get primary author in case co-authors exist. |
| 113 | - $primary_author = $this->get_primary_author( $article_jsonld['author'] ); |
|
| 113 | + $primary_author = $this->get_primary_author($article_jsonld['author']); |
|
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * The author entities can be present in graph for some entity types |
@@ -118,18 +118,18 @@ discard block |
||
| 118 | 118 | * reference : https://schema.org/author |
| 119 | 119 | */ |
| 120 | 120 | |
| 121 | - if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $primary_author['@id'] ) ) { |
|
| 121 | + if ($author_jsonld && ! $this->is_author_entity_present_in_graph($jsonld, $primary_author['@id'])) { |
|
| 122 | 122 | $jsonld[] = $author_jsonld; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | return $jsonld; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - private function is_article( $schema_types ) { |
|
| 128 | + private function is_article($schema_types) { |
|
| 129 | 129 | |
| 130 | - $array_intersect = array_intersect( self::$article_types, (array) $schema_types ); |
|
| 130 | + $array_intersect = array_intersect(self::$article_types, (array) $schema_types); |
|
| 131 | 131 | |
| 132 | - return ! empty( $array_intersect ); |
|
| 132 | + return ! empty($array_intersect); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -143,32 +143,32 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @since 3.51.4 |
| 145 | 145 | */ |
| 146 | - private function get_primary_author( $author ) { |
|
| 146 | + private function get_primary_author($author) { |
|
| 147 | 147 | |
| 148 | 148 | // Nested array of co-authors. Return the primary author. |
| 149 | - if ( is_array( $author ) && ! empty( $author ) && ! isset( $author['@id'] ) ) { |
|
| 149 | + if (is_array($author) && ! empty($author) && ! isset($author['@id'])) { |
|
| 150 | 150 | return $author[0]; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | return $author; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - private function get_author_linked_entity( $article_jsonld ) { |
|
| 157 | - if ( ! array_key_exists( 'author', $article_jsonld ) ) { |
|
| 156 | + private function get_author_linked_entity($article_jsonld) { |
|
| 157 | + if ( ! array_key_exists('author', $article_jsonld)) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $author = $this->get_primary_author( $article_jsonld['author'] ); |
|
| 161 | + $author = $this->get_primary_author($article_jsonld['author']); |
|
| 162 | 162 | |
| 163 | - if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) { |
|
| 163 | + if (count(array_keys($author)) !== 1 || ! array_key_exists('@id', $author)) { |
|
| 164 | 164 | return false; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $author_linked_entity_id = $author['@id']; |
| 168 | 168 | |
| 169 | - $author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id ); |
|
| 169 | + $author_entity_post = $this->entity_uri_service->get_entity($author_linked_entity_id); |
|
| 170 | 170 | |
| 171 | - if ( ! $author_entity_post instanceof \WP_Post ) { |
|
| 171 | + if ( ! $author_entity_post instanceof \WP_Post) { |
|
| 172 | 172 | return false; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) { |
|
| 187 | + private function is_author_entity_present_in_graph($jsonld, $author_entity_id) { |
|
| 188 | 188 | |
| 189 | - foreach ( $jsonld as $item ) { |
|
| 190 | - if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) { |
|
| 189 | + foreach ($jsonld as $item) { |
|
| 190 | + if ($item && array_key_exists('@id', $item) && $item['@id'] === $author_entity_id) { |
|
| 191 | 191 | return true; |
| 192 | 192 | } |
| 193 | 193 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/ |
| 20 | 20 | */ |
| 21 | -function _wl_jsonld_author__author_filter( $args_arr, $post_id ) { |
|
| 21 | +function _wl_jsonld_author__author_filter($args_arr, $post_id) { |
|
| 22 | 22 | |
| 23 | 23 | $author = $args_arr['author']; |
| 24 | 24 | $references = $args_arr['references']; |
@@ -26,19 +26,19 @@ discard block |
||
| 26 | 26 | $coauthor_plugin_path = 'co-authors-plus/co-authors-plus.php'; |
| 27 | 27 | |
| 28 | 28 | // If the co-authors plugin is active. |
| 29 | - if ( is_plugin_active( $coauthor_plugin_path ) && function_exists( 'get_coauthors' ) ) { |
|
| 29 | + if (is_plugin_active($coauthor_plugin_path) && function_exists('get_coauthors')) { |
|
| 30 | 30 | |
| 31 | - $coauthors = get_coauthors( $post_id ); |
|
| 31 | + $coauthors = get_coauthors($post_id); |
|
| 32 | 32 | |
| 33 | 33 | // And we have multiple authors on a post. |
| 34 | - if ( count( $coauthors ) > 1 ) { |
|
| 34 | + if (count($coauthors) > 1) { |
|
| 35 | 35 | |
| 36 | 36 | // Clear the existing author. |
| 37 | 37 | $author = array(); |
| 38 | 38 | |
| 39 | 39 | // Build array of authors. |
| 40 | - foreach ( $coauthors as $coauthor ) { |
|
| 41 | - $author[] = Wordlift_Post_To_Jsonld_Converter::get_instance()->get_author( $coauthor->ID, $references ); |
|
| 40 | + foreach ($coauthors as $coauthor) { |
|
| 41 | + $author[] = Wordlift_Post_To_Jsonld_Converter::get_instance()->get_author($coauthor->ID, $references); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -50,4 +50,4 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Add the filter |
| 53 | -add_filter( 'wl_jsonld_author', '_wl_jsonld_author__author_filter', 10, 2 ); |
|
| 53 | +add_filter('wl_jsonld_author', '_wl_jsonld_author__author_filter', 10, 2); |
|