@@ -25,345 +25,345 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | abstract class Wordlift_Abstract_Post_To_Jsonld_Converter implements Wordlift_Post_Converter { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The JSON-LD context. |
|
| 30 | - * |
|
| 31 | - * @since 3.10.0 |
|
| 32 | - */ |
|
| 33 | - const CONTEXT = 'http://schema.org'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 37 | - * |
|
| 38 | - * @since 3.10.0 |
|
| 39 | - * @access protected |
|
| 40 | - * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 41 | - */ |
|
| 42 | - protected $entity_type_service; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * A {@link Wordlift_Entity_Service} instance. |
|
| 46 | - * |
|
| 47 | - * @since 3.10.0 |
|
| 48 | - * @access protected |
|
| 49 | - * @var \Wordlift_Entity_Service $entity_type_service A {@link Wordlift_Entity_Service} instance. |
|
| 50 | - */ |
|
| 51 | - protected $entity_service; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * A {@link Wordlift_User_Service} instance. |
|
| 55 | - * |
|
| 56 | - * @since 3.10.0 |
|
| 57 | - * @access private |
|
| 58 | - * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 59 | - */ |
|
| 60 | - protected $user_service; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * A {@link Wordlift_Attachment_Service} instance. |
|
| 64 | - * |
|
| 65 | - * @since 3.10.0 |
|
| 66 | - * @access private |
|
| 67 | - * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 68 | - */ |
|
| 69 | - protected $attachment_service; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Wordlift_Post_To_Jsonld_Converter constructor. |
|
| 73 | - * |
|
| 74 | - * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 75 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 76 | - * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 77 | - * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 78 | - * |
|
| 79 | - * @since 3.10.0 |
|
| 80 | - * |
|
| 81 | - */ |
|
| 82 | - public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service ) { |
|
| 83 | - |
|
| 84 | - $this->entity_type_service = $entity_type_service; |
|
| 85 | - $this->entity_service = $entity_service; |
|
| 86 | - $this->user_service = $user_service; |
|
| 87 | - $this->attachment_service = $attachment_service; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 92 | - * found while processing the post is set in the $references array. |
|
| 93 | - * |
|
| 94 | - * @param int $post_id The post id. |
|
| 95 | - * @param array $references An array of entity references. |
|
| 96 | - * @param array $references_infos |
|
| 97 | - * |
|
| 98 | - * @return array A JSON-LD array. |
|
| 99 | - * @since 3.10.0 |
|
| 100 | - */ |
|
| 101 | - public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
| 102 | - |
|
| 103 | - // Get the post instance. |
|
| 104 | - $post = get_post( $post_id ); |
|
| 105 | - if ( null === $post ) { |
|
| 106 | - // Post not found. |
|
| 107 | - return null; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Get the post URI @id. |
|
| 111 | - $id = $this->entity_service->get_uri( $post->ID ); |
|
| 112 | - if ( is_null( $id ) ) { |
|
| 113 | - $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /* |
|
| 28 | + /** |
|
| 29 | + * The JSON-LD context. |
|
| 30 | + * |
|
| 31 | + * @since 3.10.0 |
|
| 32 | + */ |
|
| 33 | + const CONTEXT = 'http://schema.org'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 37 | + * |
|
| 38 | + * @since 3.10.0 |
|
| 39 | + * @access protected |
|
| 40 | + * @var \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 41 | + */ |
|
| 42 | + protected $entity_type_service; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * A {@link Wordlift_Entity_Service} instance. |
|
| 46 | + * |
|
| 47 | + * @since 3.10.0 |
|
| 48 | + * @access protected |
|
| 49 | + * @var \Wordlift_Entity_Service $entity_type_service A {@link Wordlift_Entity_Service} instance. |
|
| 50 | + */ |
|
| 51 | + protected $entity_service; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * A {@link Wordlift_User_Service} instance. |
|
| 55 | + * |
|
| 56 | + * @since 3.10.0 |
|
| 57 | + * @access private |
|
| 58 | + * @var \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 59 | + */ |
|
| 60 | + protected $user_service; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * A {@link Wordlift_Attachment_Service} instance. |
|
| 64 | + * |
|
| 65 | + * @since 3.10.0 |
|
| 66 | + * @access private |
|
| 67 | + * @var \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 68 | + */ |
|
| 69 | + protected $attachment_service; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Wordlift_Post_To_Jsonld_Converter constructor. |
|
| 73 | + * |
|
| 74 | + * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 75 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 76 | + * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 77 | + * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 78 | + * |
|
| 79 | + * @since 3.10.0 |
|
| 80 | + * |
|
| 81 | + */ |
|
| 82 | + public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service ) { |
|
| 83 | + |
|
| 84 | + $this->entity_type_service = $entity_type_service; |
|
| 85 | + $this->entity_service = $entity_service; |
|
| 86 | + $this->user_service = $user_service; |
|
| 87 | + $this->attachment_service = $attachment_service; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 92 | + * found while processing the post is set in the $references array. |
|
| 93 | + * |
|
| 94 | + * @param int $post_id The post id. |
|
| 95 | + * @param array $references An array of entity references. |
|
| 96 | + * @param array $references_infos |
|
| 97 | + * |
|
| 98 | + * @return array A JSON-LD array. |
|
| 99 | + * @since 3.10.0 |
|
| 100 | + */ |
|
| 101 | + public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
| 102 | + |
|
| 103 | + // Get the post instance. |
|
| 104 | + $post = get_post( $post_id ); |
|
| 105 | + if ( null === $post ) { |
|
| 106 | + // Post not found. |
|
| 107 | + return null; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Get the post URI @id. |
|
| 111 | + $id = $this->entity_service->get_uri( $post->ID ); |
|
| 112 | + if ( is_null( $id ) ) { |
|
| 113 | + $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /* |
|
| 117 | 117 | * The `types` variable holds one or more entity types. The `type` variable isn't used anymore. |
| 118 | 118 | * |
| 119 | 119 | * @since 3.20.0 We support more than one entity type. |
| 120 | 120 | * |
| 121 | 121 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 122 | 122 | */ |
| 123 | - // // Get the entity @type. We consider `post` BlogPostings. |
|
| 124 | - // $type = $this->entity_type_service->get( $post_id ); |
|
| 125 | - $types = $this->entity_type_service->get_names( $post_id ); |
|
| 126 | - $type = self::make_one( $types ); |
|
| 127 | - |
|
| 128 | - // Prepare the response. |
|
| 129 | - $jsonld = array( |
|
| 130 | - '@context' => self::CONTEXT, |
|
| 131 | - '@id' => $id, |
|
| 132 | - '@type' => $type, |
|
| 133 | - 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ), |
|
| 134 | - ); |
|
| 135 | - |
|
| 136 | - // Set the `mainEntityOfPage` property if the post has some contents. |
|
| 137 | - /* |
|
| 123 | + // // Get the entity @type. We consider `post` BlogPostings. |
|
| 124 | + // $type = $this->entity_type_service->get( $post_id ); |
|
| 125 | + $types = $this->entity_type_service->get_names( $post_id ); |
|
| 126 | + $type = self::make_one( $types ); |
|
| 127 | + |
|
| 128 | + // Prepare the response. |
|
| 129 | + $jsonld = array( |
|
| 130 | + '@context' => self::CONTEXT, |
|
| 131 | + '@id' => $id, |
|
| 132 | + '@type' => $type, |
|
| 133 | + 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ), |
|
| 134 | + ); |
|
| 135 | + |
|
| 136 | + // Set the `mainEntityOfPage` property if the post has some contents. |
|
| 137 | + /* |
|
| 138 | 138 | * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g. |
| 139 | 139 | * because the content is written elsewhere. |
| 140 | 140 | * |
| 141 | 141 | * @since 3.20.0 |
| 142 | 142 | */ |
| 143 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
| 144 | - if ( ! empty( $post_content ) ) { |
|
| 145 | - // We're setting the `mainEntityOfPage` to signal which one is the |
|
| 146 | - // main entity for the specified URL. It might be however that the |
|
| 147 | - // post/page is actually about another specific entity. How WL deals |
|
| 148 | - // with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451). |
|
| 149 | - // |
|
| 150 | - // See http://schema.org/mainEntityOfPage |
|
| 151 | - // |
|
| 152 | - // No need to specify `'@type' => 'WebPage'. |
|
| 153 | - // |
|
| 154 | - // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 155 | - $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID ); |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1207 |
|
| 159 | - * |
|
| 160 | - * @since 3.27.7 |
|
| 161 | - */ |
|
| 162 | - if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ) ) ) { |
|
| 163 | - $jsonld['mainEntityOfPage'] = array( |
|
| 164 | - '@type' => 'WebPage', |
|
| 165 | - 'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ) |
|
| 166 | - ); |
|
| 167 | - } |
|
| 168 | - }; |
|
| 169 | - |
|
| 170 | - $this->set_images( $this->attachment_service, $post, $jsonld ); |
|
| 171 | - |
|
| 172 | - // Get the entities referenced by this post and set it to the `references` |
|
| 173 | - // array so that the caller can do further processing, such as printing out |
|
| 174 | - // more of those references. |
|
| 175 | - $references_without_locations = Object_Relation_Service::get_instance() |
|
| 176 | - ->get_references( $post_id, Object_Type_Enum::POST ); |
|
| 177 | - |
|
| 178 | - /* |
|
| 143 | + $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
| 144 | + if ( ! empty( $post_content ) ) { |
|
| 145 | + // We're setting the `mainEntityOfPage` to signal which one is the |
|
| 146 | + // main entity for the specified URL. It might be however that the |
|
| 147 | + // post/page is actually about another specific entity. How WL deals |
|
| 148 | + // with that hasn't been defined yet (see https://github.com/insideout10/wordlift-plugin/issues/451). |
|
| 149 | + // |
|
| 150 | + // See http://schema.org/mainEntityOfPage |
|
| 151 | + // |
|
| 152 | + // No need to specify `'@type' => 'WebPage'. |
|
| 153 | + // |
|
| 154 | + // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 155 | + $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID ); |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1207 |
|
| 159 | + * |
|
| 160 | + * @since 3.27.7 |
|
| 161 | + */ |
|
| 162 | + if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ) ) ) { |
|
| 163 | + $jsonld['mainEntityOfPage'] = array( |
|
| 164 | + '@type' => 'WebPage', |
|
| 165 | + 'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ) |
|
| 166 | + ); |
|
| 167 | + } |
|
| 168 | + }; |
|
| 169 | + |
|
| 170 | + $this->set_images( $this->attachment_service, $post, $jsonld ); |
|
| 171 | + |
|
| 172 | + // Get the entities referenced by this post and set it to the `references` |
|
| 173 | + // array so that the caller can do further processing, such as printing out |
|
| 174 | + // more of those references. |
|
| 175 | + $references_without_locations = Object_Relation_Service::get_instance() |
|
| 176 | + ->get_references( $post_id, Object_Type_Enum::POST ); |
|
| 177 | + |
|
| 178 | + /* |
|
| 179 | 179 | * Add the locations to the references. |
| 180 | 180 | * |
| 181 | 181 | * @since 3.19.5 |
| 182 | 182 | * |
| 183 | 183 | * @see https://github.com/insideout10/wordlift-plugin/issues/858. |
| 184 | 184 | */ |
| 185 | - // A reference to use in closure. |
|
| 186 | - $entity_type_service = $this->entity_type_service; |
|
| 187 | - $locations = array_reduce( $references_without_locations, function ( $carry, $reference ) use ( $entity_type_service ) { |
|
| 188 | - /** |
|
| 189 | - * @var $reference Reference |
|
| 190 | - */ |
|
| 191 | - // @see https://schema.org/location for the schema.org types using the `location` property. |
|
| 192 | - if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' ) |
|
| 193 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' ) |
|
| 194 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) { |
|
| 195 | - |
|
| 196 | - return $carry; |
|
| 197 | - } |
|
| 198 | - $post_location_ids = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION ); |
|
| 199 | - $post_location_references = array_map( function ( $post_id ) { |
|
| 200 | - return new Post_Reference( $post_id ); |
|
| 201 | - }, $post_location_ids ); |
|
| 202 | - |
|
| 203 | - return array_merge( $carry, $post_location_references); |
|
| 204 | - }, array() ); |
|
| 205 | - |
|
| 206 | - // Merge the references with the referenced locations if any. |
|
| 207 | - $references = array_merge( $references_without_locations, $locations ); |
|
| 208 | - |
|
| 209 | - return $jsonld; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * If the provided value starts with the schema.org context, we remove the schema.org |
|
| 214 | - * part since it is set with the '@context'. |
|
| 215 | - * |
|
| 216 | - * @param string $value The property value. |
|
| 217 | - * |
|
| 218 | - * @return string The property value without the context. |
|
| 219 | - * @since 3.10.0 |
|
| 220 | - * |
|
| 221 | - */ |
|
| 222 | - public function relative_to_context( $value ) { |
|
| 223 | - |
|
| 224 | - return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Set the images, by looking for embedded images, for images loaded via the |
|
| 229 | - * gallery and for the featured image. |
|
| 230 | - * |
|
| 231 | - * Uses the cache service to store the results of this function for a day. |
|
| 232 | - * |
|
| 233 | - * @param $attachment_service Wordlift_Attachment_Service |
|
| 234 | - * @param WP_Post $post The target {@link WP_Post}. |
|
| 235 | - * @param array $jsonld The JSON-LD array. |
|
| 236 | - * |
|
| 237 | - * @since 3.10.0 |
|
| 238 | - */ |
|
| 239 | - public static function set_images( $attachment_service, $post, &$jsonld ) { |
|
| 240 | - |
|
| 241 | - // Prepare the attachment ids array. |
|
| 242 | - $ids = array(); |
|
| 243 | - |
|
| 244 | - // Set the thumbnail id as first attachment id, if any. |
|
| 245 | - $thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
| 246 | - if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) { |
|
| 247 | - $ids[] = $thumbnail_id; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // For the time being the following is being removed since the query |
|
| 251 | - // initiated by `get_image_embeds` is consuming lots of CPU. |
|
| 252 | - // |
|
| 253 | - // See https://github.com/insideout10/wordlift-plugin/issues/689. |
|
| 254 | - // |
|
| 255 | - // Get the embeds, removing existing ids. |
|
| 256 | - if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) { |
|
| 257 | - $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids ); |
|
| 258 | - } else { |
|
| 259 | - $embeds = array(); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - // Get the gallery, removing existing ids. |
|
| 263 | - $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds ); |
|
| 264 | - |
|
| 265 | - // Map the attachment ids to images' data structured for schema.org use. |
|
| 266 | - $images_with_sizes = array_filter( |
|
| 267 | - array_reduce( array_merge( $ids, $embeds, $gallery ), |
|
| 268 | - function ( $carry, $item ) { |
|
| 269 | - /* |
|
| 185 | + // A reference to use in closure. |
|
| 186 | + $entity_type_service = $this->entity_type_service; |
|
| 187 | + $locations = array_reduce( $references_without_locations, function ( $carry, $reference ) use ( $entity_type_service ) { |
|
| 188 | + /** |
|
| 189 | + * @var $reference Reference |
|
| 190 | + */ |
|
| 191 | + // @see https://schema.org/location for the schema.org types using the `location` property. |
|
| 192 | + if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' ) |
|
| 193 | + && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' ) |
|
| 194 | + && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) { |
|
| 195 | + |
|
| 196 | + return $carry; |
|
| 197 | + } |
|
| 198 | + $post_location_ids = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION ); |
|
| 199 | + $post_location_references = array_map( function ( $post_id ) { |
|
| 200 | + return new Post_Reference( $post_id ); |
|
| 201 | + }, $post_location_ids ); |
|
| 202 | + |
|
| 203 | + return array_merge( $carry, $post_location_references); |
|
| 204 | + }, array() ); |
|
| 205 | + |
|
| 206 | + // Merge the references with the referenced locations if any. |
|
| 207 | + $references = array_merge( $references_without_locations, $locations ); |
|
| 208 | + |
|
| 209 | + return $jsonld; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * If the provided value starts with the schema.org context, we remove the schema.org |
|
| 214 | + * part since it is set with the '@context'. |
|
| 215 | + * |
|
| 216 | + * @param string $value The property value. |
|
| 217 | + * |
|
| 218 | + * @return string The property value without the context. |
|
| 219 | + * @since 3.10.0 |
|
| 220 | + * |
|
| 221 | + */ |
|
| 222 | + public function relative_to_context( $value ) { |
|
| 223 | + |
|
| 224 | + return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Set the images, by looking for embedded images, for images loaded via the |
|
| 229 | + * gallery and for the featured image. |
|
| 230 | + * |
|
| 231 | + * Uses the cache service to store the results of this function for a day. |
|
| 232 | + * |
|
| 233 | + * @param $attachment_service Wordlift_Attachment_Service |
|
| 234 | + * @param WP_Post $post The target {@link WP_Post}. |
|
| 235 | + * @param array $jsonld The JSON-LD array. |
|
| 236 | + * |
|
| 237 | + * @since 3.10.0 |
|
| 238 | + */ |
|
| 239 | + public static function set_images( $attachment_service, $post, &$jsonld ) { |
|
| 240 | + |
|
| 241 | + // Prepare the attachment ids array. |
|
| 242 | + $ids = array(); |
|
| 243 | + |
|
| 244 | + // Set the thumbnail id as first attachment id, if any. |
|
| 245 | + $thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
| 246 | + if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) { |
|
| 247 | + $ids[] = $thumbnail_id; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // For the time being the following is being removed since the query |
|
| 251 | + // initiated by `get_image_embeds` is consuming lots of CPU. |
|
| 252 | + // |
|
| 253 | + // See https://github.com/insideout10/wordlift-plugin/issues/689. |
|
| 254 | + // |
|
| 255 | + // Get the embeds, removing existing ids. |
|
| 256 | + if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) { |
|
| 257 | + $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids ); |
|
| 258 | + } else { |
|
| 259 | + $embeds = array(); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + // Get the gallery, removing existing ids. |
|
| 263 | + $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds ); |
|
| 264 | + |
|
| 265 | + // Map the attachment ids to images' data structured for schema.org use. |
|
| 266 | + $images_with_sizes = array_filter( |
|
| 267 | + array_reduce( array_merge( $ids, $embeds, $gallery ), |
|
| 268 | + function ( $carry, $item ) { |
|
| 269 | + /* |
|
| 270 | 270 | * @todo: we're not sure that we're getting attachment data here, we |
| 271 | 271 | * should filter `false`s. |
| 272 | 272 | */ |
| 273 | 273 | |
| 274 | - $sources = array_merge( |
|
| 275 | - Wordlift_Image_Service::get_sources( $item ), |
|
| 276 | - array( wp_get_attachment_image_src( $item, 'full' ) ) |
|
| 277 | - ); |
|
| 278 | - |
|
| 279 | - $sources_with_image = array_filter( $sources, function ( $source ) { |
|
| 280 | - return ! empty( $source[0] ); |
|
| 281 | - } ); |
|
| 282 | - |
|
| 283 | - // Get the attachment data. |
|
| 284 | - // $attachment = wp_get_attachment_image_src( $item, 'full' ); |
|
| 285 | - |
|
| 286 | - // var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) ); |
|
| 287 | - |
|
| 288 | - // Bail if image is not found. |
|
| 289 | - // In some cases, you can delete the image from the database |
|
| 290 | - // or from uploads dir, but the image id still exists as featured image |
|
| 291 | - // or in [gallery] shortcode. |
|
| 292 | - // if ( empty( $attachment[0] ) ) { |
|
| 293 | - if ( empty( $sources_with_image ) ) { |
|
| 294 | - return $carry; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Merge the arrays. |
|
| 298 | - return array_merge( |
|
| 299 | - $carry, |
|
| 300 | - $sources_with_image |
|
| 301 | - ); |
|
| 302 | - } |
|
| 303 | - // Initial array. |
|
| 304 | - , array() ) |
|
| 305 | - ); |
|
| 306 | - |
|
| 307 | - // Refactor data as per schema.org specifications. |
|
| 308 | - $images = array_map( function ( $attachment ) { |
|
| 309 | - return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size( |
|
| 310 | - array( |
|
| 311 | - '@type' => 'ImageObject', |
|
| 312 | - 'url' => $attachment[0], |
|
| 313 | - ), $attachment |
|
| 314 | - ); |
|
| 315 | - }, $images_with_sizes ); |
|
| 316 | - |
|
| 317 | - // Add images if present. |
|
| 318 | - if ( 0 < count( $images ) ) { |
|
| 319 | - $jsonld['image'] = $images; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * If the provided array of values contains only one value, then one single |
|
| 326 | - * value is returned, otherwise the original array is returned. |
|
| 327 | - * |
|
| 328 | - * @param array $value An array of values. |
|
| 329 | - * |
|
| 330 | - * @return mixed|array A single value or the original array. |
|
| 331 | - * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to |
|
| 332 | - * {@link Wordlift_Abstract_Post_To_Jsonld_Converter}. |
|
| 333 | - * @since 3.8.0 |
|
| 334 | - * @access private |
|
| 335 | - * |
|
| 336 | - */ |
|
| 337 | - protected static function make_one( $value ) { |
|
| 338 | - |
|
| 339 | - return 1 === count( $value ) ? $value[0] : $value; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Process the provided array by adding the width / height if the values |
|
| 344 | - * are available and are greater than 0. |
|
| 345 | - * |
|
| 346 | - * @param array $image The `ImageObject` array. |
|
| 347 | - * @param array $attachment The attachment array. |
|
| 348 | - * |
|
| 349 | - * @return array The enriched `ImageObject` array. |
|
| 350 | - * @since 3.14.0 |
|
| 351 | - * |
|
| 352 | - */ |
|
| 353 | - public static function set_image_size( $image, $attachment ) { |
|
| 354 | - |
|
| 355 | - // If you specify a "width" or "height" value you should leave out |
|
| 356 | - // 'px'. For example: "width":"4608px" should be "width":"4608". |
|
| 357 | - // |
|
| 358 | - // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 359 | - if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) { |
|
| 360 | - $image['width'] = $attachment[1]; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) { |
|
| 364 | - $image['height'] = $attachment[2]; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return $image; |
|
| 368 | - } |
|
| 274 | + $sources = array_merge( |
|
| 275 | + Wordlift_Image_Service::get_sources( $item ), |
|
| 276 | + array( wp_get_attachment_image_src( $item, 'full' ) ) |
|
| 277 | + ); |
|
| 278 | + |
|
| 279 | + $sources_with_image = array_filter( $sources, function ( $source ) { |
|
| 280 | + return ! empty( $source[0] ); |
|
| 281 | + } ); |
|
| 282 | + |
|
| 283 | + // Get the attachment data. |
|
| 284 | + // $attachment = wp_get_attachment_image_src( $item, 'full' ); |
|
| 285 | + |
|
| 286 | + // var_dump( array( "sources-$item" => Wordlift_Image_Service::get_sources( $item ) ) ); |
|
| 287 | + |
|
| 288 | + // Bail if image is not found. |
|
| 289 | + // In some cases, you can delete the image from the database |
|
| 290 | + // or from uploads dir, but the image id still exists as featured image |
|
| 291 | + // or in [gallery] shortcode. |
|
| 292 | + // if ( empty( $attachment[0] ) ) { |
|
| 293 | + if ( empty( $sources_with_image ) ) { |
|
| 294 | + return $carry; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Merge the arrays. |
|
| 298 | + return array_merge( |
|
| 299 | + $carry, |
|
| 300 | + $sources_with_image |
|
| 301 | + ); |
|
| 302 | + } |
|
| 303 | + // Initial array. |
|
| 304 | + , array() ) |
|
| 305 | + ); |
|
| 306 | + |
|
| 307 | + // Refactor data as per schema.org specifications. |
|
| 308 | + $images = array_map( function ( $attachment ) { |
|
| 309 | + return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size( |
|
| 310 | + array( |
|
| 311 | + '@type' => 'ImageObject', |
|
| 312 | + 'url' => $attachment[0], |
|
| 313 | + ), $attachment |
|
| 314 | + ); |
|
| 315 | + }, $images_with_sizes ); |
|
| 316 | + |
|
| 317 | + // Add images if present. |
|
| 318 | + if ( 0 < count( $images ) ) { |
|
| 319 | + $jsonld['image'] = $images; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * If the provided array of values contains only one value, then one single |
|
| 326 | + * value is returned, otherwise the original array is returned. |
|
| 327 | + * |
|
| 328 | + * @param array $value An array of values. |
|
| 329 | + * |
|
| 330 | + * @return mixed|array A single value or the original array. |
|
| 331 | + * @since 3.20.0 The function has been moved from {@link Wordlift_Entity_Post_To_Jsonld_Converter} to |
|
| 332 | + * {@link Wordlift_Abstract_Post_To_Jsonld_Converter}. |
|
| 333 | + * @since 3.8.0 |
|
| 334 | + * @access private |
|
| 335 | + * |
|
| 336 | + */ |
|
| 337 | + protected static function make_one( $value ) { |
|
| 338 | + |
|
| 339 | + return 1 === count( $value ) ? $value[0] : $value; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Process the provided array by adding the width / height if the values |
|
| 344 | + * are available and are greater than 0. |
|
| 345 | + * |
|
| 346 | + * @param array $image The `ImageObject` array. |
|
| 347 | + * @param array $attachment The attachment array. |
|
| 348 | + * |
|
| 349 | + * @return array The enriched `ImageObject` array. |
|
| 350 | + * @since 3.14.0 |
|
| 351 | + * |
|
| 352 | + */ |
|
| 353 | + public static function set_image_size( $image, $attachment ) { |
|
| 354 | + |
|
| 355 | + // If you specify a "width" or "height" value you should leave out |
|
| 356 | + // 'px'. For example: "width":"4608px" should be "width":"4608". |
|
| 357 | + // |
|
| 358 | + // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
| 359 | + if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) { |
|
| 360 | + $image['width'] = $attachment[1]; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) { |
|
| 364 | + $image['height'] = $attachment[2]; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return $image; |
|
| 368 | + } |
|
| 369 | 369 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @since 3.10.0 |
| 80 | 80 | * |
| 81 | 81 | */ |
| 82 | - public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service ) { |
|
| 82 | + public function __construct($entity_type_service, $entity_service, $user_service, $attachment_service) { |
|
| 83 | 83 | |
| 84 | 84 | $this->entity_type_service = $entity_type_service; |
| 85 | 85 | $this->entity_service = $entity_service; |
@@ -98,19 +98,19 @@ discard block |
||
| 98 | 98 | * @return array A JSON-LD array. |
| 99 | 99 | * @since 3.10.0 |
| 100 | 100 | */ |
| 101 | - public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
| 101 | + public function convert($post_id, &$references = array(), &$references_infos = array()) { |
|
| 102 | 102 | |
| 103 | 103 | // Get the post instance. |
| 104 | - $post = get_post( $post_id ); |
|
| 105 | - if ( null === $post ) { |
|
| 104 | + $post = get_post($post_id); |
|
| 105 | + if (null === $post) { |
|
| 106 | 106 | // Post not found. |
| 107 | 107 | return null; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Get the post URI @id. |
| 111 | - $id = $this->entity_service->get_uri( $post->ID ); |
|
| 112 | - if ( is_null( $id ) ) { |
|
| 113 | - $id = 'get_uri returned null, dataset is ' . wl_configuration_get_redlink_dataset_uri(); |
|
| 111 | + $id = $this->entity_service->get_uri($post->ID); |
|
| 112 | + if (is_null($id)) { |
|
| 113 | + $id = 'get_uri returned null, dataset is '.wl_configuration_get_redlink_dataset_uri(); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /* |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | // // Get the entity @type. We consider `post` BlogPostings. |
| 124 | 124 | // $type = $this->entity_type_service->get( $post_id ); |
| 125 | - $types = $this->entity_type_service->get_names( $post_id ); |
|
| 126 | - $type = self::make_one( $types ); |
|
| 125 | + $types = $this->entity_type_service->get_names($post_id); |
|
| 126 | + $type = self::make_one($types); |
|
| 127 | 127 | |
| 128 | 128 | // Prepare the response. |
| 129 | 129 | $jsonld = array( |
| 130 | 130 | '@context' => self::CONTEXT, |
| 131 | 131 | '@id' => $id, |
| 132 | 132 | '@type' => $type, |
| 133 | - 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ), |
|
| 133 | + 'description' => Wordlift_Post_Excerpt_Helper::get_text_excerpt($post), |
|
| 134 | 134 | ); |
| 135 | 135 | |
| 136 | 136 | // Set the `mainEntityOfPage` property if the post has some contents. |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @since 3.20.0 |
| 142 | 142 | */ |
| 143 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
| 144 | - if ( ! empty( $post_content ) ) { |
|
| 143 | + $post_content = apply_filters('wl_post_content', $post->post_content, $post); |
|
| 144 | + if ( ! empty($post_content)) { |
|
| 145 | 145 | // We're setting the `mainEntityOfPage` to signal which one is the |
| 146 | 146 | // main entity for the specified URL. It might be however that the |
| 147 | 147 | // post/page is actually about another specific entity. How WL deals |
@@ -152,28 +152,28 @@ discard block |
||
| 152 | 152 | // No need to specify `'@type' => 'WebPage'. |
| 153 | 153 | // |
| 154 | 154 | // See https://github.com/insideout10/wordlift-plugin/issues/451. |
| 155 | - $jsonld['mainEntityOfPage'] = get_the_permalink( $post->ID ); |
|
| 155 | + $jsonld['mainEntityOfPage'] = get_the_permalink($post->ID); |
|
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | 158 | * @see https://github.com/insideout10/wordlift-plugin/issues/1207 |
| 159 | 159 | * |
| 160 | 160 | * @since 3.27.7 |
| 161 | 161 | */ |
| 162 | - if ( in_array( $type, array( 'Occupation', 'OccupationAggregationByEmployer' ) ) ) { |
|
| 162 | + if (in_array($type, array('Occupation', 'OccupationAggregationByEmployer'))) { |
|
| 163 | 163 | $jsonld['mainEntityOfPage'] = array( |
| 164 | 164 | '@type' => 'WebPage', |
| 165 | - 'lastReviewed' => get_post_time( 'Y-m-d\TH:i:sP', true, $post, false ) |
|
| 165 | + 'lastReviewed' => get_post_time('Y-m-d\TH:i:sP', true, $post, false) |
|
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | }; |
| 169 | 169 | |
| 170 | - $this->set_images( $this->attachment_service, $post, $jsonld ); |
|
| 170 | + $this->set_images($this->attachment_service, $post, $jsonld); |
|
| 171 | 171 | |
| 172 | 172 | // Get the entities referenced by this post and set it to the `references` |
| 173 | 173 | // array so that the caller can do further processing, such as printing out |
| 174 | 174 | // more of those references. |
| 175 | 175 | $references_without_locations = Object_Relation_Service::get_instance() |
| 176 | - ->get_references( $post_id, Object_Type_Enum::POST ); |
|
| 176 | + ->get_references($post_id, Object_Type_Enum::POST); |
|
| 177 | 177 | |
| 178 | 178 | /* |
| 179 | 179 | * Add the locations to the references. |
@@ -184,27 +184,27 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | // A reference to use in closure. |
| 186 | 186 | $entity_type_service = $this->entity_type_service; |
| 187 | - $locations = array_reduce( $references_without_locations, function ( $carry, $reference ) use ( $entity_type_service ) { |
|
| 187 | + $locations = array_reduce($references_without_locations, function($carry, $reference) use ($entity_type_service) { |
|
| 188 | 188 | /** |
| 189 | 189 | * @var $reference Reference |
| 190 | 190 | */ |
| 191 | 191 | // @see https://schema.org/location for the schema.org types using the `location` property. |
| 192 | - if ( ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Action' ) |
|
| 193 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Event' ) |
|
| 194 | - && ! $entity_type_service->has_entity_type( $reference->get_id(), 'http://schema.org/Organization' ) ) { |
|
| 192 | + if ( ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Action') |
|
| 193 | + && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Event') |
|
| 194 | + && ! $entity_type_service->has_entity_type($reference->get_id(), 'http://schema.org/Organization')) { |
|
| 195 | 195 | |
| 196 | 196 | return $carry; |
| 197 | 197 | } |
| 198 | - $post_location_ids = get_post_meta( $reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION ); |
|
| 199 | - $post_location_references = array_map( function ( $post_id ) { |
|
| 200 | - return new Post_Reference( $post_id ); |
|
| 201 | - }, $post_location_ids ); |
|
| 198 | + $post_location_ids = get_post_meta($reference->get_id(), Wordlift_Schema_Service::FIELD_LOCATION); |
|
| 199 | + $post_location_references = array_map(function($post_id) { |
|
| 200 | + return new Post_Reference($post_id); |
|
| 201 | + }, $post_location_ids); |
|
| 202 | 202 | |
| 203 | - return array_merge( $carry, $post_location_references); |
|
| 204 | - }, array() ); |
|
| 203 | + return array_merge($carry, $post_location_references); |
|
| 204 | + }, array()); |
|
| 205 | 205 | |
| 206 | 206 | // Merge the references with the referenced locations if any. |
| 207 | - $references = array_merge( $references_without_locations, $locations ); |
|
| 207 | + $references = array_merge($references_without_locations, $locations); |
|
| 208 | 208 | |
| 209 | 209 | return $jsonld; |
| 210 | 210 | } |
@@ -219,9 +219,9 @@ discard block |
||
| 219 | 219 | * @since 3.10.0 |
| 220 | 220 | * |
| 221 | 221 | */ |
| 222 | - public function relative_to_context( $value ) { |
|
| 222 | + public function relative_to_context($value) { |
|
| 223 | 223 | |
| 224 | - return 0 === strpos( $value, self::CONTEXT . '/' ) ? substr( $value, strlen( self::CONTEXT ) + 1 ) : $value; |
|
| 224 | + return 0 === strpos($value, self::CONTEXT.'/') ? substr($value, strlen(self::CONTEXT) + 1) : $value; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @since 3.10.0 |
| 238 | 238 | */ |
| 239 | - public static function set_images( $attachment_service, $post, &$jsonld ) { |
|
| 239 | + public static function set_images($attachment_service, $post, &$jsonld) { |
|
| 240 | 240 | |
| 241 | 241 | // Prepare the attachment ids array. |
| 242 | 242 | $ids = array(); |
| 243 | 243 | |
| 244 | 244 | // Set the thumbnail id as first attachment id, if any. |
| 245 | - $thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
| 246 | - if ( '' !== $thumbnail_id && 0 !== $thumbnail_id ) { |
|
| 245 | + $thumbnail_id = get_post_thumbnail_id($post->ID); |
|
| 246 | + if ('' !== $thumbnail_id && 0 !== $thumbnail_id) { |
|
| 247 | 247 | $ids[] = $thumbnail_id; |
| 248 | 248 | } |
| 249 | 249 | |
@@ -253,31 +253,31 @@ discard block |
||
| 253 | 253 | // See https://github.com/insideout10/wordlift-plugin/issues/689. |
| 254 | 254 | // |
| 255 | 255 | // Get the embeds, removing existing ids. |
| 256 | - if ( apply_filters( 'wl_feature__enable__image-embeds', false ) ) { |
|
| 257 | - $embeds = array_diff( $attachment_service->get_image_embeds( $post->post_content ), $ids ); |
|
| 256 | + if (apply_filters('wl_feature__enable__image-embeds', false)) { |
|
| 257 | + $embeds = array_diff($attachment_service->get_image_embeds($post->post_content), $ids); |
|
| 258 | 258 | } else { |
| 259 | 259 | $embeds = array(); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | // Get the gallery, removing existing ids. |
| 263 | - $gallery = array_diff( $attachment_service->get_gallery( $post ), $ids, $embeds ); |
|
| 263 | + $gallery = array_diff($attachment_service->get_gallery($post), $ids, $embeds); |
|
| 264 | 264 | |
| 265 | 265 | // Map the attachment ids to images' data structured for schema.org use. |
| 266 | 266 | $images_with_sizes = array_filter( |
| 267 | - array_reduce( array_merge( $ids, $embeds, $gallery ), |
|
| 268 | - function ( $carry, $item ) { |
|
| 267 | + array_reduce(array_merge($ids, $embeds, $gallery), |
|
| 268 | + function($carry, $item) { |
|
| 269 | 269 | /* |
| 270 | 270 | * @todo: we're not sure that we're getting attachment data here, we |
| 271 | 271 | * should filter `false`s. |
| 272 | 272 | */ |
| 273 | 273 | |
| 274 | 274 | $sources = array_merge( |
| 275 | - Wordlift_Image_Service::get_sources( $item ), |
|
| 276 | - array( wp_get_attachment_image_src( $item, 'full' ) ) |
|
| 275 | + Wordlift_Image_Service::get_sources($item), |
|
| 276 | + array(wp_get_attachment_image_src($item, 'full')) |
|
| 277 | 277 | ); |
| 278 | 278 | |
| 279 | - $sources_with_image = array_filter( $sources, function ( $source ) { |
|
| 280 | - return ! empty( $source[0] ); |
|
| 279 | + $sources_with_image = array_filter($sources, function($source) { |
|
| 280 | + return ! empty($source[0]); |
|
| 281 | 281 | } ); |
| 282 | 282 | |
| 283 | 283 | // Get the attachment data. |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | // or from uploads dir, but the image id still exists as featured image |
| 291 | 291 | // or in [gallery] shortcode. |
| 292 | 292 | // if ( empty( $attachment[0] ) ) { |
| 293 | - if ( empty( $sources_with_image ) ) { |
|
| 293 | + if (empty($sources_with_image)) { |
|
| 294 | 294 | return $carry; |
| 295 | 295 | } |
| 296 | 296 | |
@@ -301,21 +301,21 @@ discard block |
||
| 301 | 301 | ); |
| 302 | 302 | } |
| 303 | 303 | // Initial array. |
| 304 | - , array() ) |
|
| 304 | + , array()) |
|
| 305 | 305 | ); |
| 306 | 306 | |
| 307 | 307 | // Refactor data as per schema.org specifications. |
| 308 | - $images = array_map( function ( $attachment ) { |
|
| 308 | + $images = array_map(function($attachment) { |
|
| 309 | 309 | return Wordlift_Abstract_Post_To_Jsonld_Converter::set_image_size( |
| 310 | 310 | array( |
| 311 | 311 | '@type' => 'ImageObject', |
| 312 | 312 | 'url' => $attachment[0], |
| 313 | 313 | ), $attachment |
| 314 | 314 | ); |
| 315 | - }, $images_with_sizes ); |
|
| 315 | + }, $images_with_sizes); |
|
| 316 | 316 | |
| 317 | 317 | // Add images if present. |
| 318 | - if ( 0 < count( $images ) ) { |
|
| 318 | + if (0 < count($images)) { |
|
| 319 | 319 | $jsonld['image'] = $images; |
| 320 | 320 | } |
| 321 | 321 | |
@@ -334,9 +334,9 @@ discard block |
||
| 334 | 334 | * @access private |
| 335 | 335 | * |
| 336 | 336 | */ |
| 337 | - protected static function make_one( $value ) { |
|
| 337 | + protected static function make_one($value) { |
|
| 338 | 338 | |
| 339 | - return 1 === count( $value ) ? $value[0] : $value; |
|
| 339 | + return 1 === count($value) ? $value[0] : $value; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -350,17 +350,17 @@ discard block |
||
| 350 | 350 | * @since 3.14.0 |
| 351 | 351 | * |
| 352 | 352 | */ |
| 353 | - public static function set_image_size( $image, $attachment ) { |
|
| 353 | + public static function set_image_size($image, $attachment) { |
|
| 354 | 354 | |
| 355 | 355 | // If you specify a "width" or "height" value you should leave out |
| 356 | 356 | // 'px'. For example: "width":"4608px" should be "width":"4608". |
| 357 | 357 | // |
| 358 | 358 | // See https://github.com/insideout10/wordlift-plugin/issues/451. |
| 359 | - if ( isset( $attachment[1] ) && is_numeric( $attachment[1] ) && 0 < $attachment[1] ) { |
|
| 359 | + if (isset($attachment[1]) && is_numeric($attachment[1]) && 0 < $attachment[1]) { |
|
| 360 | 360 | $image['width'] = $attachment[1]; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if ( isset( $attachment[2] ) && is_numeric( $attachment[2] ) && 0 < $attachment[2] ) { |
|
| 363 | + if (isset($attachment[2]) && is_numeric($attachment[2]) && 0 < $attachment[2]) { |
|
| 364 | 364 | $image['height'] = $attachment[2]; |
| 365 | 365 | } |
| 366 | 366 | |