@@ -16,119 +16,119 @@ |
||
16 | 16 | */ |
17 | 17 | class Wordlift_Schemaorg_Sync_Batch_Operation implements Wordlift_Batch_Operation_Interface { |
18 | 18 | |
19 | - private static $instance = null; |
|
20 | - |
|
21 | - public static function get_instance() { |
|
22 | - |
|
23 | - if ( ! isset( self::$instance ) ) { |
|
24 | - self::$instance = new self(); |
|
25 | - } |
|
26 | - |
|
27 | - return self::$instance; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Process the batch operation starting from the specified offset. |
|
32 | - * |
|
33 | - * @param int $offset Start from the specified offset (or 0 if not specified). |
|
34 | - * @param int $limit Process the specified amount of items per call (or 10 if not specified). |
|
35 | - * |
|
36 | - * @return array { |
|
37 | - * The operation result. |
|
38 | - * |
|
39 | - * @type int $next The next offset. |
|
40 | - * @type int $limit The amount of items to process per call. |
|
41 | - * @type int $remaining The remaining number of elements to process. |
|
42 | - * } |
|
43 | - * @since 3.20.0 |
|
44 | - */ |
|
45 | - public function process( $offset = 0, $limit = 10 ) { |
|
46 | - |
|
47 | - // Get the schema classes. |
|
48 | - $all_schema_classes = $this->get_schema_classes(); |
|
49 | - |
|
50 | - // Get only the part that we need to process. |
|
51 | - $schema_classes = array_slice( $all_schema_classes, $offset, $limit ); |
|
52 | - |
|
53 | - // Load the Schema.org classes. |
|
54 | - foreach ( $schema_classes as $schema_class ) { |
|
55 | - $slug = $schema_class['dashname']; |
|
56 | - $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
57 | - |
|
58 | - $args = array( |
|
59 | - 'parent' => 0, |
|
60 | - 'description' => $schema_class['description'], |
|
61 | - 'slug' => $schema_class['dashname'], |
|
62 | - ); |
|
63 | - if ( null !== $term ) { |
|
64 | - wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
65 | - } else { |
|
66 | - $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
67 | - } |
|
68 | - |
|
69 | - // Update the parents/children relationship. |
|
70 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY ); |
|
71 | - foreach ( $schema_class['children'] as $child ) { |
|
72 | - add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] ); |
|
73 | - } |
|
74 | - |
|
75 | - // Update the term name. |
|
76 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY ); |
|
77 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] ); |
|
78 | - |
|
79 | - // Update the term URI. |
|
80 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY ); |
|
81 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - // Calculate the return values. |
|
86 | - $next = $offset + $limit; |
|
87 | - $remaining = $this->count(); |
|
88 | - |
|
89 | - return array( |
|
90 | - 'next' => $next, |
|
91 | - 'limit' => $limit, |
|
92 | - 'complete' => ( 0 === $remaining ), |
|
93 | - 'remaining' => $remaining, |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Count the number of elements that would be affected by the operation. |
|
99 | - * |
|
100 | - * @return int The number of elements that would be affected. |
|
101 | - * @since 3.20.0 |
|
102 | - */ |
|
103 | - public function count() { |
|
104 | - |
|
105 | - // Schema Classes count. |
|
106 | - $schema_classes_count = count( $this->get_schema_classes() ); |
|
107 | - |
|
108 | - // Terms count. |
|
109 | - $terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
110 | - |
|
111 | - // Return the difference. |
|
112 | - return $schema_classes_count - $terms_count; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Get the schema.org classes from the JSON file. |
|
117 | - * |
|
118 | - * @return array An array of schema classes. |
|
119 | - * @since 3.20.0 |
|
120 | - */ |
|
121 | - private function get_schema_classes() { |
|
122 | - |
|
123 | - // Load the file contents. |
|
124 | - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
125 | - $contents = file_get_contents( __DIR__ . '/schema-classes.json' ); |
|
126 | - |
|
127 | - // Decode the JSON contents. |
|
128 | - $json = json_decode( $contents, true ); |
|
129 | - |
|
130 | - // Return the schema classes or an empty array. |
|
131 | - return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array(); |
|
132 | - } |
|
19 | + private static $instance = null; |
|
20 | + |
|
21 | + public static function get_instance() { |
|
22 | + |
|
23 | + if ( ! isset( self::$instance ) ) { |
|
24 | + self::$instance = new self(); |
|
25 | + } |
|
26 | + |
|
27 | + return self::$instance; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Process the batch operation starting from the specified offset. |
|
32 | + * |
|
33 | + * @param int $offset Start from the specified offset (or 0 if not specified). |
|
34 | + * @param int $limit Process the specified amount of items per call (or 10 if not specified). |
|
35 | + * |
|
36 | + * @return array { |
|
37 | + * The operation result. |
|
38 | + * |
|
39 | + * @type int $next The next offset. |
|
40 | + * @type int $limit The amount of items to process per call. |
|
41 | + * @type int $remaining The remaining number of elements to process. |
|
42 | + * } |
|
43 | + * @since 3.20.0 |
|
44 | + */ |
|
45 | + public function process( $offset = 0, $limit = 10 ) { |
|
46 | + |
|
47 | + // Get the schema classes. |
|
48 | + $all_schema_classes = $this->get_schema_classes(); |
|
49 | + |
|
50 | + // Get only the part that we need to process. |
|
51 | + $schema_classes = array_slice( $all_schema_classes, $offset, $limit ); |
|
52 | + |
|
53 | + // Load the Schema.org classes. |
|
54 | + foreach ( $schema_classes as $schema_class ) { |
|
55 | + $slug = $schema_class['dashname']; |
|
56 | + $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
57 | + |
|
58 | + $args = array( |
|
59 | + 'parent' => 0, |
|
60 | + 'description' => $schema_class['description'], |
|
61 | + 'slug' => $schema_class['dashname'], |
|
62 | + ); |
|
63 | + if ( null !== $term ) { |
|
64 | + wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
65 | + } else { |
|
66 | + $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
67 | + } |
|
68 | + |
|
69 | + // Update the parents/children relationship. |
|
70 | + delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY ); |
|
71 | + foreach ( $schema_class['children'] as $child ) { |
|
72 | + add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] ); |
|
73 | + } |
|
74 | + |
|
75 | + // Update the term name. |
|
76 | + delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY ); |
|
77 | + update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] ); |
|
78 | + |
|
79 | + // Update the term URI. |
|
80 | + delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY ); |
|
81 | + update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" ); |
|
82 | + |
|
83 | + } |
|
84 | + |
|
85 | + // Calculate the return values. |
|
86 | + $next = $offset + $limit; |
|
87 | + $remaining = $this->count(); |
|
88 | + |
|
89 | + return array( |
|
90 | + 'next' => $next, |
|
91 | + 'limit' => $limit, |
|
92 | + 'complete' => ( 0 === $remaining ), |
|
93 | + 'remaining' => $remaining, |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Count the number of elements that would be affected by the operation. |
|
99 | + * |
|
100 | + * @return int The number of elements that would be affected. |
|
101 | + * @since 3.20.0 |
|
102 | + */ |
|
103 | + public function count() { |
|
104 | + |
|
105 | + // Schema Classes count. |
|
106 | + $schema_classes_count = count( $this->get_schema_classes() ); |
|
107 | + |
|
108 | + // Terms count. |
|
109 | + $terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
110 | + |
|
111 | + // Return the difference. |
|
112 | + return $schema_classes_count - $terms_count; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Get the schema.org classes from the JSON file. |
|
117 | + * |
|
118 | + * @return array An array of schema classes. |
|
119 | + * @since 3.20.0 |
|
120 | + */ |
|
121 | + private function get_schema_classes() { |
|
122 | + |
|
123 | + // Load the file contents. |
|
124 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
125 | + $contents = file_get_contents( __DIR__ . '/schema-classes.json' ); |
|
126 | + |
|
127 | + // Decode the JSON contents. |
|
128 | + $json = json_decode( $contents, true ); |
|
129 | + |
|
130 | + // Return the schema classes or an empty array. |
|
131 | + return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array(); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | public static function get_instance() { |
22 | 22 | |
23 | - if ( ! isset( self::$instance ) ) { |
|
23 | + if ( ! isset(self::$instance)) { |
|
24 | 24 | self::$instance = new self(); |
25 | 25 | } |
26 | 26 | |
@@ -42,43 +42,43 @@ discard block |
||
42 | 42 | * } |
43 | 43 | * @since 3.20.0 |
44 | 44 | */ |
45 | - public function process( $offset = 0, $limit = 10 ) { |
|
45 | + public function process($offset = 0, $limit = 10) { |
|
46 | 46 | |
47 | 47 | // Get the schema classes. |
48 | 48 | $all_schema_classes = $this->get_schema_classes(); |
49 | 49 | |
50 | 50 | // Get only the part that we need to process. |
51 | - $schema_classes = array_slice( $all_schema_classes, $offset, $limit ); |
|
51 | + $schema_classes = array_slice($all_schema_classes, $offset, $limit); |
|
52 | 52 | |
53 | 53 | // Load the Schema.org classes. |
54 | - foreach ( $schema_classes as $schema_class ) { |
|
54 | + foreach ($schema_classes as $schema_class) { |
|
55 | 55 | $slug = $schema_class['dashname']; |
56 | - $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
56 | + $term = term_exists($slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
57 | 57 | |
58 | 58 | $args = array( |
59 | 59 | 'parent' => 0, |
60 | 60 | 'description' => $schema_class['description'], |
61 | 61 | 'slug' => $schema_class['dashname'], |
62 | 62 | ); |
63 | - if ( null !== $term ) { |
|
64 | - wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
63 | + if (null !== $term) { |
|
64 | + wp_update_term($term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args); |
|
65 | 65 | } else { |
66 | - $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
66 | + $term = wp_insert_term($schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | // Update the parents/children relationship. |
70 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY ); |
|
71 | - foreach ( $schema_class['children'] as $child ) { |
|
72 | - add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] ); |
|
70 | + delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY); |
|
71 | + foreach ($schema_class['children'] as $child) { |
|
72 | + add_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname']); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Update the term name. |
76 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY ); |
|
77 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] ); |
|
76 | + delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY); |
|
77 | + update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name']); |
|
78 | 78 | |
79 | 79 | // Update the term URI. |
80 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY ); |
|
81 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" ); |
|
80 | + delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY); |
|
81 | + update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}"); |
|
82 | 82 | |
83 | 83 | } |
84 | 84 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | return array( |
90 | 90 | 'next' => $next, |
91 | 91 | 'limit' => $limit, |
92 | - 'complete' => ( 0 === $remaining ), |
|
92 | + 'complete' => (0 === $remaining), |
|
93 | 93 | 'remaining' => $remaining, |
94 | 94 | ); |
95 | 95 | } |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | public function count() { |
104 | 104 | |
105 | 105 | // Schema Classes count. |
106 | - $schema_classes_count = count( $this->get_schema_classes() ); |
|
106 | + $schema_classes_count = count($this->get_schema_classes()); |
|
107 | 107 | |
108 | 108 | // Terms count. |
109 | - $terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
109 | + $terms_count = wp_count_terms(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
110 | 110 | |
111 | 111 | // Return the difference. |
112 | 112 | return $schema_classes_count - $terms_count; |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | |
123 | 123 | // Load the file contents. |
124 | 124 | // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
125 | - $contents = file_get_contents( __DIR__ . '/schema-classes.json' ); |
|
125 | + $contents = file_get_contents(__DIR__.'/schema-classes.json'); |
|
126 | 126 | |
127 | 127 | // Decode the JSON contents. |
128 | - $json = json_decode( $contents, true ); |
|
128 | + $json = json_decode($contents, true); |
|
129 | 129 | |
130 | 130 | // Return the schema classes or an empty array. |
131 | - return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array(); |
|
131 | + return isset($json['schemaClasses']) ? $json['schemaClasses'] : array(); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | } |
@@ -16,110 +16,110 @@ |
||
16 | 16 | */ |
17 | 17 | class Wordlift_Schemaorg_Property_Service { |
18 | 18 | |
19 | - /** |
|
20 | - * The meta key prefix used to store properties. The `_` prefix makes these metas invisible in the |
|
21 | - * edit screen custom fields metabox. |
|
22 | - * |
|
23 | - * @since 3.20.0 |
|
24 | - */ |
|
25 | - const PREFIX = '_wl_prop_'; |
|
26 | - |
|
27 | - /** |
|
28 | - * Create a {@link Wordlift_Schemaorg_Property_Service} instance. |
|
29 | - * |
|
30 | - * @since 3.20.0 |
|
31 | - */ |
|
32 | - protected function __construct() { |
|
33 | - |
|
34 | - } |
|
35 | - |
|
36 | - private static $instance = null; |
|
37 | - |
|
38 | - /** |
|
39 | - * Get the singleton instance. |
|
40 | - * |
|
41 | - * @return \Wordlift_Schemaorg_Property_Service The singleton instance. |
|
42 | - * @since 3.20.0 |
|
43 | - */ |
|
44 | - public static function get_instance() { |
|
45 | - |
|
46 | - if ( ! isset( self::$instance ) ) { |
|
47 | - self::$instance = new self(); |
|
48 | - } |
|
49 | - |
|
50 | - return self::$instance; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get all the properties bound to the specified post. |
|
55 | - * |
|
56 | - * @param int $post_id The post id. |
|
57 | - * |
|
58 | - * @return array An array of properties instances keyed by the property name. Each property contains a |
|
59 | - * `type` and a `value` and optionally a `language`. |
|
60 | - * } |
|
61 | - * @since 3.20.0 |
|
62 | - */ |
|
63 | - public function get_all( $post_id ) { |
|
64 | - |
|
65 | - // Get all the post metas. |
|
66 | - $post_metas = get_post_meta( $post_id ); |
|
67 | - |
|
68 | - // Cycle through them to get the Schema.org properties. |
|
69 | - $props = array(); |
|
70 | - foreach ( $post_metas as $key => $values ) { |
|
71 | - $matches = array(); |
|
72 | - |
|
73 | - // We're looking for `_wl_prop_propName_uuid_key`. |
|
74 | - if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) { |
|
75 | - $name = $matches[1]; |
|
76 | - $uuid = $matches[2]; |
|
77 | - $key = $matches[3]; |
|
78 | - |
|
79 | - // Record the value. |
|
80 | - $props[ $name ][ $uuid ][ $key ] = $values[0]; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - // Remove the UUIDs. |
|
85 | - foreach ( $props as $name => $instance ) { |
|
86 | - foreach ( $instance as $uuid => $keys ) { |
|
87 | - // This way we remove the `uuid`s. |
|
88 | - $props[ $name ] = array_values( $instance ); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - // Finally return the props. |
|
93 | - return $props; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the meta keys for Schema.org properties associated with the specified post. |
|
98 | - * |
|
99 | - * @param int $post_id The post id. |
|
100 | - * |
|
101 | - * @return array An array of meta keys. |
|
102 | - * @since 3.20.0 |
|
103 | - */ |
|
104 | - public function get_keys( $post_id ) { |
|
105 | - |
|
106 | - // Get all the post metas to remove the `_wl_prop` ones. |
|
107 | - $post_meta = get_post_meta( $post_id ); |
|
108 | - |
|
109 | - // Get the keys. |
|
110 | - $post_meta_keys = array_unique( array_keys( $post_meta ) ); |
|
111 | - |
|
112 | - // Get only the `_wl_prop` keys. `array_values` resets the indexes. |
|
113 | - $prop_keys = array_values( |
|
114 | - array_filter( |
|
115 | - $post_meta_keys, |
|
116 | - function ( $item ) { |
|
117 | - return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX ); |
|
118 | - } |
|
119 | - ) |
|
120 | - ); |
|
121 | - |
|
122 | - return $prop_keys; |
|
123 | - } |
|
19 | + /** |
|
20 | + * The meta key prefix used to store properties. The `_` prefix makes these metas invisible in the |
|
21 | + * edit screen custom fields metabox. |
|
22 | + * |
|
23 | + * @since 3.20.0 |
|
24 | + */ |
|
25 | + const PREFIX = '_wl_prop_'; |
|
26 | + |
|
27 | + /** |
|
28 | + * Create a {@link Wordlift_Schemaorg_Property_Service} instance. |
|
29 | + * |
|
30 | + * @since 3.20.0 |
|
31 | + */ |
|
32 | + protected function __construct() { |
|
33 | + |
|
34 | + } |
|
35 | + |
|
36 | + private static $instance = null; |
|
37 | + |
|
38 | + /** |
|
39 | + * Get the singleton instance. |
|
40 | + * |
|
41 | + * @return \Wordlift_Schemaorg_Property_Service The singleton instance. |
|
42 | + * @since 3.20.0 |
|
43 | + */ |
|
44 | + public static function get_instance() { |
|
45 | + |
|
46 | + if ( ! isset( self::$instance ) ) { |
|
47 | + self::$instance = new self(); |
|
48 | + } |
|
49 | + |
|
50 | + return self::$instance; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get all the properties bound to the specified post. |
|
55 | + * |
|
56 | + * @param int $post_id The post id. |
|
57 | + * |
|
58 | + * @return array An array of properties instances keyed by the property name. Each property contains a |
|
59 | + * `type` and a `value` and optionally a `language`. |
|
60 | + * } |
|
61 | + * @since 3.20.0 |
|
62 | + */ |
|
63 | + public function get_all( $post_id ) { |
|
64 | + |
|
65 | + // Get all the post metas. |
|
66 | + $post_metas = get_post_meta( $post_id ); |
|
67 | + |
|
68 | + // Cycle through them to get the Schema.org properties. |
|
69 | + $props = array(); |
|
70 | + foreach ( $post_metas as $key => $values ) { |
|
71 | + $matches = array(); |
|
72 | + |
|
73 | + // We're looking for `_wl_prop_propName_uuid_key`. |
|
74 | + if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) { |
|
75 | + $name = $matches[1]; |
|
76 | + $uuid = $matches[2]; |
|
77 | + $key = $matches[3]; |
|
78 | + |
|
79 | + // Record the value. |
|
80 | + $props[ $name ][ $uuid ][ $key ] = $values[0]; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + // Remove the UUIDs. |
|
85 | + foreach ( $props as $name => $instance ) { |
|
86 | + foreach ( $instance as $uuid => $keys ) { |
|
87 | + // This way we remove the `uuid`s. |
|
88 | + $props[ $name ] = array_values( $instance ); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + // Finally return the props. |
|
93 | + return $props; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the meta keys for Schema.org properties associated with the specified post. |
|
98 | + * |
|
99 | + * @param int $post_id The post id. |
|
100 | + * |
|
101 | + * @return array An array of meta keys. |
|
102 | + * @since 3.20.0 |
|
103 | + */ |
|
104 | + public function get_keys( $post_id ) { |
|
105 | + |
|
106 | + // Get all the post metas to remove the `_wl_prop` ones. |
|
107 | + $post_meta = get_post_meta( $post_id ); |
|
108 | + |
|
109 | + // Get the keys. |
|
110 | + $post_meta_keys = array_unique( array_keys( $post_meta ) ); |
|
111 | + |
|
112 | + // Get only the `_wl_prop` keys. `array_values` resets the indexes. |
|
113 | + $prop_keys = array_values( |
|
114 | + array_filter( |
|
115 | + $post_meta_keys, |
|
116 | + function ( $item ) { |
|
117 | + return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX ); |
|
118 | + } |
|
119 | + ) |
|
120 | + ); |
|
121 | + |
|
122 | + return $prop_keys; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function get_instance() { |
45 | 45 | |
46 | - if ( ! isset( self::$instance ) ) { |
|
46 | + if ( ! isset(self::$instance)) { |
|
47 | 47 | self::$instance = new self(); |
48 | 48 | } |
49 | 49 | |
@@ -60,32 +60,32 @@ discard block |
||
60 | 60 | * } |
61 | 61 | * @since 3.20.0 |
62 | 62 | */ |
63 | - public function get_all( $post_id ) { |
|
63 | + public function get_all($post_id) { |
|
64 | 64 | |
65 | 65 | // Get all the post metas. |
66 | - $post_metas = get_post_meta( $post_id ); |
|
66 | + $post_metas = get_post_meta($post_id); |
|
67 | 67 | |
68 | 68 | // Cycle through them to get the Schema.org properties. |
69 | 69 | $props = array(); |
70 | - foreach ( $post_metas as $key => $values ) { |
|
70 | + foreach ($post_metas as $key => $values) { |
|
71 | 71 | $matches = array(); |
72 | 72 | |
73 | 73 | // We're looking for `_wl_prop_propName_uuid_key`. |
74 | - if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) { |
|
74 | + if (1 === preg_match('/'.self::PREFIX.'(\w+)_([\w-]+)_(\w+)/i', $key, $matches)) { |
|
75 | 75 | $name = $matches[1]; |
76 | 76 | $uuid = $matches[2]; |
77 | 77 | $key = $matches[3]; |
78 | 78 | |
79 | 79 | // Record the value. |
80 | - $props[ $name ][ $uuid ][ $key ] = $values[0]; |
|
80 | + $props[$name][$uuid][$key] = $values[0]; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | 84 | // Remove the UUIDs. |
85 | - foreach ( $props as $name => $instance ) { |
|
86 | - foreach ( $instance as $uuid => $keys ) { |
|
85 | + foreach ($props as $name => $instance) { |
|
86 | + foreach ($instance as $uuid => $keys) { |
|
87 | 87 | // This way we remove the `uuid`s. |
88 | - $props[ $name ] = array_values( $instance ); |
|
88 | + $props[$name] = array_values($instance); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -101,20 +101,20 @@ discard block |
||
101 | 101 | * @return array An array of meta keys. |
102 | 102 | * @since 3.20.0 |
103 | 103 | */ |
104 | - public function get_keys( $post_id ) { |
|
104 | + public function get_keys($post_id) { |
|
105 | 105 | |
106 | 106 | // Get all the post metas to remove the `_wl_prop` ones. |
107 | - $post_meta = get_post_meta( $post_id ); |
|
107 | + $post_meta = get_post_meta($post_id); |
|
108 | 108 | |
109 | 109 | // Get the keys. |
110 | - $post_meta_keys = array_unique( array_keys( $post_meta ) ); |
|
110 | + $post_meta_keys = array_unique(array_keys($post_meta)); |
|
111 | 111 | |
112 | 112 | // Get only the `_wl_prop` keys. `array_values` resets the indexes. |
113 | 113 | $prop_keys = array_values( |
114 | 114 | array_filter( |
115 | 115 | $post_meta_keys, |
116 | - function ( $item ) { |
|
117 | - return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX ); |
|
116 | + function($item) { |
|
117 | + return 0 === strpos($item, Wordlift_Schemaorg_Property_Service::PREFIX); |
|
118 | 118 | } |
119 | 119 | ) |
120 | 120 | ); |
@@ -16,20 +16,20 @@ |
||
16 | 16 | */ |
17 | 17 | class Wordlift_NewRelic_Adapter { |
18 | 18 | |
19 | - /** |
|
20 | - * Tell NewRelic to ignore this "transaction" for the Apdex. |
|
21 | - * |
|
22 | - * @see https://github.com/insideout10/wordlift-plugin/issues/521 |
|
23 | - * |
|
24 | - * @since 3.11.3 |
|
25 | - */ |
|
26 | - public static function ignore_apdex() { |
|
19 | + /** |
|
20 | + * Tell NewRelic to ignore this "transaction" for the Apdex. |
|
21 | + * |
|
22 | + * @see https://github.com/insideout10/wordlift-plugin/issues/521 |
|
23 | + * |
|
24 | + * @since 3.11.3 |
|
25 | + */ |
|
26 | + public static function ignore_apdex() { |
|
27 | 27 | |
28 | - // Ensure PHP agent and the function are available. |
|
29 | - if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) { |
|
30 | - newrelic_ignore_apdex(); |
|
31 | - } |
|
28 | + // Ensure PHP agent and the function are available. |
|
29 | + if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) { |
|
30 | + newrelic_ignore_apdex(); |
|
31 | + } |
|
32 | 32 | |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | 35 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | public static function ignore_apdex() { |
27 | 27 | |
28 | 28 | // Ensure PHP agent and the function are available. |
29 | - if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) { |
|
29 | + if (extension_loaded('newrelic') && function_exists('newrelic_ignore_apdex')) { |
|
30 | 30 | newrelic_ignore_apdex(); |
31 | 31 | } |
32 | 32 |
@@ -17,54 +17,54 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class Wordlift_Entity_Page_Service { |
19 | 19 | |
20 | - /** |
|
21 | - * Set the entity post types as one to be included in archive pages. |
|
22 | - * |
|
23 | - * In order to have entities show up in standard WP categories (Posts categories) |
|
24 | - * we configure the `entity` post type, but we also need to alter the main |
|
25 | - * WP query (which by default queries posts only) to include the `entities`. |
|
26 | - * |
|
27 | - * @since 3.12.0 |
|
28 | - * |
|
29 | - * @param WP_Query $query WP's {@link WP_Query} instance. |
|
30 | - */ |
|
31 | - public function pre_get_posts( $query ) { |
|
32 | - |
|
33 | - // Only for the main query, avoid problems with widgets and what not. |
|
34 | - if ( ! $query->is_main_query() ) { |
|
35 | - return; |
|
36 | - } |
|
37 | - |
|
38 | - // We don't want to alter the query if we're in the admin UI, if this is |
|
39 | - // not a entity type achieve query, or if the `suppress_filters` is set. |
|
40 | - // |
|
41 | - // Note that it is unlikely for `suppress_filter` to be set on the front |
|
42 | - // end, but let's be safe if it is set the calling code assumes no |
|
43 | - // modifications of queries. |
|
44 | - |
|
45 | - // Ignore admin side request, requests for which filters should be |
|
46 | - // suppressed, and when we are not on a entity type archive page. |
|
47 | - if ( is_admin() || |
|
48 | - ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) || |
|
49 | - ! empty( $query->query_vars['suppress_filters'] ) |
|
50 | - ) { |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - // Events should be sorted by start date in descending order. |
|
55 | - if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) { |
|
56 | - |
|
57 | - // Update the query to use the start time meta and desc order. |
|
58 | - $meta_query = array( |
|
59 | - array( |
|
60 | - 'key' => Wordlift_Schema_Service::FIELD_DATE_START, |
|
61 | - ), |
|
62 | - ); |
|
63 | - $query->set( 'meta_query', $meta_query ); |
|
64 | - $query->set( 'orderby', 'meta_value' ); |
|
65 | - $query->set( 'order', 'DESC' ); |
|
66 | - } else { |
|
67 | - /* |
|
20 | + /** |
|
21 | + * Set the entity post types as one to be included in archive pages. |
|
22 | + * |
|
23 | + * In order to have entities show up in standard WP categories (Posts categories) |
|
24 | + * we configure the `entity` post type, but we also need to alter the main |
|
25 | + * WP query (which by default queries posts only) to include the `entities`. |
|
26 | + * |
|
27 | + * @since 3.12.0 |
|
28 | + * |
|
29 | + * @param WP_Query $query WP's {@link WP_Query} instance. |
|
30 | + */ |
|
31 | + public function pre_get_posts( $query ) { |
|
32 | + |
|
33 | + // Only for the main query, avoid problems with widgets and what not. |
|
34 | + if ( ! $query->is_main_query() ) { |
|
35 | + return; |
|
36 | + } |
|
37 | + |
|
38 | + // We don't want to alter the query if we're in the admin UI, if this is |
|
39 | + // not a entity type achieve query, or if the `suppress_filters` is set. |
|
40 | + // |
|
41 | + // Note that it is unlikely for `suppress_filter` to be set on the front |
|
42 | + // end, but let's be safe if it is set the calling code assumes no |
|
43 | + // modifications of queries. |
|
44 | + |
|
45 | + // Ignore admin side request, requests for which filters should be |
|
46 | + // suppressed, and when we are not on a entity type archive page. |
|
47 | + if ( is_admin() || |
|
48 | + ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) || |
|
49 | + ! empty( $query->query_vars['suppress_filters'] ) |
|
50 | + ) { |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + // Events should be sorted by start date in descending order. |
|
55 | + if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) { |
|
56 | + |
|
57 | + // Update the query to use the start time meta and desc order. |
|
58 | + $meta_query = array( |
|
59 | + array( |
|
60 | + 'key' => Wordlift_Schema_Service::FIELD_DATE_START, |
|
61 | + ), |
|
62 | + ); |
|
63 | + $query->set( 'meta_query', $meta_query ); |
|
64 | + $query->set( 'orderby', 'meta_value' ); |
|
65 | + $query->set( 'order', 'DESC' ); |
|
66 | + } else { |
|
67 | + /* |
|
68 | 68 | * All other entity types should be sorted by their connectivity. |
69 | 69 | * For this we need to query the relationship table which has |
70 | 70 | * to be done by manipulating the SQL generated for the query. |
@@ -72,73 +72,73 @@ discard block |
||
72 | 72 | * additional filters to handle it. |
73 | 73 | */ |
74 | 74 | |
75 | - add_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
76 | - add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
77 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Filter handler that sets the join part of a query to include the |
|
83 | - * relationship table to be able to use it in the sorting. |
|
84 | - * |
|
85 | - * @since 3.15.0 |
|
86 | - * |
|
87 | - * @param string $join_statement The join part of the SQL statement which is used for the query. |
|
88 | - * |
|
89 | - * @return string An join SQL which add the relationships table to the join. |
|
90 | - */ |
|
91 | - public function posts_join( $join_statement ) { |
|
92 | - |
|
93 | - global $wpdb; |
|
94 | - |
|
95 | - $join_statement .= " LEFT JOIN {$wpdb->prefix}wl_relation_instances ri " |
|
96 | - . " ON (ri.object_id = {$wpdb->posts}.ID)"; |
|
97 | - |
|
98 | - // Remove to make sure it will not run agan in other context. |
|
99 | - remove_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
100 | - |
|
101 | - return $join_statement; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Filter handler that sets the groupby part of a query to include the |
|
106 | - * relationship table to be able to use it in the sorting. |
|
107 | - * |
|
108 | - * @since 3.15.0 |
|
109 | - * |
|
110 | - * @param string $groupby_statement The groupby part of the SQL statement which is used for the query. |
|
111 | - * |
|
112 | - * @return string A groupby SQL which add the relationships table to the join. |
|
113 | - */ |
|
114 | - public function posts_groupby( $groupby_statement ) { |
|
115 | - |
|
116 | - $groupby_statement = 'ri.object_id, ' . $groupby_statement; |
|
117 | - |
|
118 | - // Remove to make sure it will not run agan in other context. |
|
119 | - remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
120 | - |
|
121 | - return $groupby_statement; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Filter handler that sets the orderby part of a query to sort by number of |
|
126 | - * relationships. |
|
127 | - * |
|
128 | - * @since 3.15.0 |
|
129 | - * |
|
130 | - * @param string $orderby_statement The orderby part of the SQL statement which is used for the query. |
|
131 | - * |
|
132 | - * @return string An orderby SQL which sorts by the number of relationships |
|
133 | - */ |
|
134 | - public function posts_orderby( $orderby_statement ) { |
|
135 | - |
|
136 | - $orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement; |
|
137 | - |
|
138 | - // Remove to make sure it will not run agan in other context. |
|
139 | - remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
140 | - |
|
141 | - return $orderby_statement; |
|
142 | - } |
|
75 | + add_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
76 | + add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
77 | + add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Filter handler that sets the join part of a query to include the |
|
83 | + * relationship table to be able to use it in the sorting. |
|
84 | + * |
|
85 | + * @since 3.15.0 |
|
86 | + * |
|
87 | + * @param string $join_statement The join part of the SQL statement which is used for the query. |
|
88 | + * |
|
89 | + * @return string An join SQL which add the relationships table to the join. |
|
90 | + */ |
|
91 | + public function posts_join( $join_statement ) { |
|
92 | + |
|
93 | + global $wpdb; |
|
94 | + |
|
95 | + $join_statement .= " LEFT JOIN {$wpdb->prefix}wl_relation_instances ri " |
|
96 | + . " ON (ri.object_id = {$wpdb->posts}.ID)"; |
|
97 | + |
|
98 | + // Remove to make sure it will not run agan in other context. |
|
99 | + remove_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
100 | + |
|
101 | + return $join_statement; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Filter handler that sets the groupby part of a query to include the |
|
106 | + * relationship table to be able to use it in the sorting. |
|
107 | + * |
|
108 | + * @since 3.15.0 |
|
109 | + * |
|
110 | + * @param string $groupby_statement The groupby part of the SQL statement which is used for the query. |
|
111 | + * |
|
112 | + * @return string A groupby SQL which add the relationships table to the join. |
|
113 | + */ |
|
114 | + public function posts_groupby( $groupby_statement ) { |
|
115 | + |
|
116 | + $groupby_statement = 'ri.object_id, ' . $groupby_statement; |
|
117 | + |
|
118 | + // Remove to make sure it will not run agan in other context. |
|
119 | + remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
120 | + |
|
121 | + return $groupby_statement; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Filter handler that sets the orderby part of a query to sort by number of |
|
126 | + * relationships. |
|
127 | + * |
|
128 | + * @since 3.15.0 |
|
129 | + * |
|
130 | + * @param string $orderby_statement The orderby part of the SQL statement which is used for the query. |
|
131 | + * |
|
132 | + * @return string An orderby SQL which sorts by the number of relationships |
|
133 | + */ |
|
134 | + public function posts_orderby( $orderby_statement ) { |
|
135 | + |
|
136 | + $orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement; |
|
137 | + |
|
138 | + // Remove to make sure it will not run agan in other context. |
|
139 | + remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
140 | + |
|
141 | + return $orderby_statement; |
|
142 | + } |
|
143 | 143 | |
144 | 144 | } |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @param WP_Query $query WP's {@link WP_Query} instance. |
30 | 30 | */ |
31 | - public function pre_get_posts( $query ) { |
|
31 | + public function pre_get_posts($query) { |
|
32 | 32 | |
33 | 33 | // Only for the main query, avoid problems with widgets and what not. |
34 | - if ( ! $query->is_main_query() ) { |
|
34 | + if ( ! $query->is_main_query()) { |
|
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | |
45 | 45 | // Ignore admin side request, requests for which filters should be |
46 | 46 | // suppressed, and when we are not on a entity type archive page. |
47 | - if ( is_admin() || |
|
48 | - ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) || |
|
49 | - ! empty( $query->query_vars['suppress_filters'] ) |
|
47 | + if (is_admin() || |
|
48 | + ! is_tax(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME) || |
|
49 | + ! empty($query->query_vars['suppress_filters']) |
|
50 | 50 | ) { |
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | // Events should be sorted by start date in descending order. |
55 | - if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) { |
|
55 | + if (is_tax(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event')) { |
|
56 | 56 | |
57 | 57 | // Update the query to use the start time meta and desc order. |
58 | 58 | $meta_query = array( |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | 'key' => Wordlift_Schema_Service::FIELD_DATE_START, |
61 | 61 | ), |
62 | 62 | ); |
63 | - $query->set( 'meta_query', $meta_query ); |
|
64 | - $query->set( 'orderby', 'meta_value' ); |
|
65 | - $query->set( 'order', 'DESC' ); |
|
63 | + $query->set('meta_query', $meta_query); |
|
64 | + $query->set('orderby', 'meta_value'); |
|
65 | + $query->set('order', 'DESC'); |
|
66 | 66 | } else { |
67 | 67 | /* |
68 | 68 | * All other entity types should be sorted by their connectivity. |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | * additional filters to handle it. |
73 | 73 | */ |
74 | 74 | |
75 | - add_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
76 | - add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
77 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
75 | + add_filter('posts_join', array($this, 'posts_join')); |
|
76 | + add_filter('posts_groupby', array($this, 'posts_groupby')); |
|
77 | + add_filter('posts_orderby', array($this, 'posts_orderby')); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string An join SQL which add the relationships table to the join. |
90 | 90 | */ |
91 | - public function posts_join( $join_statement ) { |
|
91 | + public function posts_join($join_statement) { |
|
92 | 92 | |
93 | 93 | global $wpdb; |
94 | 94 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | . " ON (ri.object_id = {$wpdb->posts}.ID)"; |
97 | 97 | |
98 | 98 | // Remove to make sure it will not run agan in other context. |
99 | - remove_filter( 'posts_join', array( $this, 'posts_join' ) ); |
|
99 | + remove_filter('posts_join', array($this, 'posts_join')); |
|
100 | 100 | |
101 | 101 | return $join_statement; |
102 | 102 | } |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return string A groupby SQL which add the relationships table to the join. |
113 | 113 | */ |
114 | - public function posts_groupby( $groupby_statement ) { |
|
114 | + public function posts_groupby($groupby_statement) { |
|
115 | 115 | |
116 | - $groupby_statement = 'ri.object_id, ' . $groupby_statement; |
|
116 | + $groupby_statement = 'ri.object_id, '.$groupby_statement; |
|
117 | 117 | |
118 | 118 | // Remove to make sure it will not run agan in other context. |
119 | - remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) ); |
|
119 | + remove_filter('posts_groupby', array($this, 'posts_groupby')); |
|
120 | 120 | |
121 | 121 | return $groupby_statement; |
122 | 122 | } |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return string An orderby SQL which sorts by the number of relationships |
133 | 133 | */ |
134 | - public function posts_orderby( $orderby_statement ) { |
|
134 | + public function posts_orderby($orderby_statement) { |
|
135 | 135 | |
136 | - $orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement; |
|
136 | + $orderby_statement = 'COUNT( ri.object_id ) DESC, '.$orderby_statement; |
|
137 | 137 | |
138 | 138 | // Remove to make sure it will not run agan in other context. |
139 | - remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) ); |
|
139 | + remove_filter('posts_orderby', array($this, 'posts_orderby')); |
|
140 | 140 | |
141 | 141 | return $orderby_statement; |
142 | 142 | } |
@@ -17,98 +17,98 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class Wordlift_Sample_Data_Service { |
19 | 19 | |
20 | - /** |
|
21 | - * An array of sample data. |
|
22 | - * |
|
23 | - * @since 3.12.0 |
|
24 | - * @var array $samples An array of sample data. |
|
25 | - */ |
|
26 | - private $samples = array( |
|
27 | - array( |
|
28 | - 'post' => array( |
|
29 | - 'post_name' => 'praesent_imperdiet_odio_sed_lectus_vulputate_finibus', |
|
30 | - 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
31 | - 'post_content' => 'Praesent imperdiet odio sed lectus vulputate finibus. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.', |
|
32 | - 'post_type' => 'entity', |
|
33 | - 'post_status' => 'publish', |
|
34 | - ), |
|
35 | - 'entity_type_uri' => 'http://schema.org/Event', |
|
36 | - ), |
|
37 | - array( |
|
38 | - 'post' => array( |
|
39 | - 'post_name' => 'nullam_tempor_lectus_sit_amet_tincidunt_euismod', |
|
40 | - 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
41 | - 'post_content' => '<span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span> Nullam tempor lectus sit amet tincidunt euismod. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.', |
|
42 | - 'post_type' => 'entity', |
|
43 | - 'post_status' => 'publish', |
|
44 | - ), |
|
45 | - 'entity_type_uri' => 'http://schema.org/Place', |
|
46 | - ), |
|
47 | - array( |
|
48 | - 'post' => array( |
|
49 | - 'post_name' => 'praesent_luctus_tincidunt_odio_quis_aliquam', |
|
50 | - 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
51 | - 'post_content' => 'Praesent luctus tincidunt odio quis aliquam. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.', |
|
52 | - 'post_type' => 'entity', |
|
53 | - 'post_status' => 'publish', |
|
54 | - ), |
|
55 | - 'entity_type_uri' => 'http://schema.org/Organization', |
|
56 | - ), |
|
57 | - array( |
|
58 | - 'post' => array( |
|
59 | - 'post_name' => 'lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit', |
|
60 | - 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
61 | - 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
|
62 | - 'post_type' => 'entity', |
|
63 | - 'post_status' => 'publish', |
|
64 | - ), |
|
65 | - 'entity_type_uri' => 'http://schema.org/CreativeWork', |
|
66 | - ), |
|
67 | - array( |
|
68 | - 'post' => |
|
69 | - array( |
|
70 | - 'post_name' => 'post_1', |
|
71 | - 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
72 | - 'post_content' => '<span><span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span>. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.</span>', |
|
73 | - 'post_type' => 'post', |
|
74 | - 'post_status' => 'publish', |
|
75 | - ), |
|
76 | - ), |
|
77 | - array( |
|
78 | - 'post' => |
|
79 | - array( |
|
80 | - 'post_name' => 'post_2', |
|
81 | - 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
82 | - 'post_content' => '<span><span id="urn:local-text-annotation-p8i5o4279ex3rsbwqkrx9z5mh1ox91ae" class="textannotation disambiguated wl-place" itemid="{dataset-uri}/entity/nullam_tempor_lectus_sit_amet_tincidunt_euismod">Nullam tempor lectus sit amet tincidunt euismod</span>. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</span>', |
|
83 | - 'post_type' => 'post', |
|
84 | - 'post_status' => 'publish', |
|
85 | - ), |
|
86 | - ), |
|
87 | - array( |
|
88 | - 'post' => |
|
89 | - array( |
|
90 | - 'post_name' => 'post_3', |
|
91 | - 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
92 | - 'post_content' => '<span><span id="urn:enhancement-b3487a20-4696-b6d9-6c55-842445f5c263" class="textannotation disambiguated wl-organization" itemid="{dataset-uri}/entity/praesent_luctus_tincidunt_odio_quis_aliquam">Praesent luctus tincidunt odio quis aliquam</span>. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.</span>', |
|
93 | - 'post_type' => 'post', |
|
94 | - 'post_status' => 'publish', |
|
95 | - ), |
|
96 | - ), |
|
97 | - array( |
|
98 | - 'post' => |
|
99 | - array( |
|
100 | - 'post_name' => 'post_4', |
|
101 | - 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
102 | - 'post_content' => '<span><span id="urn:enhancement-4edc3bde-d275-22f9-8d50-0b707596b292" class="textannotation disambiguated wl-thing" itemid="{dataset-uri}/entity/lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>. Proin rutrum ultrices nulla ut elementum. Nunc nec lacus tortor. Curabitur bibendum imperdiet luctus. Vivamus a faucibus dolor. Donec blandit malesuada risus. Vestibulum volutpat ut tellus sed tincidunt. Sed id tincidunt velit. Integer sed felis id libero fringilla molestie vitae id orci. Ut vel purus ullamcorper, feugiat tortor non, iaculis neque. Vivamus vitae vehicula sem. Mauris fermentum, metus id vestibulum sodales, lorem lacus efficitur ante, non vestibulum ligula ligula a turpis. Vivamus quis scelerisque massa.</span>', |
|
103 | - 'post_type' => 'post', |
|
104 | - 'post_status' => 'publish', |
|
105 | - ), |
|
106 | - ), |
|
107 | - array( |
|
108 | - 'post' => array( |
|
109 | - 'post_name' => 'post_5', |
|
110 | - 'post_title' => 'Lorem ipsum', |
|
111 | - 'post_content' => ' |
|
20 | + /** |
|
21 | + * An array of sample data. |
|
22 | + * |
|
23 | + * @since 3.12.0 |
|
24 | + * @var array $samples An array of sample data. |
|
25 | + */ |
|
26 | + private $samples = array( |
|
27 | + array( |
|
28 | + 'post' => array( |
|
29 | + 'post_name' => 'praesent_imperdiet_odio_sed_lectus_vulputate_finibus', |
|
30 | + 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
31 | + 'post_content' => 'Praesent imperdiet odio sed lectus vulputate finibus. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.', |
|
32 | + 'post_type' => 'entity', |
|
33 | + 'post_status' => 'publish', |
|
34 | + ), |
|
35 | + 'entity_type_uri' => 'http://schema.org/Event', |
|
36 | + ), |
|
37 | + array( |
|
38 | + 'post' => array( |
|
39 | + 'post_name' => 'nullam_tempor_lectus_sit_amet_tincidunt_euismod', |
|
40 | + 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
41 | + 'post_content' => '<span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span> Nullam tempor lectus sit amet tincidunt euismod. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.', |
|
42 | + 'post_type' => 'entity', |
|
43 | + 'post_status' => 'publish', |
|
44 | + ), |
|
45 | + 'entity_type_uri' => 'http://schema.org/Place', |
|
46 | + ), |
|
47 | + array( |
|
48 | + 'post' => array( |
|
49 | + 'post_name' => 'praesent_luctus_tincidunt_odio_quis_aliquam', |
|
50 | + 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
51 | + 'post_content' => 'Praesent luctus tincidunt odio quis aliquam. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.', |
|
52 | + 'post_type' => 'entity', |
|
53 | + 'post_status' => 'publish', |
|
54 | + ), |
|
55 | + 'entity_type_uri' => 'http://schema.org/Organization', |
|
56 | + ), |
|
57 | + array( |
|
58 | + 'post' => array( |
|
59 | + 'post_name' => 'lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit', |
|
60 | + 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
61 | + 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
|
62 | + 'post_type' => 'entity', |
|
63 | + 'post_status' => 'publish', |
|
64 | + ), |
|
65 | + 'entity_type_uri' => 'http://schema.org/CreativeWork', |
|
66 | + ), |
|
67 | + array( |
|
68 | + 'post' => |
|
69 | + array( |
|
70 | + 'post_name' => 'post_1', |
|
71 | + 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
72 | + 'post_content' => '<span><span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span>. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.</span>', |
|
73 | + 'post_type' => 'post', |
|
74 | + 'post_status' => 'publish', |
|
75 | + ), |
|
76 | + ), |
|
77 | + array( |
|
78 | + 'post' => |
|
79 | + array( |
|
80 | + 'post_name' => 'post_2', |
|
81 | + 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
82 | + 'post_content' => '<span><span id="urn:local-text-annotation-p8i5o4279ex3rsbwqkrx9z5mh1ox91ae" class="textannotation disambiguated wl-place" itemid="{dataset-uri}/entity/nullam_tempor_lectus_sit_amet_tincidunt_euismod">Nullam tempor lectus sit amet tincidunt euismod</span>. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</span>', |
|
83 | + 'post_type' => 'post', |
|
84 | + 'post_status' => 'publish', |
|
85 | + ), |
|
86 | + ), |
|
87 | + array( |
|
88 | + 'post' => |
|
89 | + array( |
|
90 | + 'post_name' => 'post_3', |
|
91 | + 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
92 | + 'post_content' => '<span><span id="urn:enhancement-b3487a20-4696-b6d9-6c55-842445f5c263" class="textannotation disambiguated wl-organization" itemid="{dataset-uri}/entity/praesent_luctus_tincidunt_odio_quis_aliquam">Praesent luctus tincidunt odio quis aliquam</span>. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.</span>', |
|
93 | + 'post_type' => 'post', |
|
94 | + 'post_status' => 'publish', |
|
95 | + ), |
|
96 | + ), |
|
97 | + array( |
|
98 | + 'post' => |
|
99 | + array( |
|
100 | + 'post_name' => 'post_4', |
|
101 | + 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
102 | + 'post_content' => '<span><span id="urn:enhancement-4edc3bde-d275-22f9-8d50-0b707596b292" class="textannotation disambiguated wl-thing" itemid="{dataset-uri}/entity/lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>. Proin rutrum ultrices nulla ut elementum. Nunc nec lacus tortor. Curabitur bibendum imperdiet luctus. Vivamus a faucibus dolor. Donec blandit malesuada risus. Vestibulum volutpat ut tellus sed tincidunt. Sed id tincidunt velit. Integer sed felis id libero fringilla molestie vitae id orci. Ut vel purus ullamcorper, feugiat tortor non, iaculis neque. Vivamus vitae vehicula sem. Mauris fermentum, metus id vestibulum sodales, lorem lacus efficitur ante, non vestibulum ligula ligula a turpis. Vivamus quis scelerisque massa.</span>', |
|
103 | + 'post_type' => 'post', |
|
104 | + 'post_status' => 'publish', |
|
105 | + ), |
|
106 | + ), |
|
107 | + array( |
|
108 | + 'post' => array( |
|
109 | + 'post_name' => 'post_5', |
|
110 | + 'post_title' => 'Lorem ipsum', |
|
111 | + 'post_content' => ' |
|
112 | 112 | <span id="urn:enhancement-28cb4112-64cf-bd49-ef97-a2ee54727de7" class="textannotation disambiguated wl-thing" itemid="{dataset-uri}/entity/lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit">Lorem ipsum</span> dolor sit amet, consectetur adipiscing elit. Proin rutrum ultrices nulla ut elementum. Nunc nec lacus tortor. Curabitur bibendum imperdiet luctus. Vivamus a faucibus dolor. Donec blandit malesuada risus. Vestibulum volutpat ut tellus sed tincidunt. Sed id tincidunt velit. Integer sed felis id libero fringilla molestie vitae id orci. Ut vel purus ullamcorper, feugiat tortor non, iaculis neque. Vivamus vitae vehicula sem. Mauris fermentum, metus id vestibulum sodales, lorem lacus efficitur ante, non vestibulum ligula ligula a turpis. Vivamus quis scelerisque massa. |
113 | 113 | |
114 | 114 | [wl_navigator] |
@@ -123,242 +123,242 @@ discard block |
||
123 | 123 | |
124 | 124 | <span id="urn:local-text-annotation-v0kqdtx685n6cg9jrfvl67amkhm28hxh" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span>. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus. |
125 | 125 | ', |
126 | - 'post_type' => 'post', |
|
127 | - 'post_status' => 'publish', |
|
128 | - ), |
|
129 | - ), |
|
130 | - ); |
|
131 | - |
|
132 | - /** |
|
133 | - * The {@link Wordlift_Entity_Type_Service} instance. |
|
134 | - * |
|
135 | - * @since 3.12.0 |
|
136 | - * @access private |
|
137 | - * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
138 | - */ |
|
139 | - private $entity_type_service; |
|
140 | - |
|
141 | - /** |
|
142 | - * The {@link Wordlift_User_Service} instance. |
|
143 | - * |
|
144 | - * @since 3.16.0 |
|
145 | - * @access private |
|
146 | - * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
147 | - */ |
|
148 | - private $user_service; |
|
149 | - |
|
150 | - /** |
|
151 | - * Create a {@link Wordlift_Sample_Data_Service} instance. |
|
152 | - * |
|
153 | - * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
154 | - * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
155 | - * |
|
156 | - * @since 3.12.0 |
|
157 | - */ |
|
158 | - protected function __construct( $entity_type_service, $user_service ) { |
|
159 | - |
|
160 | - $this->entity_type_service = $entity_type_service; |
|
161 | - $this->user_service = $user_service; |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - private static $instance = null; |
|
166 | - |
|
167 | - public static function get_instance() { |
|
168 | - |
|
169 | - if ( ! isset( self::$instance ) ) { |
|
170 | - self::$instance = new self( Wordlift_Entity_Type_Service::get_instance(), Wordlift_User_Service::get_instance() ); |
|
171 | - } |
|
172 | - |
|
173 | - return self::$instance; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Create sample data in this WordPress instance. |
|
178 | - * |
|
179 | - * @since 3.12.0 |
|
180 | - */ |
|
181 | - public function create() { |
|
182 | - |
|
183 | - // Get the source image path. |
|
184 | - $source = plugin_dir_path( __DIR__ ) . 'images/rome.png'; |
|
185 | - |
|
186 | - // Create an attachment with the local file. |
|
187 | - $attachment_id = $this->create_attachment_from_local_file( $source ); |
|
188 | - |
|
189 | - // Add a flag to signal the attachment is sample data and allow easy delete |
|
190 | - // afterwards. |
|
191 | - add_post_meta( $attachment_id, '_wl_sample_data', 1, true ); |
|
192 | - |
|
193 | - // Get the dataset URI, used for replacements in the `post_content`. |
|
194 | - $dataset_uri = untrailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ); |
|
195 | - |
|
196 | - // Create the author and get its id. |
|
197 | - $author_id = $this->create_author(); |
|
198 | - |
|
199 | - // Create 4 entities. |
|
200 | - // Create 4 posts referencing each one entity. |
|
201 | - // Create 1 post referencing all the entities. |
|
202 | - foreach ( $this->samples as $sample ) { |
|
203 | - |
|
204 | - // Get the post data. |
|
205 | - $post = array_replace_recursive( |
|
206 | - $sample['post'], |
|
207 | - array( |
|
208 | - 'post_content' => str_replace( '{dataset-uri}', $dataset_uri, $sample['post']['post_content'] ), |
|
209 | - ) |
|
210 | - ); |
|
211 | - |
|
212 | - // Set the author. |
|
213 | - $post['post_author'] = $author_id; |
|
214 | - |
|
215 | - // Insert the post. |
|
216 | - $post_id = wp_insert_post( $post ); |
|
217 | - |
|
218 | - // Add a flag to signal the post is sample data and allow easy delete |
|
219 | - // afterwards. |
|
220 | - add_post_meta( $post_id, '_wl_sample_data', 1, true ); |
|
221 | - |
|
222 | - // Set the post thumbnail. |
|
223 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
224 | - |
|
225 | - // If the `entity_type_uri` property is set, set it on the post. |
|
226 | - if ( isset( $sample['entity_type_uri'] ) ) { |
|
227 | - $this->entity_type_service->set( $post_id, $sample['entity_type_uri'] ); |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Create an author to bind to posts. |
|
235 | - * |
|
236 | - * @return int The {@link WP_User}'s id. |
|
237 | - * @since 3.16.0 |
|
238 | - */ |
|
239 | - private function create_author() { |
|
240 | - |
|
241 | - $user_id = wp_create_user( 'wl-sample-data', wp_generate_password() ); |
|
242 | - $author_post_id = wp_insert_post( |
|
243 | - array( |
|
244 | - 'post_type' => 'entity', |
|
245 | - 'post_title' => 'WordLift Sample Data Person', |
|
246 | - ) |
|
247 | - ); |
|
248 | - // Add a flag to signal the attachment is sample data and allow easy delete |
|
249 | - // afterwards. |
|
250 | - add_post_meta( $author_post_id, '_wl_sample_data', 1, true ); |
|
251 | - |
|
252 | - $this->entity_type_service->set( $author_post_id, 'http://schema.org/Person' ); |
|
253 | - $this->user_service->set_entity( $user_id, $author_post_id ); |
|
254 | - |
|
255 | - return $user_id; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Remove the sample data from this WordPress instance. |
|
260 | - * |
|
261 | - * @since 3.12.0 |
|
262 | - */ |
|
263 | - public function delete() { |
|
264 | - |
|
265 | - $this->delete_by_type( 'post' ); |
|
266 | - $this->delete_by_type( 'entity' ); |
|
267 | - $this->delete_by_type( 'attachment' ); |
|
268 | - |
|
269 | - // Get and delete the user. |
|
270 | - $user = get_user_by( 'login', 'wl-sample-data' ); |
|
271 | - wp_delete_user( $user->ID ); |
|
272 | - |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Remove the sample data of the specified type (e.g. `post`, `entity`, `attachment`) |
|
277 | - * from the local WordPress instance. |
|
278 | - * |
|
279 | - * @param string $type WordPress {@link WP_Post}'s type, e.g. `post`, `entity`, `attachment`. |
|
280 | - * |
|
281 | - * @since 3.12.0 |
|
282 | - */ |
|
283 | - private function delete_by_type( $type ) { |
|
284 | - |
|
285 | - $posts = get_posts( |
|
286 | - array( |
|
287 | - 'meta_key' => '_wl_sample_data', |
|
288 | - 'meta_value' => 1, |
|
289 | - 'post_status' => 'any', |
|
290 | - 'post_type' => $type, |
|
291 | - ) |
|
292 | - ); |
|
293 | - |
|
294 | - foreach ( $posts as $post ) { |
|
295 | - wp_delete_post( $post->ID, true ); |
|
296 | - } |
|
297 | - |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Create a WordPress' attachment using the specified file. |
|
302 | - * |
|
303 | - * @param string $source The source file path. |
|
304 | - * |
|
305 | - * @return int WordPress' attachment's id. |
|
306 | - * @since 3.12.0 |
|
307 | - */ |
|
308 | - private function create_attachment_from_local_file( $source ) { |
|
309 | - |
|
310 | - // Get the path to the upload directory. |
|
311 | - $upload_dir = wp_upload_dir(); |
|
312 | - $upload_path = $upload_dir['path']; |
|
313 | - |
|
314 | - // Get the destination image path. |
|
315 | - $destination = $upload_path . '/wl-sample-data.png'; |
|
316 | - |
|
317 | - // Copy the source file to the destination. |
|
318 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
319 | - @copy( $source, $destination ); |
|
320 | - |
|
321 | - return $this->create_attachment( $destination ); |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Create a WordPress attachment using the specified file in the upload folder. |
|
326 | - * |
|
327 | - * @see https://codex.wordpress.org/Function_Reference/wp_insert_attachment |
|
328 | - * |
|
329 | - * @since 3.12.0 |
|
330 | - * |
|
331 | - * @param string $filename The image filename. |
|
332 | - * |
|
333 | - * @return int The attachment id. |
|
334 | - */ |
|
335 | - private function create_attachment( $filename ) { |
|
336 | - |
|
337 | - // Check the type of file. We'll use this as the 'post_mime_type'. |
|
338 | - $filetype = wp_check_filetype( basename( $filename ), null ); |
|
339 | - |
|
340 | - // Get the path to the upload directory. |
|
341 | - $wp_upload_dir = wp_upload_dir(); |
|
342 | - |
|
343 | - // Prepare an array of post data for the attachment. |
|
344 | - $attachment = array( |
|
345 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), |
|
346 | - 'post_mime_type' => $filetype['type'], |
|
347 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
348 | - 'post_content' => '', |
|
349 | - 'post_status' => 'inherit', |
|
350 | - ); |
|
351 | - |
|
352 | - // Insert the attachment. |
|
353 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
354 | - |
|
355 | - // Generate the metadata for the attachment, and update the database record. |
|
356 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
357 | - |
|
358 | - // Update the attachment metadata. |
|
359 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
360 | - |
|
361 | - return $attachment_id; |
|
362 | - } |
|
126 | + 'post_type' => 'post', |
|
127 | + 'post_status' => 'publish', |
|
128 | + ), |
|
129 | + ), |
|
130 | + ); |
|
131 | + |
|
132 | + /** |
|
133 | + * The {@link Wordlift_Entity_Type_Service} instance. |
|
134 | + * |
|
135 | + * @since 3.12.0 |
|
136 | + * @access private |
|
137 | + * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
138 | + */ |
|
139 | + private $entity_type_service; |
|
140 | + |
|
141 | + /** |
|
142 | + * The {@link Wordlift_User_Service} instance. |
|
143 | + * |
|
144 | + * @since 3.16.0 |
|
145 | + * @access private |
|
146 | + * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
147 | + */ |
|
148 | + private $user_service; |
|
149 | + |
|
150 | + /** |
|
151 | + * Create a {@link Wordlift_Sample_Data_Service} instance. |
|
152 | + * |
|
153 | + * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
154 | + * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
155 | + * |
|
156 | + * @since 3.12.0 |
|
157 | + */ |
|
158 | + protected function __construct( $entity_type_service, $user_service ) { |
|
159 | + |
|
160 | + $this->entity_type_service = $entity_type_service; |
|
161 | + $this->user_service = $user_service; |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + private static $instance = null; |
|
166 | + |
|
167 | + public static function get_instance() { |
|
168 | + |
|
169 | + if ( ! isset( self::$instance ) ) { |
|
170 | + self::$instance = new self( Wordlift_Entity_Type_Service::get_instance(), Wordlift_User_Service::get_instance() ); |
|
171 | + } |
|
172 | + |
|
173 | + return self::$instance; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Create sample data in this WordPress instance. |
|
178 | + * |
|
179 | + * @since 3.12.0 |
|
180 | + */ |
|
181 | + public function create() { |
|
182 | + |
|
183 | + // Get the source image path. |
|
184 | + $source = plugin_dir_path( __DIR__ ) . 'images/rome.png'; |
|
185 | + |
|
186 | + // Create an attachment with the local file. |
|
187 | + $attachment_id = $this->create_attachment_from_local_file( $source ); |
|
188 | + |
|
189 | + // Add a flag to signal the attachment is sample data and allow easy delete |
|
190 | + // afterwards. |
|
191 | + add_post_meta( $attachment_id, '_wl_sample_data', 1, true ); |
|
192 | + |
|
193 | + // Get the dataset URI, used for replacements in the `post_content`. |
|
194 | + $dataset_uri = untrailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ); |
|
195 | + |
|
196 | + // Create the author and get its id. |
|
197 | + $author_id = $this->create_author(); |
|
198 | + |
|
199 | + // Create 4 entities. |
|
200 | + // Create 4 posts referencing each one entity. |
|
201 | + // Create 1 post referencing all the entities. |
|
202 | + foreach ( $this->samples as $sample ) { |
|
203 | + |
|
204 | + // Get the post data. |
|
205 | + $post = array_replace_recursive( |
|
206 | + $sample['post'], |
|
207 | + array( |
|
208 | + 'post_content' => str_replace( '{dataset-uri}', $dataset_uri, $sample['post']['post_content'] ), |
|
209 | + ) |
|
210 | + ); |
|
211 | + |
|
212 | + // Set the author. |
|
213 | + $post['post_author'] = $author_id; |
|
214 | + |
|
215 | + // Insert the post. |
|
216 | + $post_id = wp_insert_post( $post ); |
|
217 | + |
|
218 | + // Add a flag to signal the post is sample data and allow easy delete |
|
219 | + // afterwards. |
|
220 | + add_post_meta( $post_id, '_wl_sample_data', 1, true ); |
|
221 | + |
|
222 | + // Set the post thumbnail. |
|
223 | + set_post_thumbnail( $post_id, $attachment_id ); |
|
224 | + |
|
225 | + // If the `entity_type_uri` property is set, set it on the post. |
|
226 | + if ( isset( $sample['entity_type_uri'] ) ) { |
|
227 | + $this->entity_type_service->set( $post_id, $sample['entity_type_uri'] ); |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Create an author to bind to posts. |
|
235 | + * |
|
236 | + * @return int The {@link WP_User}'s id. |
|
237 | + * @since 3.16.0 |
|
238 | + */ |
|
239 | + private function create_author() { |
|
240 | + |
|
241 | + $user_id = wp_create_user( 'wl-sample-data', wp_generate_password() ); |
|
242 | + $author_post_id = wp_insert_post( |
|
243 | + array( |
|
244 | + 'post_type' => 'entity', |
|
245 | + 'post_title' => 'WordLift Sample Data Person', |
|
246 | + ) |
|
247 | + ); |
|
248 | + // Add a flag to signal the attachment is sample data and allow easy delete |
|
249 | + // afterwards. |
|
250 | + add_post_meta( $author_post_id, '_wl_sample_data', 1, true ); |
|
251 | + |
|
252 | + $this->entity_type_service->set( $author_post_id, 'http://schema.org/Person' ); |
|
253 | + $this->user_service->set_entity( $user_id, $author_post_id ); |
|
254 | + |
|
255 | + return $user_id; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Remove the sample data from this WordPress instance. |
|
260 | + * |
|
261 | + * @since 3.12.0 |
|
262 | + */ |
|
263 | + public function delete() { |
|
264 | + |
|
265 | + $this->delete_by_type( 'post' ); |
|
266 | + $this->delete_by_type( 'entity' ); |
|
267 | + $this->delete_by_type( 'attachment' ); |
|
268 | + |
|
269 | + // Get and delete the user. |
|
270 | + $user = get_user_by( 'login', 'wl-sample-data' ); |
|
271 | + wp_delete_user( $user->ID ); |
|
272 | + |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Remove the sample data of the specified type (e.g. `post`, `entity`, `attachment`) |
|
277 | + * from the local WordPress instance. |
|
278 | + * |
|
279 | + * @param string $type WordPress {@link WP_Post}'s type, e.g. `post`, `entity`, `attachment`. |
|
280 | + * |
|
281 | + * @since 3.12.0 |
|
282 | + */ |
|
283 | + private function delete_by_type( $type ) { |
|
284 | + |
|
285 | + $posts = get_posts( |
|
286 | + array( |
|
287 | + 'meta_key' => '_wl_sample_data', |
|
288 | + 'meta_value' => 1, |
|
289 | + 'post_status' => 'any', |
|
290 | + 'post_type' => $type, |
|
291 | + ) |
|
292 | + ); |
|
293 | + |
|
294 | + foreach ( $posts as $post ) { |
|
295 | + wp_delete_post( $post->ID, true ); |
|
296 | + } |
|
297 | + |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Create a WordPress' attachment using the specified file. |
|
302 | + * |
|
303 | + * @param string $source The source file path. |
|
304 | + * |
|
305 | + * @return int WordPress' attachment's id. |
|
306 | + * @since 3.12.0 |
|
307 | + */ |
|
308 | + private function create_attachment_from_local_file( $source ) { |
|
309 | + |
|
310 | + // Get the path to the upload directory. |
|
311 | + $upload_dir = wp_upload_dir(); |
|
312 | + $upload_path = $upload_dir['path']; |
|
313 | + |
|
314 | + // Get the destination image path. |
|
315 | + $destination = $upload_path . '/wl-sample-data.png'; |
|
316 | + |
|
317 | + // Copy the source file to the destination. |
|
318 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
319 | + @copy( $source, $destination ); |
|
320 | + |
|
321 | + return $this->create_attachment( $destination ); |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Create a WordPress attachment using the specified file in the upload folder. |
|
326 | + * |
|
327 | + * @see https://codex.wordpress.org/Function_Reference/wp_insert_attachment |
|
328 | + * |
|
329 | + * @since 3.12.0 |
|
330 | + * |
|
331 | + * @param string $filename The image filename. |
|
332 | + * |
|
333 | + * @return int The attachment id. |
|
334 | + */ |
|
335 | + private function create_attachment( $filename ) { |
|
336 | + |
|
337 | + // Check the type of file. We'll use this as the 'post_mime_type'. |
|
338 | + $filetype = wp_check_filetype( basename( $filename ), null ); |
|
339 | + |
|
340 | + // Get the path to the upload directory. |
|
341 | + $wp_upload_dir = wp_upload_dir(); |
|
342 | + |
|
343 | + // Prepare an array of post data for the attachment. |
|
344 | + $attachment = array( |
|
345 | + 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), |
|
346 | + 'post_mime_type' => $filetype['type'], |
|
347 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
348 | + 'post_content' => '', |
|
349 | + 'post_status' => 'inherit', |
|
350 | + ); |
|
351 | + |
|
352 | + // Insert the attachment. |
|
353 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
354 | + |
|
355 | + // Generate the metadata for the attachment, and update the database record. |
|
356 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
357 | + |
|
358 | + // Update the attachment metadata. |
|
359 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
360 | + |
|
361 | + return $attachment_id; |
|
362 | + } |
|
363 | 363 | |
364 | 364 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @since 3.12.0 |
157 | 157 | */ |
158 | - protected function __construct( $entity_type_service, $user_service ) { |
|
158 | + protected function __construct($entity_type_service, $user_service) { |
|
159 | 159 | |
160 | 160 | $this->entity_type_service = $entity_type_service; |
161 | 161 | $this->user_service = $user_service; |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | |
167 | 167 | public static function get_instance() { |
168 | 168 | |
169 | - if ( ! isset( self::$instance ) ) { |
|
170 | - self::$instance = new self( Wordlift_Entity_Type_Service::get_instance(), Wordlift_User_Service::get_instance() ); |
|
169 | + if ( ! isset(self::$instance)) { |
|
170 | + self::$instance = new self(Wordlift_Entity_Type_Service::get_instance(), Wordlift_User_Service::get_instance()); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | return self::$instance; |
@@ -181,17 +181,17 @@ discard block |
||
181 | 181 | public function create() { |
182 | 182 | |
183 | 183 | // Get the source image path. |
184 | - $source = plugin_dir_path( __DIR__ ) . 'images/rome.png'; |
|
184 | + $source = plugin_dir_path(__DIR__).'images/rome.png'; |
|
185 | 185 | |
186 | 186 | // Create an attachment with the local file. |
187 | - $attachment_id = $this->create_attachment_from_local_file( $source ); |
|
187 | + $attachment_id = $this->create_attachment_from_local_file($source); |
|
188 | 188 | |
189 | 189 | // Add a flag to signal the attachment is sample data and allow easy delete |
190 | 190 | // afterwards. |
191 | - add_post_meta( $attachment_id, '_wl_sample_data', 1, true ); |
|
191 | + add_post_meta($attachment_id, '_wl_sample_data', 1, true); |
|
192 | 192 | |
193 | 193 | // Get the dataset URI, used for replacements in the `post_content`. |
194 | - $dataset_uri = untrailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ); |
|
194 | + $dataset_uri = untrailingslashit(Wordlift_Configuration_Service::get_instance()->get_dataset_uri()); |
|
195 | 195 | |
196 | 196 | // Create the author and get its id. |
197 | 197 | $author_id = $this->create_author(); |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | // Create 4 entities. |
200 | 200 | // Create 4 posts referencing each one entity. |
201 | 201 | // Create 1 post referencing all the entities. |
202 | - foreach ( $this->samples as $sample ) { |
|
202 | + foreach ($this->samples as $sample) { |
|
203 | 203 | |
204 | 204 | // Get the post data. |
205 | 205 | $post = array_replace_recursive( |
206 | 206 | $sample['post'], |
207 | 207 | array( |
208 | - 'post_content' => str_replace( '{dataset-uri}', $dataset_uri, $sample['post']['post_content'] ), |
|
208 | + 'post_content' => str_replace('{dataset-uri}', $dataset_uri, $sample['post']['post_content']), |
|
209 | 209 | ) |
210 | 210 | ); |
211 | 211 | |
@@ -213,18 +213,18 @@ discard block |
||
213 | 213 | $post['post_author'] = $author_id; |
214 | 214 | |
215 | 215 | // Insert the post. |
216 | - $post_id = wp_insert_post( $post ); |
|
216 | + $post_id = wp_insert_post($post); |
|
217 | 217 | |
218 | 218 | // Add a flag to signal the post is sample data and allow easy delete |
219 | 219 | // afterwards. |
220 | - add_post_meta( $post_id, '_wl_sample_data', 1, true ); |
|
220 | + add_post_meta($post_id, '_wl_sample_data', 1, true); |
|
221 | 221 | |
222 | 222 | // Set the post thumbnail. |
223 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
223 | + set_post_thumbnail($post_id, $attachment_id); |
|
224 | 224 | |
225 | 225 | // If the `entity_type_uri` property is set, set it on the post. |
226 | - if ( isset( $sample['entity_type_uri'] ) ) { |
|
227 | - $this->entity_type_service->set( $post_id, $sample['entity_type_uri'] ); |
|
226 | + if (isset($sample['entity_type_uri'])) { |
|
227 | + $this->entity_type_service->set($post_id, $sample['entity_type_uri']); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | private function create_author() { |
240 | 240 | |
241 | - $user_id = wp_create_user( 'wl-sample-data', wp_generate_password() ); |
|
241 | + $user_id = wp_create_user('wl-sample-data', wp_generate_password()); |
|
242 | 242 | $author_post_id = wp_insert_post( |
243 | 243 | array( |
244 | 244 | 'post_type' => 'entity', |
@@ -247,10 +247,10 @@ discard block |
||
247 | 247 | ); |
248 | 248 | // Add a flag to signal the attachment is sample data and allow easy delete |
249 | 249 | // afterwards. |
250 | - add_post_meta( $author_post_id, '_wl_sample_data', 1, true ); |
|
250 | + add_post_meta($author_post_id, '_wl_sample_data', 1, true); |
|
251 | 251 | |
252 | - $this->entity_type_service->set( $author_post_id, 'http://schema.org/Person' ); |
|
253 | - $this->user_service->set_entity( $user_id, $author_post_id ); |
|
252 | + $this->entity_type_service->set($author_post_id, 'http://schema.org/Person'); |
|
253 | + $this->user_service->set_entity($user_id, $author_post_id); |
|
254 | 254 | |
255 | 255 | return $user_id; |
256 | 256 | } |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public function delete() { |
264 | 264 | |
265 | - $this->delete_by_type( 'post' ); |
|
266 | - $this->delete_by_type( 'entity' ); |
|
267 | - $this->delete_by_type( 'attachment' ); |
|
265 | + $this->delete_by_type('post'); |
|
266 | + $this->delete_by_type('entity'); |
|
267 | + $this->delete_by_type('attachment'); |
|
268 | 268 | |
269 | 269 | // Get and delete the user. |
270 | - $user = get_user_by( 'login', 'wl-sample-data' ); |
|
271 | - wp_delete_user( $user->ID ); |
|
270 | + $user = get_user_by('login', 'wl-sample-data'); |
|
271 | + wp_delete_user($user->ID); |
|
272 | 272 | |
273 | 273 | } |
274 | 274 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @since 3.12.0 |
282 | 282 | */ |
283 | - private function delete_by_type( $type ) { |
|
283 | + private function delete_by_type($type) { |
|
284 | 284 | |
285 | 285 | $posts = get_posts( |
286 | 286 | array( |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | ) |
292 | 292 | ); |
293 | 293 | |
294 | - foreach ( $posts as $post ) { |
|
295 | - wp_delete_post( $post->ID, true ); |
|
294 | + foreach ($posts as $post) { |
|
295 | + wp_delete_post($post->ID, true); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | } |
@@ -305,20 +305,20 @@ discard block |
||
305 | 305 | * @return int WordPress' attachment's id. |
306 | 306 | * @since 3.12.0 |
307 | 307 | */ |
308 | - private function create_attachment_from_local_file( $source ) { |
|
308 | + private function create_attachment_from_local_file($source) { |
|
309 | 309 | |
310 | 310 | // Get the path to the upload directory. |
311 | 311 | $upload_dir = wp_upload_dir(); |
312 | 312 | $upload_path = $upload_dir['path']; |
313 | 313 | |
314 | 314 | // Get the destination image path. |
315 | - $destination = $upload_path . '/wl-sample-data.png'; |
|
315 | + $destination = $upload_path.'/wl-sample-data.png'; |
|
316 | 316 | |
317 | 317 | // Copy the source file to the destination. |
318 | 318 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
319 | - @copy( $source, $destination ); |
|
319 | + @copy($source, $destination); |
|
320 | 320 | |
321 | - return $this->create_attachment( $destination ); |
|
321 | + return $this->create_attachment($destination); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -332,31 +332,31 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @return int The attachment id. |
334 | 334 | */ |
335 | - private function create_attachment( $filename ) { |
|
335 | + private function create_attachment($filename) { |
|
336 | 336 | |
337 | 337 | // Check the type of file. We'll use this as the 'post_mime_type'. |
338 | - $filetype = wp_check_filetype( basename( $filename ), null ); |
|
338 | + $filetype = wp_check_filetype(basename($filename), null); |
|
339 | 339 | |
340 | 340 | // Get the path to the upload directory. |
341 | 341 | $wp_upload_dir = wp_upload_dir(); |
342 | 342 | |
343 | 343 | // Prepare an array of post data for the attachment. |
344 | 344 | $attachment = array( |
345 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), |
|
345 | + 'guid' => $wp_upload_dir['url'].'/'.basename($filename), |
|
346 | 346 | 'post_mime_type' => $filetype['type'], |
347 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
347 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
348 | 348 | 'post_content' => '', |
349 | 349 | 'post_status' => 'inherit', |
350 | 350 | ); |
351 | 351 | |
352 | 352 | // Insert the attachment. |
353 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
353 | + $attachment_id = wp_insert_attachment($attachment, $filename); |
|
354 | 354 | |
355 | 355 | // Generate the metadata for the attachment, and update the database record. |
356 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
356 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
357 | 357 | |
358 | 358 | // Update the attachment metadata. |
359 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
359 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
360 | 360 | |
361 | 361 | return $attachment_id; |
362 | 362 | } |
@@ -23,257 +23,257 @@ |
||
23 | 23 | */ |
24 | 24 | class Wordlift_Content_Filter_Service { |
25 | 25 | |
26 | - /** |
|
27 | - * The pattern to find entities in text. |
|
28 | - * |
|
29 | - * @since 3.8.0 |
|
30 | - */ |
|
31 | - const PATTERN = '/<(\\w+)[^<]*class="([^"]*)"\\sitemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i'; |
|
32 | - |
|
33 | - /** |
|
34 | - * A {@link Wordlift_Entity_Service} instance. |
|
35 | - * |
|
36 | - * @since 3.8.0 |
|
37 | - * @access private |
|
38 | - * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
39 | - */ |
|
40 | - private $entity_service; |
|
41 | - |
|
42 | - /** |
|
43 | - * The `link by default` setting. |
|
44 | - * |
|
45 | - * @since 3.13.0 |
|
46 | - * @access private |
|
47 | - * @var bool True if link by default is enabled otherwise false. |
|
48 | - */ |
|
49 | - private $is_link_by_default; |
|
50 | - |
|
51 | - private $linked_entity_uris = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * The {@link Wordlift_Entity_Uri_Service} instance. |
|
55 | - * |
|
56 | - * @since 3.16.3 |
|
57 | - * @access private |
|
58 | - * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
59 | - */ |
|
60 | - private $entity_uri_service; |
|
61 | - |
|
62 | - /** |
|
63 | - * A {@link Wordlift_Log_Service} instance. |
|
64 | - * |
|
65 | - * @since 3.16.0 |
|
66 | - * |
|
67 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
68 | - */ |
|
69 | - private $log; |
|
70 | - /** |
|
71 | - * @var Object_Link_Provider |
|
72 | - */ |
|
73 | - private $object_link_provider; |
|
74 | - |
|
75 | - /** |
|
76 | - * Create a {@link Wordlift_Content_Filter_Service} instance. |
|
77 | - * |
|
78 | - * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
79 | - * @param \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
80 | - * |
|
81 | - * @since 3.8.0 |
|
82 | - */ |
|
83 | - protected function __construct( $entity_service, $entity_uri_service ) { |
|
84 | - |
|
85 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
86 | - |
|
87 | - $this->entity_service = $entity_service; |
|
88 | - $this->entity_uri_service = $entity_uri_service; |
|
89 | - $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - private static $instance = null; |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the {@link Wordlift_Content_Filter_Service} singleton instance. |
|
97 | - * |
|
98 | - * @return \Wordlift_Content_Filter_Service The {@link Wordlift_Content_Filter_Service} singleton instance. |
|
99 | - * @since 3.14.2 |
|
100 | - */ |
|
101 | - public static function get_instance() { |
|
102 | - |
|
103 | - if ( ! isset( self::$instance ) ) { |
|
104 | - self::$instance = new self( Wordlift_Entity_Service::get_instance(), Wordlift_Entity_Uri_Service::get_instance() ); |
|
105 | - } |
|
106 | - |
|
107 | - return self::$instance; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Mangle the content by adding links to the entity pages. This function is |
|
112 | - * hooked to the 'the_content' WP's filter. |
|
113 | - * |
|
114 | - * @param string $content The content being filtered. |
|
115 | - * |
|
116 | - * @return string The filtered content. |
|
117 | - * @since 3.8.0 |
|
118 | - */ |
|
119 | - public function the_content( $content ) { |
|
120 | - $this->log->trace( 'Filtering content [ ' . ( is_singular() ? 'yes' : 'no' ) . ' ]...' ); |
|
121 | - |
|
122 | - // Links should be added only on the front end and not for RSS. |
|
123 | - if ( is_feed() || is_admin() || is_search() ) { |
|
124 | - return $content; |
|
125 | - } |
|
126 | - |
|
127 | - // Preload the `link by default` setting. |
|
128 | - $this->is_link_by_default = Wordlift_Configuration_Service::get_instance()->is_link_by_default(); |
|
129 | - |
|
130 | - // Reset the array of of entity post ids linked from the post content. |
|
131 | - // This is used to avoid linking more the once the same post. |
|
132 | - $this->linked_entity_uris = array(); |
|
133 | - |
|
134 | - // Preload URIs. |
|
135 | - $matches = array(); |
|
136 | - preg_match_all( self::PATTERN, $content, $matches ); |
|
137 | - |
|
138 | - // Bail out if there are no URIs. |
|
139 | - if ( empty( $matches[3] ) ) { |
|
140 | - return $content; |
|
141 | - } |
|
142 | - |
|
143 | - // Replace each match of the entity tag with the entity link. If an error |
|
144 | - // occurs fail silently returning the original content. |
|
145 | - $maybe_content = preg_replace_callback( |
|
146 | - self::PATTERN, |
|
147 | - array( |
|
148 | - $this, |
|
149 | - 'link', |
|
150 | - ), |
|
151 | - $content |
|
152 | - ); |
|
153 | - |
|
154 | - return $maybe_content ? $maybe_content : $content; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Get the entity match and replace it with a page link. |
|
159 | - * |
|
160 | - * @param array $matches An array of matches. |
|
161 | - * |
|
162 | - * @return string The replaced text with the link to the entity page. |
|
163 | - * @since 3.8.0 |
|
164 | - */ |
|
165 | - private function link( $matches ) { |
|
166 | - |
|
167 | - // Get the entity itemid URI and label. |
|
168 | - $css_class = $matches[2]; |
|
169 | - $uri = $matches[3]; |
|
170 | - $label = $matches[4]; |
|
171 | - |
|
172 | - /** |
|
173 | - * If the entity is already linked, dont send query to the db. |
|
174 | - */ |
|
175 | - if ( $this->is_already_linked( $uri ) ) { |
|
176 | - return $label; |
|
177 | - } |
|
178 | - |
|
179 | - $link = - 1 < strpos( $css_class, 'wl-link' ); |
|
180 | - |
|
181 | - // If the entity should not be linked and link by default is also disabled, |
|
182 | - // then don't lookup the entity on the table. |
|
183 | - if ( ! $this->is_link_by_default && ! $link ) { |
|
184 | - return $label; |
|
185 | - } |
|
186 | - |
|
187 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
188 | - $content = $content_service->get_by_entity_id_or_same_as( $uri ); |
|
189 | - |
|
190 | - // If no content is found, return the label, that is _remove the annotation_. |
|
191 | - if ( ! is_object( $content ) ) { |
|
192 | - return $label; |
|
193 | - } |
|
194 | - |
|
195 | - $object_id = $content->get_id(); |
|
196 | - $object_type = $content->get_object_type_enum(); |
|
197 | - |
|
198 | - $no_link = - 1 < strpos( $css_class, 'wl-no-link' ); |
|
199 | - |
|
200 | - // Don't link if links are disabled and the entity is not link or the |
|
201 | - // entity is do not link. |
|
202 | - $dont_link = ( ! $this->is_link_by_default && ! $link ) || $no_link; |
|
203 | - |
|
204 | - // Return the label if it's don't link. |
|
205 | - if ( $dont_link ) { |
|
206 | - return $label; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @since 3.32.0 |
|
211 | - * Object_ids are prefixed with object_type to prevent conflicts. |
|
212 | - */ |
|
213 | - $this->linked_entity_uris[] = $uri; |
|
214 | - |
|
215 | - // Get the link. |
|
216 | - $href = Wordlift_Post_Adapter::get_production_permalink( $object_id, $object_type ); |
|
217 | - |
|
218 | - // Bail out if the `$href` has been reset. |
|
219 | - if ( empty( $href ) ) { |
|
220 | - return $label; |
|
221 | - } |
|
222 | - |
|
223 | - return Link_Builder::create( $uri, $object_id ) |
|
224 | - ->label( $label ) |
|
225 | - ->href( $href ) |
|
226 | - ->generate_link(); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Get a string to be used as a title attribute in links to a post |
|
231 | - * |
|
232 | - * @param int $post_id The post id of the post being linked. |
|
233 | - * @param string $ignore_label A label to ignore. |
|
234 | - * |
|
235 | - * @return string The title to be used in the link. An empty string when |
|
236 | - * there is no alternative that is not the $ignore_label. |
|
237 | - * @deprecated 3.32.0 Use object link provider to get the link title for getting link |
|
238 | - * title for different types. |
|
239 | - * @since 3.15.0 |
|
240 | - * |
|
241 | - * As of 3.32.0 this method is not used anywhere in the core, this should be removed |
|
242 | - * from tests and companion plugins. |
|
243 | - */ |
|
244 | - public function get_link_title( $post_id, $ignore_label, $object_type = Object_Type_Enum::POST ) { |
|
245 | - return $this->object_link_provider->get_link_title( $post_id, $ignore_label, $object_type ); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Get the entity URIs (configured in the `itemid` attribute) contained in |
|
250 | - * the provided content. |
|
251 | - * |
|
252 | - * @param string $content The content. |
|
253 | - * |
|
254 | - * @return array An array of URIs. |
|
255 | - * @since 3.14.2 |
|
256 | - */ |
|
257 | - public function get_entity_uris( $content ) { |
|
258 | - |
|
259 | - $matches = array(); |
|
260 | - preg_match_all( self::PATTERN, $content, $matches ); |
|
261 | - |
|
262 | - // We need to use `array_values` here in order to avoid further `json_encode` |
|
263 | - // to turn it into an object (since if the 3rd match isn't found the index |
|
264 | - // is not sequential. |
|
265 | - // |
|
266 | - // See https://github.com/insideout10/wordlift-plugin/issues/646. |
|
267 | - return array_values( array_unique( $matches[3] ) ); |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * @param $entity_uri |
|
272 | - * |
|
273 | - * @return bool |
|
274 | - */ |
|
275 | - private function is_already_linked( $entity_uri ) { |
|
276 | - return in_array( $entity_uri, $this->linked_entity_uris, true ); |
|
277 | - } |
|
26 | + /** |
|
27 | + * The pattern to find entities in text. |
|
28 | + * |
|
29 | + * @since 3.8.0 |
|
30 | + */ |
|
31 | + const PATTERN = '/<(\\w+)[^<]*class="([^"]*)"\\sitemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i'; |
|
32 | + |
|
33 | + /** |
|
34 | + * A {@link Wordlift_Entity_Service} instance. |
|
35 | + * |
|
36 | + * @since 3.8.0 |
|
37 | + * @access private |
|
38 | + * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
39 | + */ |
|
40 | + private $entity_service; |
|
41 | + |
|
42 | + /** |
|
43 | + * The `link by default` setting. |
|
44 | + * |
|
45 | + * @since 3.13.0 |
|
46 | + * @access private |
|
47 | + * @var bool True if link by default is enabled otherwise false. |
|
48 | + */ |
|
49 | + private $is_link_by_default; |
|
50 | + |
|
51 | + private $linked_entity_uris = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * The {@link Wordlift_Entity_Uri_Service} instance. |
|
55 | + * |
|
56 | + * @since 3.16.3 |
|
57 | + * @access private |
|
58 | + * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
59 | + */ |
|
60 | + private $entity_uri_service; |
|
61 | + |
|
62 | + /** |
|
63 | + * A {@link Wordlift_Log_Service} instance. |
|
64 | + * |
|
65 | + * @since 3.16.0 |
|
66 | + * |
|
67 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
68 | + */ |
|
69 | + private $log; |
|
70 | + /** |
|
71 | + * @var Object_Link_Provider |
|
72 | + */ |
|
73 | + private $object_link_provider; |
|
74 | + |
|
75 | + /** |
|
76 | + * Create a {@link Wordlift_Content_Filter_Service} instance. |
|
77 | + * |
|
78 | + * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
79 | + * @param \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance. |
|
80 | + * |
|
81 | + * @since 3.8.0 |
|
82 | + */ |
|
83 | + protected function __construct( $entity_service, $entity_uri_service ) { |
|
84 | + |
|
85 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
86 | + |
|
87 | + $this->entity_service = $entity_service; |
|
88 | + $this->entity_uri_service = $entity_uri_service; |
|
89 | + $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + private static $instance = null; |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the {@link Wordlift_Content_Filter_Service} singleton instance. |
|
97 | + * |
|
98 | + * @return \Wordlift_Content_Filter_Service The {@link Wordlift_Content_Filter_Service} singleton instance. |
|
99 | + * @since 3.14.2 |
|
100 | + */ |
|
101 | + public static function get_instance() { |
|
102 | + |
|
103 | + if ( ! isset( self::$instance ) ) { |
|
104 | + self::$instance = new self( Wordlift_Entity_Service::get_instance(), Wordlift_Entity_Uri_Service::get_instance() ); |
|
105 | + } |
|
106 | + |
|
107 | + return self::$instance; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Mangle the content by adding links to the entity pages. This function is |
|
112 | + * hooked to the 'the_content' WP's filter. |
|
113 | + * |
|
114 | + * @param string $content The content being filtered. |
|
115 | + * |
|
116 | + * @return string The filtered content. |
|
117 | + * @since 3.8.0 |
|
118 | + */ |
|
119 | + public function the_content( $content ) { |
|
120 | + $this->log->trace( 'Filtering content [ ' . ( is_singular() ? 'yes' : 'no' ) . ' ]...' ); |
|
121 | + |
|
122 | + // Links should be added only on the front end and not for RSS. |
|
123 | + if ( is_feed() || is_admin() || is_search() ) { |
|
124 | + return $content; |
|
125 | + } |
|
126 | + |
|
127 | + // Preload the `link by default` setting. |
|
128 | + $this->is_link_by_default = Wordlift_Configuration_Service::get_instance()->is_link_by_default(); |
|
129 | + |
|
130 | + // Reset the array of of entity post ids linked from the post content. |
|
131 | + // This is used to avoid linking more the once the same post. |
|
132 | + $this->linked_entity_uris = array(); |
|
133 | + |
|
134 | + // Preload URIs. |
|
135 | + $matches = array(); |
|
136 | + preg_match_all( self::PATTERN, $content, $matches ); |
|
137 | + |
|
138 | + // Bail out if there are no URIs. |
|
139 | + if ( empty( $matches[3] ) ) { |
|
140 | + return $content; |
|
141 | + } |
|
142 | + |
|
143 | + // Replace each match of the entity tag with the entity link. If an error |
|
144 | + // occurs fail silently returning the original content. |
|
145 | + $maybe_content = preg_replace_callback( |
|
146 | + self::PATTERN, |
|
147 | + array( |
|
148 | + $this, |
|
149 | + 'link', |
|
150 | + ), |
|
151 | + $content |
|
152 | + ); |
|
153 | + |
|
154 | + return $maybe_content ? $maybe_content : $content; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Get the entity match and replace it with a page link. |
|
159 | + * |
|
160 | + * @param array $matches An array of matches. |
|
161 | + * |
|
162 | + * @return string The replaced text with the link to the entity page. |
|
163 | + * @since 3.8.0 |
|
164 | + */ |
|
165 | + private function link( $matches ) { |
|
166 | + |
|
167 | + // Get the entity itemid URI and label. |
|
168 | + $css_class = $matches[2]; |
|
169 | + $uri = $matches[3]; |
|
170 | + $label = $matches[4]; |
|
171 | + |
|
172 | + /** |
|
173 | + * If the entity is already linked, dont send query to the db. |
|
174 | + */ |
|
175 | + if ( $this->is_already_linked( $uri ) ) { |
|
176 | + return $label; |
|
177 | + } |
|
178 | + |
|
179 | + $link = - 1 < strpos( $css_class, 'wl-link' ); |
|
180 | + |
|
181 | + // If the entity should not be linked and link by default is also disabled, |
|
182 | + // then don't lookup the entity on the table. |
|
183 | + if ( ! $this->is_link_by_default && ! $link ) { |
|
184 | + return $label; |
|
185 | + } |
|
186 | + |
|
187 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
188 | + $content = $content_service->get_by_entity_id_or_same_as( $uri ); |
|
189 | + |
|
190 | + // If no content is found, return the label, that is _remove the annotation_. |
|
191 | + if ( ! is_object( $content ) ) { |
|
192 | + return $label; |
|
193 | + } |
|
194 | + |
|
195 | + $object_id = $content->get_id(); |
|
196 | + $object_type = $content->get_object_type_enum(); |
|
197 | + |
|
198 | + $no_link = - 1 < strpos( $css_class, 'wl-no-link' ); |
|
199 | + |
|
200 | + // Don't link if links are disabled and the entity is not link or the |
|
201 | + // entity is do not link. |
|
202 | + $dont_link = ( ! $this->is_link_by_default && ! $link ) || $no_link; |
|
203 | + |
|
204 | + // Return the label if it's don't link. |
|
205 | + if ( $dont_link ) { |
|
206 | + return $label; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @since 3.32.0 |
|
211 | + * Object_ids are prefixed with object_type to prevent conflicts. |
|
212 | + */ |
|
213 | + $this->linked_entity_uris[] = $uri; |
|
214 | + |
|
215 | + // Get the link. |
|
216 | + $href = Wordlift_Post_Adapter::get_production_permalink( $object_id, $object_type ); |
|
217 | + |
|
218 | + // Bail out if the `$href` has been reset. |
|
219 | + if ( empty( $href ) ) { |
|
220 | + return $label; |
|
221 | + } |
|
222 | + |
|
223 | + return Link_Builder::create( $uri, $object_id ) |
|
224 | + ->label( $label ) |
|
225 | + ->href( $href ) |
|
226 | + ->generate_link(); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Get a string to be used as a title attribute in links to a post |
|
231 | + * |
|
232 | + * @param int $post_id The post id of the post being linked. |
|
233 | + * @param string $ignore_label A label to ignore. |
|
234 | + * |
|
235 | + * @return string The title to be used in the link. An empty string when |
|
236 | + * there is no alternative that is not the $ignore_label. |
|
237 | + * @deprecated 3.32.0 Use object link provider to get the link title for getting link |
|
238 | + * title for different types. |
|
239 | + * @since 3.15.0 |
|
240 | + * |
|
241 | + * As of 3.32.0 this method is not used anywhere in the core, this should be removed |
|
242 | + * from tests and companion plugins. |
|
243 | + */ |
|
244 | + public function get_link_title( $post_id, $ignore_label, $object_type = Object_Type_Enum::POST ) { |
|
245 | + return $this->object_link_provider->get_link_title( $post_id, $ignore_label, $object_type ); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Get the entity URIs (configured in the `itemid` attribute) contained in |
|
250 | + * the provided content. |
|
251 | + * |
|
252 | + * @param string $content The content. |
|
253 | + * |
|
254 | + * @return array An array of URIs. |
|
255 | + * @since 3.14.2 |
|
256 | + */ |
|
257 | + public function get_entity_uris( $content ) { |
|
258 | + |
|
259 | + $matches = array(); |
|
260 | + preg_match_all( self::PATTERN, $content, $matches ); |
|
261 | + |
|
262 | + // We need to use `array_values` here in order to avoid further `json_encode` |
|
263 | + // to turn it into an object (since if the 3rd match isn't found the index |
|
264 | + // is not sequential. |
|
265 | + // |
|
266 | + // See https://github.com/insideout10/wordlift-plugin/issues/646. |
|
267 | + return array_values( array_unique( $matches[3] ) ); |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * @param $entity_uri |
|
272 | + * |
|
273 | + * @return bool |
|
274 | + */ |
|
275 | + private function is_already_linked( $entity_uri ) { |
|
276 | + return in_array( $entity_uri, $this->linked_entity_uris, true ); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @since 3.8.0 |
82 | 82 | */ |
83 | - protected function __construct( $entity_service, $entity_uri_service ) { |
|
83 | + protected function __construct($entity_service, $entity_uri_service) { |
|
84 | 84 | |
85 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
85 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
86 | 86 | |
87 | 87 | $this->entity_service = $entity_service; |
88 | 88 | $this->entity_uri_service = $entity_uri_service; |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public static function get_instance() { |
102 | 102 | |
103 | - if ( ! isset( self::$instance ) ) { |
|
104 | - self::$instance = new self( Wordlift_Entity_Service::get_instance(), Wordlift_Entity_Uri_Service::get_instance() ); |
|
103 | + if ( ! isset(self::$instance)) { |
|
104 | + self::$instance = new self(Wordlift_Entity_Service::get_instance(), Wordlift_Entity_Uri_Service::get_instance()); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return self::$instance; |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | * @return string The filtered content. |
117 | 117 | * @since 3.8.0 |
118 | 118 | */ |
119 | - public function the_content( $content ) { |
|
120 | - $this->log->trace( 'Filtering content [ ' . ( is_singular() ? 'yes' : 'no' ) . ' ]...' ); |
|
119 | + public function the_content($content) { |
|
120 | + $this->log->trace('Filtering content [ '.(is_singular() ? 'yes' : 'no').' ]...'); |
|
121 | 121 | |
122 | 122 | // Links should be added only on the front end and not for RSS. |
123 | - if ( is_feed() || is_admin() || is_search() ) { |
|
123 | + if (is_feed() || is_admin() || is_search()) { |
|
124 | 124 | return $content; |
125 | 125 | } |
126 | 126 | |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | |
134 | 134 | // Preload URIs. |
135 | 135 | $matches = array(); |
136 | - preg_match_all( self::PATTERN, $content, $matches ); |
|
136 | + preg_match_all(self::PATTERN, $content, $matches); |
|
137 | 137 | |
138 | 138 | // Bail out if there are no URIs. |
139 | - if ( empty( $matches[3] ) ) { |
|
139 | + if (empty($matches[3])) { |
|
140 | 140 | return $content; |
141 | 141 | } |
142 | 142 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @return string The replaced text with the link to the entity page. |
163 | 163 | * @since 3.8.0 |
164 | 164 | */ |
165 | - private function link( $matches ) { |
|
165 | + private function link($matches) { |
|
166 | 166 | |
167 | 167 | // Get the entity itemid URI and label. |
168 | 168 | $css_class = $matches[2]; |
@@ -172,37 +172,37 @@ discard block |
||
172 | 172 | /** |
173 | 173 | * If the entity is already linked, dont send query to the db. |
174 | 174 | */ |
175 | - if ( $this->is_already_linked( $uri ) ) { |
|
175 | + if ($this->is_already_linked($uri)) { |
|
176 | 176 | return $label; |
177 | 177 | } |
178 | 178 | |
179 | - $link = - 1 < strpos( $css_class, 'wl-link' ); |
|
179 | + $link = - 1 < strpos($css_class, 'wl-link'); |
|
180 | 180 | |
181 | 181 | // If the entity should not be linked and link by default is also disabled, |
182 | 182 | // then don't lookup the entity on the table. |
183 | - if ( ! $this->is_link_by_default && ! $link ) { |
|
183 | + if ( ! $this->is_link_by_default && ! $link) { |
|
184 | 184 | return $label; |
185 | 185 | } |
186 | 186 | |
187 | 187 | $content_service = Wordpress_Content_Service::get_instance(); |
188 | - $content = $content_service->get_by_entity_id_or_same_as( $uri ); |
|
188 | + $content = $content_service->get_by_entity_id_or_same_as($uri); |
|
189 | 189 | |
190 | 190 | // If no content is found, return the label, that is _remove the annotation_. |
191 | - if ( ! is_object( $content ) ) { |
|
191 | + if ( ! is_object($content)) { |
|
192 | 192 | return $label; |
193 | 193 | } |
194 | 194 | |
195 | 195 | $object_id = $content->get_id(); |
196 | 196 | $object_type = $content->get_object_type_enum(); |
197 | 197 | |
198 | - $no_link = - 1 < strpos( $css_class, 'wl-no-link' ); |
|
198 | + $no_link = - 1 < strpos($css_class, 'wl-no-link'); |
|
199 | 199 | |
200 | 200 | // Don't link if links are disabled and the entity is not link or the |
201 | 201 | // entity is do not link. |
202 | - $dont_link = ( ! $this->is_link_by_default && ! $link ) || $no_link; |
|
202 | + $dont_link = ( ! $this->is_link_by_default && ! $link) || $no_link; |
|
203 | 203 | |
204 | 204 | // Return the label if it's don't link. |
205 | - if ( $dont_link ) { |
|
205 | + if ($dont_link) { |
|
206 | 206 | return $label; |
207 | 207 | } |
208 | 208 | |
@@ -213,16 +213,16 @@ discard block |
||
213 | 213 | $this->linked_entity_uris[] = $uri; |
214 | 214 | |
215 | 215 | // Get the link. |
216 | - $href = Wordlift_Post_Adapter::get_production_permalink( $object_id, $object_type ); |
|
216 | + $href = Wordlift_Post_Adapter::get_production_permalink($object_id, $object_type); |
|
217 | 217 | |
218 | 218 | // Bail out if the `$href` has been reset. |
219 | - if ( empty( $href ) ) { |
|
219 | + if (empty($href)) { |
|
220 | 220 | return $label; |
221 | 221 | } |
222 | 222 | |
223 | - return Link_Builder::create( $uri, $object_id ) |
|
224 | - ->label( $label ) |
|
225 | - ->href( $href ) |
|
223 | + return Link_Builder::create($uri, $object_id) |
|
224 | + ->label($label) |
|
225 | + ->href($href) |
|
226 | 226 | ->generate_link(); |
227 | 227 | } |
228 | 228 | |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * As of 3.32.0 this method is not used anywhere in the core, this should be removed |
242 | 242 | * from tests and companion plugins. |
243 | 243 | */ |
244 | - public function get_link_title( $post_id, $ignore_label, $object_type = Object_Type_Enum::POST ) { |
|
245 | - return $this->object_link_provider->get_link_title( $post_id, $ignore_label, $object_type ); |
|
244 | + public function get_link_title($post_id, $ignore_label, $object_type = Object_Type_Enum::POST) { |
|
245 | + return $this->object_link_provider->get_link_title($post_id, $ignore_label, $object_type); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -254,17 +254,17 @@ discard block |
||
254 | 254 | * @return array An array of URIs. |
255 | 255 | * @since 3.14.2 |
256 | 256 | */ |
257 | - public function get_entity_uris( $content ) { |
|
257 | + public function get_entity_uris($content) { |
|
258 | 258 | |
259 | 259 | $matches = array(); |
260 | - preg_match_all( self::PATTERN, $content, $matches ); |
|
260 | + preg_match_all(self::PATTERN, $content, $matches); |
|
261 | 261 | |
262 | 262 | // We need to use `array_values` here in order to avoid further `json_encode` |
263 | 263 | // to turn it into an object (since if the 3rd match isn't found the index |
264 | 264 | // is not sequential. |
265 | 265 | // |
266 | 266 | // See https://github.com/insideout10/wordlift-plugin/issues/646. |
267 | - return array_values( array_unique( $matches[3] ) ); |
|
267 | + return array_values(array_unique($matches[3])); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return bool |
274 | 274 | */ |
275 | - private function is_already_linked( $entity_uri ) { |
|
276 | - return in_array( $entity_uri, $this->linked_entity_uris, true ); |
|
275 | + private function is_already_linked($entity_uri) { |
|
276 | + return in_array($entity_uri, $this->linked_entity_uris, true); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | } |
@@ -19,522 +19,522 @@ |
||
19 | 19 | */ |
20 | 20 | class Wordlift_Post_To_Jsonld_Converter extends Wordlift_Abstract_Post_To_Jsonld_Converter { |
21 | 21 | |
22 | - /** |
|
23 | - * @var Wordlift_Post_To_Jsonld_Converter |
|
24 | - */ |
|
25 | - private static $instance; |
|
26 | - |
|
27 | - /** |
|
28 | - * A {@link Wordlift_Log_Service} instance. |
|
29 | - * |
|
30 | - * @since 3.10.0 |
|
31 | - * @access private |
|
32 | - * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
33 | - */ |
|
34 | - private $log; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var false |
|
38 | - */ |
|
39 | - private $disable_convert_filters; |
|
40 | - /** |
|
41 | - * @var Object_Relation_Service |
|
42 | - */ |
|
43 | - private $object_relation_service; |
|
44 | - |
|
45 | - /** |
|
46 | - * Wordlift_Post_To_Jsonld_Converter constructor. |
|
47 | - * |
|
48 | - * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
49 | - * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
50 | - * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
51 | - * |
|
52 | - * @since 3.10.0 |
|
53 | - */ |
|
54 | - public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) { |
|
55 | - parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() ); |
|
56 | - $this->disable_convert_filters = $disable_convert_filters; |
|
57 | - $this->object_relation_service = Object_Relation_Service::get_instance(); |
|
58 | - // Set a reference to the logger. |
|
59 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
60 | - |
|
61 | - self::$instance = $this; |
|
62 | - |
|
63 | - } |
|
64 | - |
|
65 | - public static function get_instance() { |
|
66 | - |
|
67 | - return self::$instance; |
|
68 | - } |
|
69 | - |
|
70 | - public function new_instance_with_filters_disabled() { |
|
71 | - return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
76 | - * found while processing the post is set in the $references array. |
|
77 | - * |
|
78 | - * @param int $post_id The post id. |
|
79 | - * @param array<Reference> $references An array of entity references. |
|
80 | - * @param array $references_infos |
|
81 | - * |
|
82 | - * @return array A JSON-LD array. |
|
83 | - * @since 3.10.0 |
|
84 | - */ |
|
85 | - public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
86 | - |
|
87 | - // Get the post instance. |
|
88 | - $post = get_post( $post_id ); |
|
89 | - if ( null === $post ) { |
|
90 | - // Post not found. |
|
91 | - return null; |
|
92 | - } |
|
93 | - |
|
94 | - // Get the base JSON-LD and the list of entities referenced by this entity. |
|
95 | - $jsonld = parent::convert( $post_id, $references, $references_infos ); |
|
96 | - |
|
97 | - // Set WebPage by default. |
|
98 | - if ( empty( $jsonld['@type'] ) ) { |
|
99 | - $jsonld['@type'] = 'WebPage'; |
|
100 | - } |
|
101 | - |
|
102 | - // Get the entity name. |
|
103 | - $jsonld['headline'] = $post->post_title; |
|
104 | - |
|
105 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id ); |
|
106 | - |
|
107 | - if ( isset( $custom_fields ) ) { |
|
108 | - $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos ); |
|
109 | - } |
|
110 | - |
|
111 | - // Set the published and modified dates. |
|
112 | - /* |
|
22 | + /** |
|
23 | + * @var Wordlift_Post_To_Jsonld_Converter |
|
24 | + */ |
|
25 | + private static $instance; |
|
26 | + |
|
27 | + /** |
|
28 | + * A {@link Wordlift_Log_Service} instance. |
|
29 | + * |
|
30 | + * @since 3.10.0 |
|
31 | + * @access private |
|
32 | + * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
33 | + */ |
|
34 | + private $log; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var false |
|
38 | + */ |
|
39 | + private $disable_convert_filters; |
|
40 | + /** |
|
41 | + * @var Object_Relation_Service |
|
42 | + */ |
|
43 | + private $object_relation_service; |
|
44 | + |
|
45 | + /** |
|
46 | + * Wordlift_Post_To_Jsonld_Converter constructor. |
|
47 | + * |
|
48 | + * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
49 | + * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
50 | + * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
51 | + * |
|
52 | + * @since 3.10.0 |
|
53 | + */ |
|
54 | + public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) { |
|
55 | + parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() ); |
|
56 | + $this->disable_convert_filters = $disable_convert_filters; |
|
57 | + $this->object_relation_service = Object_Relation_Service::get_instance(); |
|
58 | + // Set a reference to the logger. |
|
59 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
60 | + |
|
61 | + self::$instance = $this; |
|
62 | + |
|
63 | + } |
|
64 | + |
|
65 | + public static function get_instance() { |
|
66 | + |
|
67 | + return self::$instance; |
|
68 | + } |
|
69 | + |
|
70 | + public function new_instance_with_filters_disabled() { |
|
71 | + return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
76 | + * found while processing the post is set in the $references array. |
|
77 | + * |
|
78 | + * @param int $post_id The post id. |
|
79 | + * @param array<Reference> $references An array of entity references. |
|
80 | + * @param array $references_infos |
|
81 | + * |
|
82 | + * @return array A JSON-LD array. |
|
83 | + * @since 3.10.0 |
|
84 | + */ |
|
85 | + public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
86 | + |
|
87 | + // Get the post instance. |
|
88 | + $post = get_post( $post_id ); |
|
89 | + if ( null === $post ) { |
|
90 | + // Post not found. |
|
91 | + return null; |
|
92 | + } |
|
93 | + |
|
94 | + // Get the base JSON-LD and the list of entities referenced by this entity. |
|
95 | + $jsonld = parent::convert( $post_id, $references, $references_infos ); |
|
96 | + |
|
97 | + // Set WebPage by default. |
|
98 | + if ( empty( $jsonld['@type'] ) ) { |
|
99 | + $jsonld['@type'] = 'WebPage'; |
|
100 | + } |
|
101 | + |
|
102 | + // Get the entity name. |
|
103 | + $jsonld['headline'] = $post->post_title; |
|
104 | + |
|
105 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id ); |
|
106 | + |
|
107 | + if ( isset( $custom_fields ) ) { |
|
108 | + $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos ); |
|
109 | + } |
|
110 | + |
|
111 | + // Set the published and modified dates. |
|
112 | + /* |
|
113 | 113 | * Set the `datePublished` and `dateModified` using the local timezone. |
114 | 114 | * |
115 | 115 | * @see https://github.com/insideout10/wordlift-plugin/issues/887 |
116 | 116 | * |
117 | 117 | * @since 3.20.0 |
118 | 118 | */ |
119 | - try { |
|
120 | - $default_timezone = date_default_timezone_get(); |
|
121 | - $timezone = get_option( 'timezone_string' ); |
|
122 | - if ( ! empty( $timezone ) ) { |
|
123 | - date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
124 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
125 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
126 | - date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
127 | - } else { |
|
128 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
129 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
130 | - } |
|
131 | - } catch ( Exception $e ) { |
|
132 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
133 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
134 | - } |
|
135 | - |
|
136 | - // Get the word count for the post. |
|
137 | - /* |
|
119 | + try { |
|
120 | + $default_timezone = date_default_timezone_get(); |
|
121 | + $timezone = get_option( 'timezone_string' ); |
|
122 | + if ( ! empty( $timezone ) ) { |
|
123 | + date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
124 | + $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
125 | + $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
126 | + date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
127 | + } else { |
|
128 | + $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
129 | + $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
130 | + } |
|
131 | + } catch ( Exception $e ) { |
|
132 | + $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
133 | + $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
134 | + } |
|
135 | + |
|
136 | + // Get the word count for the post. |
|
137 | + /* |
|
138 | 138 | * Do not display the `wordCount` on a `WebPage`. |
139 | 139 | * |
140 | 140 | * @see https://github.com/insideout10/wordlift-plugin/issues/888 |
141 | 141 | * |
142 | 142 | * @since 3.20.0 |
143 | 143 | */ |
144 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
145 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
146 | - $jsonld['wordCount'] = $post_adapter->word_count(); |
|
147 | - } |
|
144 | + if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
145 | + $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
146 | + $jsonld['wordCount'] = $post_adapter->word_count(); |
|
147 | + } |
|
148 | 148 | |
149 | - /* |
|
149 | + /* |
|
150 | 150 | * Add keywords, articleSection, commentCount and inLanguage properties to `Article` JSON-LD |
151 | 151 | * |
152 | 152 | * @see https://github.com/insideout10/wordlift-plugin/issues/1140 |
153 | 153 | * |
154 | 154 | * @since 3.27.2 |
155 | 155 | */ |
156 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
157 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
158 | - $keywords = $post_adapter->keywords(); |
|
159 | - $article_section = $post_adapter->article_section(); |
|
160 | - $comment_count = $post_adapter->comment_count(); |
|
161 | - $locale = $post_adapter->locale(); |
|
162 | - |
|
163 | - if ( isset( $keywords ) ) { |
|
164 | - $jsonld['keywords'] = $keywords; |
|
165 | - } |
|
166 | - if ( ! empty( $article_section ) ) { |
|
167 | - $jsonld['articleSection'] = $article_section; |
|
168 | - } |
|
169 | - $jsonld['commentCount'] = $comment_count; |
|
170 | - $jsonld['inLanguage'] = $locale; |
|
171 | - $post_adapter->add_references( $post_id, $references ); |
|
172 | - } |
|
173 | - |
|
174 | - // Set the publisher. |
|
175 | - $this->set_publisher( $jsonld ); |
|
176 | - |
|
177 | - $references = $this->convert_references( $references ); |
|
178 | - |
|
179 | - // Process the references if any. |
|
180 | - $this->set_mentions_and_about( $references, $post, $jsonld ); |
|
181 | - |
|
182 | - // Finally set the author. |
|
183 | - $jsonld['author'] = $this->get_author( $post->post_author, $references ); |
|
184 | - |
|
185 | - // Return the JSON-LD if filters are disabled by the client. |
|
186 | - if ( $this->disable_convert_filters ) { |
|
187 | - return $jsonld; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references. |
|
192 | - * |
|
193 | - * @param array $value { |
|
194 | - * |
|
195 | - * @type array $jsonld The JSON-LD structure. |
|
196 | - * @type int[] $references An array of post IDs. |
|
197 | - * } |
|
198 | - * @since 3.25.0 |
|
199 | - * |
|
200 | - * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/ |
|
201 | - * |
|
202 | - * @api |
|
203 | - */ |
|
204 | - $ret_val = apply_filters( |
|
205 | - 'wl_post_jsonld_array', |
|
206 | - array( |
|
207 | - 'jsonld' => $jsonld, |
|
208 | - 'references' => $references, |
|
209 | - ), |
|
210 | - $post_id |
|
211 | - ); |
|
212 | - |
|
213 | - $jsonld = $ret_val['jsonld']; |
|
214 | - $references = $ret_val['references']; |
|
215 | - |
|
216 | - /** |
|
217 | - * Call the `wl_post_jsonld` filter. |
|
218 | - * |
|
219 | - * @param array $jsonld The JSON-LD structure. |
|
220 | - * @param int $post_id The {@link WP_Post} `id`. |
|
221 | - * @param array $references The array of referenced entities. |
|
222 | - * |
|
223 | - * @since 3.14.0 |
|
224 | - * |
|
225 | - * @api |
|
226 | - */ |
|
227 | - return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references ); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Get the author's JSON-LD fragment. |
|
232 | - * |
|
233 | - * The JSON-LD fragment is generated using the {@link WP_User}'s data or |
|
234 | - * the referenced entity if configured for the {@link WP_User}. |
|
235 | - * |
|
236 | - * @param int $author_id The author {@link WP_User}'s `id`. |
|
237 | - * @param array $references An array of referenced entities. |
|
238 | - * |
|
239 | - * @return string|array A JSON-LD structure. |
|
240 | - * @since 3.14.0 |
|
241 | - */ |
|
242 | - public function get_author( $author_id, &$references ) { |
|
243 | - |
|
244 | - // Get the entity bound to this user. |
|
245 | - $entity_id = $this->user_service->get_entity( $author_id ); |
|
246 | - |
|
247 | - // If there's no entity bound return a simple author structure. |
|
248 | - if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) { |
|
249 | - |
|
250 | - $author = get_the_author_meta( 'display_name', $author_id ); |
|
251 | - $author_first_name = get_the_author_meta( 'first_name', $author_id ); |
|
252 | - $author_last_name = get_the_author_meta( 'last_name', $author_id ); |
|
253 | - $author_uri = $this->user_service->get_uri( $author_id ); |
|
254 | - |
|
255 | - return array( |
|
256 | - '@type' => 'Person', |
|
257 | - '@id' => $author_uri, |
|
258 | - 'name' => $author, |
|
259 | - 'givenName' => $author_first_name, |
|
260 | - 'familyName' => $author_last_name, |
|
261 | - 'url' => get_author_posts_url( $author_id ), |
|
262 | - ); |
|
263 | - } |
|
264 | - |
|
265 | - // Add the author to the references. |
|
266 | - $author_uri = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id ); |
|
267 | - $references[] = $entity_id; |
|
268 | - |
|
269 | - // Return the JSON-LD for the referenced entity. |
|
270 | - return array( |
|
271 | - '@id' => $author_uri, |
|
272 | - ); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Enrich the provided params array with publisher data, if available. |
|
277 | - * |
|
278 | - * @param array $params The parameters array. |
|
279 | - * |
|
280 | - * @since 3.10.0 |
|
281 | - */ |
|
282 | - protected function set_publisher( &$params ) { |
|
283 | - |
|
284 | - // If the publisher id isn't set don't do anything. |
|
285 | - $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id(); |
|
286 | - if ( null === $publisher_id ) { |
|
287 | - return; |
|
288 | - } |
|
289 | - |
|
290 | - // Get the post instance. |
|
291 | - $post = get_post( $publisher_id ); |
|
292 | - if ( null === $post ) { |
|
293 | - // Publisher not found. |
|
294 | - return; |
|
295 | - } |
|
296 | - |
|
297 | - // Get the item id. |
|
298 | - $id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id ); |
|
299 | - |
|
300 | - // Get the type. |
|
301 | - $type = $this->entity_type_service->get( $publisher_id ); |
|
302 | - |
|
303 | - // Get the name. |
|
304 | - $name = $post->post_title; |
|
305 | - |
|
306 | - // Set the publisher data. |
|
307 | - $params['publisher'] = array( |
|
308 | - '@type' => $this->relative_to_context( $type['uri'] ), |
|
309 | - '@id' => $id, |
|
310 | - 'name' => $name, |
|
311 | - ); |
|
312 | - |
|
313 | - // Add the sameAs values associated with the publisher. |
|
314 | - $storage_factory = Wordlift_Storage_Factory::get_instance(); |
|
315 | - $sameas = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id ); |
|
316 | - if ( ! empty( $sameas ) ) { |
|
317 | - $params['publisher']['sameAs'] = $sameas; |
|
318 | - } |
|
319 | - |
|
320 | - // Set the logo, only for http://schema.org/Organization as Person doesn't |
|
321 | - // support the logo property. |
|
322 | - // |
|
323 | - // See http://schema.org/logo. |
|
324 | - if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) { |
|
325 | - return; |
|
326 | - } |
|
327 | - |
|
328 | - // Get the publisher logo. |
|
329 | - $publisher_logo = $this->get_publisher_logo( $post->ID ); |
|
330 | - |
|
331 | - // Bail out if the publisher logo isn't set. |
|
332 | - if ( false === $publisher_logo ) { |
|
333 | - return; |
|
334 | - } |
|
335 | - |
|
336 | - // Copy over some useful properties. |
|
337 | - // |
|
338 | - // See https://developers.google.com/search/docs/data-types/articles. |
|
339 | - $params['publisher']['logo']['@type'] = 'ImageObject'; |
|
340 | - $params['publisher']['logo']['url'] = $publisher_logo['url']; |
|
341 | - |
|
342 | - // If you specify a "width" or "height" value you should leave out |
|
343 | - // 'px'. For example: "width":"4608px" should be "width":"4608". |
|
344 | - // |
|
345 | - // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
346 | - $params['publisher']['logo']['width'] = $publisher_logo['width']; |
|
347 | - $params['publisher']['logo']['height'] = $publisher_logo['height']; |
|
348 | - |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Get the publisher logo structure. |
|
353 | - * |
|
354 | - * The function returns false when the publisher logo cannot be determined, i.e.: |
|
355 | - * - the post has no featured image. |
|
356 | - * - the featured image has no file. |
|
357 | - * - a wp_image_editor instance cannot be instantiated on the original file or on the publisher logo file. |
|
358 | - * |
|
359 | - * @param int $post_id The post id. |
|
360 | - * |
|
361 | - * @return array|false Returns an array with the `url`, `width` and `height` for the publisher logo or false in case |
|
362 | - * of errors. |
|
363 | - * @since 3.19.2 |
|
364 | - * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue. |
|
365 | - */ |
|
366 | - private function get_publisher_logo( $post_id ) { |
|
367 | - |
|
368 | - // Get the featured image for the post. |
|
369 | - $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
370 | - |
|
371 | - // Bail out if thumbnail not available. |
|
372 | - if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) { |
|
373 | - $this->log->info( "Featured image not set for post $post_id." ); |
|
374 | - |
|
375 | - return false; |
|
376 | - } |
|
377 | - |
|
378 | - // Get the uploads base URL. |
|
379 | - $uploads_dir = wp_upload_dir(); |
|
380 | - |
|
381 | - // Get the attachment metadata. |
|
382 | - $metadata = wp_get_attachment_metadata( $thumbnail_id ); |
|
383 | - |
|
384 | - // Bail out if the file isn't set. |
|
385 | - if ( ! isset( $metadata['file'] ) ) { |
|
386 | - $this->log->warn( "Featured image file not found for post $post_id." ); |
|
387 | - |
|
388 | - return false; |
|
389 | - } |
|
390 | - |
|
391 | - // Retrieve the relative filename, e.g. "2018/05/logo_publisher.png" |
|
392 | - $path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file']; |
|
393 | - |
|
394 | - // Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149 |
|
395 | - if ( ! file_exists( $path ) ) { |
|
396 | - $this->log->warn( "Featured image file $path doesn't exist for post $post_id." ); |
|
397 | - |
|
398 | - $attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' ); |
|
399 | - if ( $attachment_image_src ) { |
|
400 | - return array( |
|
401 | - 'url' => $attachment_image_src[0], |
|
402 | - 'width' => $attachment_image_src[1], |
|
403 | - 'height' => $attachment_image_src[2], |
|
404 | - ); |
|
405 | - } |
|
406 | - |
|
407 | - // Bail out if we cant fetch wp_get_attachment_image_src |
|
408 | - return false; |
|
409 | - |
|
410 | - } |
|
411 | - |
|
412 | - // Try to get the image editor and bail out if the editor cannot be instantiated. |
|
413 | - $original_file_editor = wp_get_image_editor( $path ); |
|
414 | - if ( is_wp_error( $original_file_editor ) ) { |
|
415 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." ); |
|
416 | - |
|
417 | - return false; |
|
418 | - } |
|
419 | - |
|
420 | - // Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling |
|
421 | - // and we don't actually know the end values. |
|
422 | - $publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' ); |
|
423 | - |
|
424 | - // If the file doesn't exist yet, create it. |
|
425 | - if ( ! file_exists( $publisher_logo_path ) ) { |
|
426 | - $original_file_editor->resize( 600, 60 ); |
|
427 | - $original_file_editor->save( $publisher_logo_path ); |
|
428 | - } |
|
429 | - |
|
430 | - // Try to get the image editor and bail out if the editor cannot be instantiated. |
|
431 | - $publisher_logo_editor = wp_get_image_editor( $publisher_logo_path ); |
|
432 | - if ( is_wp_error( $publisher_logo_editor ) ) { |
|
433 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." ); |
|
434 | - |
|
435 | - return false; |
|
436 | - } |
|
437 | - |
|
438 | - // Get the actual size. |
|
439 | - $size = $publisher_logo_editor->get_size(); |
|
440 | - |
|
441 | - // Finally return the array with data. |
|
442 | - return array( |
|
443 | - 'url' => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ), |
|
444 | - 'width' => $size['width'], |
|
445 | - 'height' => $size['height'], |
|
446 | - ); |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * @param $references |
|
451 | - * @param $post |
|
452 | - * @param $jsonld |
|
453 | - * |
|
454 | - * @return void |
|
455 | - */ |
|
456 | - private function set_mentions_and_about( $references, $post, &$jsonld ) { |
|
457 | - |
|
458 | - if ( count( $references ) === 0 ) { |
|
459 | - return; |
|
460 | - } |
|
461 | - |
|
462 | - // Prepare the `about` and `mentions` array. |
|
463 | - $mentions = array(); |
|
464 | - $about = array(); |
|
465 | - |
|
466 | - // If the entity is in the title, then it should be an `about`. |
|
467 | - foreach ( $references as $reference ) { |
|
468 | - |
|
469 | - if ( ! $reference instanceof Reference ) { |
|
470 | - // This condition should never be reached. |
|
471 | - continue; |
|
472 | - } |
|
473 | - |
|
474 | - // Get the entity labels. |
|
475 | - $labels = Wordlift_Entity_Service::get_instance()->get_labels( $reference->get_id(), $reference->get_type() ); |
|
476 | - // Get the entity URI. |
|
477 | - $item = array( |
|
478 | - '@id' => Wordlift_Entity_Service::get_instance()->get_uri( $reference->get_id(), $reference->get_type() ), |
|
479 | - ); |
|
480 | - |
|
481 | - $escaped_labels = array_map( |
|
482 | - function ( $value ) { |
|
483 | - return preg_quote( $value, '/' ); |
|
484 | - }, |
|
485 | - $labels |
|
486 | - ); |
|
487 | - |
|
488 | - $matches = false; |
|
489 | - |
|
490 | - // When the title is empty, then we shouldn't yield a match to about section. |
|
491 | - if ( array_filter( $escaped_labels ) ) { |
|
492 | - // Check if the labels match any part of the title. |
|
493 | - $matches = 1 === preg_match( '/' . implode( '|', $escaped_labels ) . '/', $post->post_title ); |
|
494 | - } |
|
495 | - |
|
496 | - // If the title matches, assign the entity to the about, otherwise to the mentions. |
|
497 | - if ( $matches ) { |
|
498 | - $about[] = $item; |
|
499 | - } else { |
|
500 | - $mentions[] = $item; |
|
501 | - } |
|
502 | - } |
|
503 | - |
|
504 | - // If we have abouts, assign them to the JSON-LD. |
|
505 | - if ( 0 < count( $about ) ) { |
|
506 | - $jsonld['about'] = $about; |
|
507 | - } |
|
508 | - |
|
509 | - // If we have mentions, assign them to the JSON-LD. |
|
510 | - if ( 0 < count( $mentions ) ) { |
|
511 | - $jsonld['mentions'] = $mentions; |
|
512 | - } |
|
513 | - |
|
514 | - return $jsonld; |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Convert references to abstract data type if we find any. |
|
519 | - * |
|
520 | - * @param $references array<int|Reference> |
|
521 | - * |
|
522 | - * @return Reference[] |
|
523 | - */ |
|
524 | - private function convert_references( $references ) { |
|
525 | - return array_map( |
|
526 | - function ( $reference ) { |
|
527 | - // Legacy code may still push numerical references to this |
|
528 | - // $references variable, so convert it to post references. |
|
529 | - if ( is_numeric( $reference ) ) { |
|
530 | - return new Post_Reference( $reference ); |
|
531 | - } |
|
532 | - |
|
533 | - return $reference; |
|
534 | - |
|
535 | - }, |
|
536 | - $references |
|
537 | - ); |
|
538 | - } |
|
156 | + if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
157 | + $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
158 | + $keywords = $post_adapter->keywords(); |
|
159 | + $article_section = $post_adapter->article_section(); |
|
160 | + $comment_count = $post_adapter->comment_count(); |
|
161 | + $locale = $post_adapter->locale(); |
|
162 | + |
|
163 | + if ( isset( $keywords ) ) { |
|
164 | + $jsonld['keywords'] = $keywords; |
|
165 | + } |
|
166 | + if ( ! empty( $article_section ) ) { |
|
167 | + $jsonld['articleSection'] = $article_section; |
|
168 | + } |
|
169 | + $jsonld['commentCount'] = $comment_count; |
|
170 | + $jsonld['inLanguage'] = $locale; |
|
171 | + $post_adapter->add_references( $post_id, $references ); |
|
172 | + } |
|
173 | + |
|
174 | + // Set the publisher. |
|
175 | + $this->set_publisher( $jsonld ); |
|
176 | + |
|
177 | + $references = $this->convert_references( $references ); |
|
178 | + |
|
179 | + // Process the references if any. |
|
180 | + $this->set_mentions_and_about( $references, $post, $jsonld ); |
|
181 | + |
|
182 | + // Finally set the author. |
|
183 | + $jsonld['author'] = $this->get_author( $post->post_author, $references ); |
|
184 | + |
|
185 | + // Return the JSON-LD if filters are disabled by the client. |
|
186 | + if ( $this->disable_convert_filters ) { |
|
187 | + return $jsonld; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Call the `wl_post_jsonld_array` filter. This filter allows 3rd parties to also modify the references. |
|
192 | + * |
|
193 | + * @param array $value { |
|
194 | + * |
|
195 | + * @type array $jsonld The JSON-LD structure. |
|
196 | + * @type int[] $references An array of post IDs. |
|
197 | + * } |
|
198 | + * @since 3.25.0 |
|
199 | + * |
|
200 | + * @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/ |
|
201 | + * |
|
202 | + * @api |
|
203 | + */ |
|
204 | + $ret_val = apply_filters( |
|
205 | + 'wl_post_jsonld_array', |
|
206 | + array( |
|
207 | + 'jsonld' => $jsonld, |
|
208 | + 'references' => $references, |
|
209 | + ), |
|
210 | + $post_id |
|
211 | + ); |
|
212 | + |
|
213 | + $jsonld = $ret_val['jsonld']; |
|
214 | + $references = $ret_val['references']; |
|
215 | + |
|
216 | + /** |
|
217 | + * Call the `wl_post_jsonld` filter. |
|
218 | + * |
|
219 | + * @param array $jsonld The JSON-LD structure. |
|
220 | + * @param int $post_id The {@link WP_Post} `id`. |
|
221 | + * @param array $references The array of referenced entities. |
|
222 | + * |
|
223 | + * @since 3.14.0 |
|
224 | + * |
|
225 | + * @api |
|
226 | + */ |
|
227 | + return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references ); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Get the author's JSON-LD fragment. |
|
232 | + * |
|
233 | + * The JSON-LD fragment is generated using the {@link WP_User}'s data or |
|
234 | + * the referenced entity if configured for the {@link WP_User}. |
|
235 | + * |
|
236 | + * @param int $author_id The author {@link WP_User}'s `id`. |
|
237 | + * @param array $references An array of referenced entities. |
|
238 | + * |
|
239 | + * @return string|array A JSON-LD structure. |
|
240 | + * @since 3.14.0 |
|
241 | + */ |
|
242 | + public function get_author( $author_id, &$references ) { |
|
243 | + |
|
244 | + // Get the entity bound to this user. |
|
245 | + $entity_id = $this->user_service->get_entity( $author_id ); |
|
246 | + |
|
247 | + // If there's no entity bound return a simple author structure. |
|
248 | + if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) { |
|
249 | + |
|
250 | + $author = get_the_author_meta( 'display_name', $author_id ); |
|
251 | + $author_first_name = get_the_author_meta( 'first_name', $author_id ); |
|
252 | + $author_last_name = get_the_author_meta( 'last_name', $author_id ); |
|
253 | + $author_uri = $this->user_service->get_uri( $author_id ); |
|
254 | + |
|
255 | + return array( |
|
256 | + '@type' => 'Person', |
|
257 | + '@id' => $author_uri, |
|
258 | + 'name' => $author, |
|
259 | + 'givenName' => $author_first_name, |
|
260 | + 'familyName' => $author_last_name, |
|
261 | + 'url' => get_author_posts_url( $author_id ), |
|
262 | + ); |
|
263 | + } |
|
264 | + |
|
265 | + // Add the author to the references. |
|
266 | + $author_uri = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id ); |
|
267 | + $references[] = $entity_id; |
|
268 | + |
|
269 | + // Return the JSON-LD for the referenced entity. |
|
270 | + return array( |
|
271 | + '@id' => $author_uri, |
|
272 | + ); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Enrich the provided params array with publisher data, if available. |
|
277 | + * |
|
278 | + * @param array $params The parameters array. |
|
279 | + * |
|
280 | + * @since 3.10.0 |
|
281 | + */ |
|
282 | + protected function set_publisher( &$params ) { |
|
283 | + |
|
284 | + // If the publisher id isn't set don't do anything. |
|
285 | + $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id(); |
|
286 | + if ( null === $publisher_id ) { |
|
287 | + return; |
|
288 | + } |
|
289 | + |
|
290 | + // Get the post instance. |
|
291 | + $post = get_post( $publisher_id ); |
|
292 | + if ( null === $post ) { |
|
293 | + // Publisher not found. |
|
294 | + return; |
|
295 | + } |
|
296 | + |
|
297 | + // Get the item id. |
|
298 | + $id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id ); |
|
299 | + |
|
300 | + // Get the type. |
|
301 | + $type = $this->entity_type_service->get( $publisher_id ); |
|
302 | + |
|
303 | + // Get the name. |
|
304 | + $name = $post->post_title; |
|
305 | + |
|
306 | + // Set the publisher data. |
|
307 | + $params['publisher'] = array( |
|
308 | + '@type' => $this->relative_to_context( $type['uri'] ), |
|
309 | + '@id' => $id, |
|
310 | + 'name' => $name, |
|
311 | + ); |
|
312 | + |
|
313 | + // Add the sameAs values associated with the publisher. |
|
314 | + $storage_factory = Wordlift_Storage_Factory::get_instance(); |
|
315 | + $sameas = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id ); |
|
316 | + if ( ! empty( $sameas ) ) { |
|
317 | + $params['publisher']['sameAs'] = $sameas; |
|
318 | + } |
|
319 | + |
|
320 | + // Set the logo, only for http://schema.org/Organization as Person doesn't |
|
321 | + // support the logo property. |
|
322 | + // |
|
323 | + // See http://schema.org/logo. |
|
324 | + if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) { |
|
325 | + return; |
|
326 | + } |
|
327 | + |
|
328 | + // Get the publisher logo. |
|
329 | + $publisher_logo = $this->get_publisher_logo( $post->ID ); |
|
330 | + |
|
331 | + // Bail out if the publisher logo isn't set. |
|
332 | + if ( false === $publisher_logo ) { |
|
333 | + return; |
|
334 | + } |
|
335 | + |
|
336 | + // Copy over some useful properties. |
|
337 | + // |
|
338 | + // See https://developers.google.com/search/docs/data-types/articles. |
|
339 | + $params['publisher']['logo']['@type'] = 'ImageObject'; |
|
340 | + $params['publisher']['logo']['url'] = $publisher_logo['url']; |
|
341 | + |
|
342 | + // If you specify a "width" or "height" value you should leave out |
|
343 | + // 'px'. For example: "width":"4608px" should be "width":"4608". |
|
344 | + // |
|
345 | + // See https://github.com/insideout10/wordlift-plugin/issues/451. |
|
346 | + $params['publisher']['logo']['width'] = $publisher_logo['width']; |
|
347 | + $params['publisher']['logo']['height'] = $publisher_logo['height']; |
|
348 | + |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Get the publisher logo structure. |
|
353 | + * |
|
354 | + * The function returns false when the publisher logo cannot be determined, i.e.: |
|
355 | + * - the post has no featured image. |
|
356 | + * - the featured image has no file. |
|
357 | + * - a wp_image_editor instance cannot be instantiated on the original file or on the publisher logo file. |
|
358 | + * |
|
359 | + * @param int $post_id The post id. |
|
360 | + * |
|
361 | + * @return array|false Returns an array with the `url`, `width` and `height` for the publisher logo or false in case |
|
362 | + * of errors. |
|
363 | + * @since 3.19.2 |
|
364 | + * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue. |
|
365 | + */ |
|
366 | + private function get_publisher_logo( $post_id ) { |
|
367 | + |
|
368 | + // Get the featured image for the post. |
|
369 | + $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
370 | + |
|
371 | + // Bail out if thumbnail not available. |
|
372 | + if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) { |
|
373 | + $this->log->info( "Featured image not set for post $post_id." ); |
|
374 | + |
|
375 | + return false; |
|
376 | + } |
|
377 | + |
|
378 | + // Get the uploads base URL. |
|
379 | + $uploads_dir = wp_upload_dir(); |
|
380 | + |
|
381 | + // Get the attachment metadata. |
|
382 | + $metadata = wp_get_attachment_metadata( $thumbnail_id ); |
|
383 | + |
|
384 | + // Bail out if the file isn't set. |
|
385 | + if ( ! isset( $metadata['file'] ) ) { |
|
386 | + $this->log->warn( "Featured image file not found for post $post_id." ); |
|
387 | + |
|
388 | + return false; |
|
389 | + } |
|
390 | + |
|
391 | + // Retrieve the relative filename, e.g. "2018/05/logo_publisher.png" |
|
392 | + $path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file']; |
|
393 | + |
|
394 | + // Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149 |
|
395 | + if ( ! file_exists( $path ) ) { |
|
396 | + $this->log->warn( "Featured image file $path doesn't exist for post $post_id." ); |
|
397 | + |
|
398 | + $attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' ); |
|
399 | + if ( $attachment_image_src ) { |
|
400 | + return array( |
|
401 | + 'url' => $attachment_image_src[0], |
|
402 | + 'width' => $attachment_image_src[1], |
|
403 | + 'height' => $attachment_image_src[2], |
|
404 | + ); |
|
405 | + } |
|
406 | + |
|
407 | + // Bail out if we cant fetch wp_get_attachment_image_src |
|
408 | + return false; |
|
409 | + |
|
410 | + } |
|
411 | + |
|
412 | + // Try to get the image editor and bail out if the editor cannot be instantiated. |
|
413 | + $original_file_editor = wp_get_image_editor( $path ); |
|
414 | + if ( is_wp_error( $original_file_editor ) ) { |
|
415 | + $this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." ); |
|
416 | + |
|
417 | + return false; |
|
418 | + } |
|
419 | + |
|
420 | + // Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling |
|
421 | + // and we don't actually know the end values. |
|
422 | + $publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' ); |
|
423 | + |
|
424 | + // If the file doesn't exist yet, create it. |
|
425 | + if ( ! file_exists( $publisher_logo_path ) ) { |
|
426 | + $original_file_editor->resize( 600, 60 ); |
|
427 | + $original_file_editor->save( $publisher_logo_path ); |
|
428 | + } |
|
429 | + |
|
430 | + // Try to get the image editor and bail out if the editor cannot be instantiated. |
|
431 | + $publisher_logo_editor = wp_get_image_editor( $publisher_logo_path ); |
|
432 | + if ( is_wp_error( $publisher_logo_editor ) ) { |
|
433 | + $this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." ); |
|
434 | + |
|
435 | + return false; |
|
436 | + } |
|
437 | + |
|
438 | + // Get the actual size. |
|
439 | + $size = $publisher_logo_editor->get_size(); |
|
440 | + |
|
441 | + // Finally return the array with data. |
|
442 | + return array( |
|
443 | + 'url' => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ), |
|
444 | + 'width' => $size['width'], |
|
445 | + 'height' => $size['height'], |
|
446 | + ); |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * @param $references |
|
451 | + * @param $post |
|
452 | + * @param $jsonld |
|
453 | + * |
|
454 | + * @return void |
|
455 | + */ |
|
456 | + private function set_mentions_and_about( $references, $post, &$jsonld ) { |
|
457 | + |
|
458 | + if ( count( $references ) === 0 ) { |
|
459 | + return; |
|
460 | + } |
|
461 | + |
|
462 | + // Prepare the `about` and `mentions` array. |
|
463 | + $mentions = array(); |
|
464 | + $about = array(); |
|
465 | + |
|
466 | + // If the entity is in the title, then it should be an `about`. |
|
467 | + foreach ( $references as $reference ) { |
|
468 | + |
|
469 | + if ( ! $reference instanceof Reference ) { |
|
470 | + // This condition should never be reached. |
|
471 | + continue; |
|
472 | + } |
|
473 | + |
|
474 | + // Get the entity labels. |
|
475 | + $labels = Wordlift_Entity_Service::get_instance()->get_labels( $reference->get_id(), $reference->get_type() ); |
|
476 | + // Get the entity URI. |
|
477 | + $item = array( |
|
478 | + '@id' => Wordlift_Entity_Service::get_instance()->get_uri( $reference->get_id(), $reference->get_type() ), |
|
479 | + ); |
|
480 | + |
|
481 | + $escaped_labels = array_map( |
|
482 | + function ( $value ) { |
|
483 | + return preg_quote( $value, '/' ); |
|
484 | + }, |
|
485 | + $labels |
|
486 | + ); |
|
487 | + |
|
488 | + $matches = false; |
|
489 | + |
|
490 | + // When the title is empty, then we shouldn't yield a match to about section. |
|
491 | + if ( array_filter( $escaped_labels ) ) { |
|
492 | + // Check if the labels match any part of the title. |
|
493 | + $matches = 1 === preg_match( '/' . implode( '|', $escaped_labels ) . '/', $post->post_title ); |
|
494 | + } |
|
495 | + |
|
496 | + // If the title matches, assign the entity to the about, otherwise to the mentions. |
|
497 | + if ( $matches ) { |
|
498 | + $about[] = $item; |
|
499 | + } else { |
|
500 | + $mentions[] = $item; |
|
501 | + } |
|
502 | + } |
|
503 | + |
|
504 | + // If we have abouts, assign them to the JSON-LD. |
|
505 | + if ( 0 < count( $about ) ) { |
|
506 | + $jsonld['about'] = $about; |
|
507 | + } |
|
508 | + |
|
509 | + // If we have mentions, assign them to the JSON-LD. |
|
510 | + if ( 0 < count( $mentions ) ) { |
|
511 | + $jsonld['mentions'] = $mentions; |
|
512 | + } |
|
513 | + |
|
514 | + return $jsonld; |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Convert references to abstract data type if we find any. |
|
519 | + * |
|
520 | + * @param $references array<int|Reference> |
|
521 | + * |
|
522 | + * @return Reference[] |
|
523 | + */ |
|
524 | + private function convert_references( $references ) { |
|
525 | + return array_map( |
|
526 | + function ( $reference ) { |
|
527 | + // Legacy code may still push numerical references to this |
|
528 | + // $references variable, so convert it to post references. |
|
529 | + if ( is_numeric( $reference ) ) { |
|
530 | + return new Post_Reference( $reference ); |
|
531 | + } |
|
532 | + |
|
533 | + return $reference; |
|
534 | + |
|
535 | + }, |
|
536 | + $references |
|
537 | + ); |
|
538 | + } |
|
539 | 539 | |
540 | 540 | } |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @since 3.10.0 |
53 | 53 | */ |
54 | - public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) { |
|
55 | - parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() ); |
|
54 | + public function __construct($entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false) { |
|
55 | + parent::__construct($entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create()); |
|
56 | 56 | $this->disable_convert_filters = $disable_convert_filters; |
57 | 57 | $this->object_relation_service = Object_Relation_Service::get_instance(); |
58 | 58 | // Set a reference to the logger. |
59 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
59 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Post_To_Jsonld_Converter'); |
|
60 | 60 | |
61 | 61 | self::$instance = $this; |
62 | 62 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | public function new_instance_with_filters_disabled() { |
71 | - return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true ); |
|
71 | + return new static($this->entity_type_service, $this->user_service, $this->attachment_service, true); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -82,30 +82,30 @@ discard block |
||
82 | 82 | * @return array A JSON-LD array. |
83 | 83 | * @since 3.10.0 |
84 | 84 | */ |
85 | - public function convert( $post_id, &$references = array(), &$references_infos = array() ) { |
|
85 | + public function convert($post_id, &$references = array(), &$references_infos = array()) { |
|
86 | 86 | |
87 | 87 | // Get the post instance. |
88 | - $post = get_post( $post_id ); |
|
89 | - if ( null === $post ) { |
|
88 | + $post = get_post($post_id); |
|
89 | + if (null === $post) { |
|
90 | 90 | // Post not found. |
91 | 91 | return null; |
92 | 92 | } |
93 | 93 | |
94 | 94 | // Get the base JSON-LD and the list of entities referenced by this entity. |
95 | - $jsonld = parent::convert( $post_id, $references, $references_infos ); |
|
95 | + $jsonld = parent::convert($post_id, $references, $references_infos); |
|
96 | 96 | |
97 | 97 | // Set WebPage by default. |
98 | - if ( empty( $jsonld['@type'] ) ) { |
|
98 | + if (empty($jsonld['@type'])) { |
|
99 | 99 | $jsonld['@type'] = 'WebPage'; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Get the entity name. |
103 | 103 | $jsonld['headline'] = $post->post_title; |
104 | 104 | |
105 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id ); |
|
105 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_post($post_id); |
|
106 | 106 | |
107 | - if ( isset( $custom_fields ) ) { |
|
108 | - $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos ); |
|
107 | + if (isset($custom_fields)) { |
|
108 | + $this->process_type_custom_fields($jsonld, $custom_fields, $post, $references, $references_infos); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Set the published and modified dates. |
@@ -118,19 +118,19 @@ discard block |
||
118 | 118 | */ |
119 | 119 | try { |
120 | 120 | $default_timezone = date_default_timezone_get(); |
121 | - $timezone = get_option( 'timezone_string' ); |
|
122 | - if ( ! empty( $timezone ) ) { |
|
123 | - date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
124 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
125 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
126 | - date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
121 | + $timezone = get_option('timezone_string'); |
|
122 | + if ( ! empty($timezone)) { |
|
123 | + date_default_timezone_set($timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
124 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i:sP', false, $post); |
|
125 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i:sP', false, $post); |
|
126 | + date_default_timezone_set($default_timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
127 | 127 | } else { |
128 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
129 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
128 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false); |
|
129 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i', true, $post, false); |
|
130 | 130 | } |
131 | - } catch ( Exception $e ) { |
|
132 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
133 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
131 | + } catch (Exception $e) { |
|
132 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false); |
|
133 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i', true, $post, false); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | // Get the word count for the post. |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @since 3.20.0 |
143 | 143 | */ |
144 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
145 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
144 | + if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) { |
|
145 | + $post_adapter = new Wordlift_Post_Adapter($post_id); |
|
146 | 146 | $jsonld['wordCount'] = $post_adapter->word_count(); |
147 | 147 | } |
148 | 148 | |
@@ -153,37 +153,37 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @since 3.27.2 |
155 | 155 | */ |
156 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
157 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
156 | + if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) { |
|
157 | + $post_adapter = new Wordlift_Post_Adapter($post_id); |
|
158 | 158 | $keywords = $post_adapter->keywords(); |
159 | 159 | $article_section = $post_adapter->article_section(); |
160 | 160 | $comment_count = $post_adapter->comment_count(); |
161 | 161 | $locale = $post_adapter->locale(); |
162 | 162 | |
163 | - if ( isset( $keywords ) ) { |
|
163 | + if (isset($keywords)) { |
|
164 | 164 | $jsonld['keywords'] = $keywords; |
165 | 165 | } |
166 | - if ( ! empty( $article_section ) ) { |
|
166 | + if ( ! empty($article_section)) { |
|
167 | 167 | $jsonld['articleSection'] = $article_section; |
168 | 168 | } |
169 | 169 | $jsonld['commentCount'] = $comment_count; |
170 | 170 | $jsonld['inLanguage'] = $locale; |
171 | - $post_adapter->add_references( $post_id, $references ); |
|
171 | + $post_adapter->add_references($post_id, $references); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Set the publisher. |
175 | - $this->set_publisher( $jsonld ); |
|
175 | + $this->set_publisher($jsonld); |
|
176 | 176 | |
177 | - $references = $this->convert_references( $references ); |
|
177 | + $references = $this->convert_references($references); |
|
178 | 178 | |
179 | 179 | // Process the references if any. |
180 | - $this->set_mentions_and_about( $references, $post, $jsonld ); |
|
180 | + $this->set_mentions_and_about($references, $post, $jsonld); |
|
181 | 181 | |
182 | 182 | // Finally set the author. |
183 | - $jsonld['author'] = $this->get_author( $post->post_author, $references ); |
|
183 | + $jsonld['author'] = $this->get_author($post->post_author, $references); |
|
184 | 184 | |
185 | 185 | // Return the JSON-LD if filters are disabled by the client. |
186 | - if ( $this->disable_convert_filters ) { |
|
186 | + if ($this->disable_convert_filters) { |
|
187 | 187 | return $jsonld; |
188 | 188 | } |
189 | 189 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @api |
226 | 226 | */ |
227 | - return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references ); |
|
227 | + return apply_filters('wl_post_jsonld', $jsonld, $post_id, $references); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -239,18 +239,18 @@ discard block |
||
239 | 239 | * @return string|array A JSON-LD structure. |
240 | 240 | * @since 3.14.0 |
241 | 241 | */ |
242 | - public function get_author( $author_id, &$references ) { |
|
242 | + public function get_author($author_id, &$references) { |
|
243 | 243 | |
244 | 244 | // Get the entity bound to this user. |
245 | - $entity_id = $this->user_service->get_entity( $author_id ); |
|
245 | + $entity_id = $this->user_service->get_entity($author_id); |
|
246 | 246 | |
247 | 247 | // If there's no entity bound return a simple author structure. |
248 | - if ( empty( $entity_id ) || 'publish' !== get_post_status( $entity_id ) ) { |
|
248 | + if (empty($entity_id) || 'publish' !== get_post_status($entity_id)) { |
|
249 | 249 | |
250 | - $author = get_the_author_meta( 'display_name', $author_id ); |
|
251 | - $author_first_name = get_the_author_meta( 'first_name', $author_id ); |
|
252 | - $author_last_name = get_the_author_meta( 'last_name', $author_id ); |
|
253 | - $author_uri = $this->user_service->get_uri( $author_id ); |
|
250 | + $author = get_the_author_meta('display_name', $author_id); |
|
251 | + $author_first_name = get_the_author_meta('first_name', $author_id); |
|
252 | + $author_last_name = get_the_author_meta('last_name', $author_id); |
|
253 | + $author_uri = $this->user_service->get_uri($author_id); |
|
254 | 254 | |
255 | 255 | return array( |
256 | 256 | '@type' => 'Person', |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | 'name' => $author, |
259 | 259 | 'givenName' => $author_first_name, |
260 | 260 | 'familyName' => $author_last_name, |
261 | - 'url' => get_author_posts_url( $author_id ), |
|
261 | + 'url' => get_author_posts_url($author_id), |
|
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | 265 | // Add the author to the references. |
266 | - $author_uri = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id ); |
|
266 | + $author_uri = Wordlift_Entity_Service::get_instance()->get_uri($entity_id); |
|
267 | 267 | $references[] = $entity_id; |
268 | 268 | |
269 | 269 | // Return the JSON-LD for the referenced entity. |
@@ -279,41 +279,41 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @since 3.10.0 |
281 | 281 | */ |
282 | - protected function set_publisher( &$params ) { |
|
282 | + protected function set_publisher(&$params) { |
|
283 | 283 | |
284 | 284 | // If the publisher id isn't set don't do anything. |
285 | 285 | $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id(); |
286 | - if ( null === $publisher_id ) { |
|
286 | + if (null === $publisher_id) { |
|
287 | 287 | return; |
288 | 288 | } |
289 | 289 | |
290 | 290 | // Get the post instance. |
291 | - $post = get_post( $publisher_id ); |
|
292 | - if ( null === $post ) { |
|
291 | + $post = get_post($publisher_id); |
|
292 | + if (null === $post) { |
|
293 | 293 | // Publisher not found. |
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Get the item id. |
298 | - $id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id ); |
|
298 | + $id = Wordlift_Entity_Service::get_instance()->get_uri($publisher_id); |
|
299 | 299 | |
300 | 300 | // Get the type. |
301 | - $type = $this->entity_type_service->get( $publisher_id ); |
|
301 | + $type = $this->entity_type_service->get($publisher_id); |
|
302 | 302 | |
303 | 303 | // Get the name. |
304 | 304 | $name = $post->post_title; |
305 | 305 | |
306 | 306 | // Set the publisher data. |
307 | 307 | $params['publisher'] = array( |
308 | - '@type' => $this->relative_to_context( $type['uri'] ), |
|
308 | + '@type' => $this->relative_to_context($type['uri']), |
|
309 | 309 | '@id' => $id, |
310 | 310 | 'name' => $name, |
311 | 311 | ); |
312 | 312 | |
313 | 313 | // Add the sameAs values associated with the publisher. |
314 | 314 | $storage_factory = Wordlift_Storage_Factory::get_instance(); |
315 | - $sameas = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id ); |
|
316 | - if ( ! empty( $sameas ) ) { |
|
315 | + $sameas = $storage_factory->post_meta(Wordlift_Schema_Service::FIELD_SAME_AS)->get($publisher_id); |
|
316 | + if ( ! empty($sameas)) { |
|
317 | 317 | $params['publisher']['sameAs'] = $sameas; |
318 | 318 | } |
319 | 319 | |
@@ -321,15 +321,15 @@ discard block |
||
321 | 321 | // support the logo property. |
322 | 322 | // |
323 | 323 | // See http://schema.org/logo. |
324 | - if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) { |
|
324 | + if (1 !== preg_match('~Organization$~', $type['uri'])) { |
|
325 | 325 | return; |
326 | 326 | } |
327 | 327 | |
328 | 328 | // Get the publisher logo. |
329 | - $publisher_logo = $this->get_publisher_logo( $post->ID ); |
|
329 | + $publisher_logo = $this->get_publisher_logo($post->ID); |
|
330 | 330 | |
331 | 331 | // Bail out if the publisher logo isn't set. |
332 | - if ( false === $publisher_logo ) { |
|
332 | + if (false === $publisher_logo) { |
|
333 | 333 | return; |
334 | 334 | } |
335 | 335 | |
@@ -363,14 +363,14 @@ discard block |
||
363 | 363 | * @since 3.19.2 |
364 | 364 | * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue. |
365 | 365 | */ |
366 | - private function get_publisher_logo( $post_id ) { |
|
366 | + private function get_publisher_logo($post_id) { |
|
367 | 367 | |
368 | 368 | // Get the featured image for the post. |
369 | - $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
369 | + $thumbnail_id = get_post_thumbnail_id($post_id); |
|
370 | 370 | |
371 | 371 | // Bail out if thumbnail not available. |
372 | - if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) { |
|
373 | - $this->log->info( "Featured image not set for post $post_id." ); |
|
372 | + if (empty($thumbnail_id) || 0 === $thumbnail_id) { |
|
373 | + $this->log->info("Featured image not set for post $post_id."); |
|
374 | 374 | |
375 | 375 | return false; |
376 | 376 | } |
@@ -379,24 +379,24 @@ discard block |
||
379 | 379 | $uploads_dir = wp_upload_dir(); |
380 | 380 | |
381 | 381 | // Get the attachment metadata. |
382 | - $metadata = wp_get_attachment_metadata( $thumbnail_id ); |
|
382 | + $metadata = wp_get_attachment_metadata($thumbnail_id); |
|
383 | 383 | |
384 | 384 | // Bail out if the file isn't set. |
385 | - if ( ! isset( $metadata['file'] ) ) { |
|
386 | - $this->log->warn( "Featured image file not found for post $post_id." ); |
|
385 | + if ( ! isset($metadata['file'])) { |
|
386 | + $this->log->warn("Featured image file not found for post $post_id."); |
|
387 | 387 | |
388 | 388 | return false; |
389 | 389 | } |
390 | 390 | |
391 | 391 | // Retrieve the relative filename, e.g. "2018/05/logo_publisher.png" |
392 | - $path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file']; |
|
392 | + $path = $uploads_dir['basedir'].DIRECTORY_SEPARATOR.$metadata['file']; |
|
393 | 393 | |
394 | 394 | // Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149 |
395 | - if ( ! file_exists( $path ) ) { |
|
396 | - $this->log->warn( "Featured image file $path doesn't exist for post $post_id." ); |
|
395 | + if ( ! file_exists($path)) { |
|
396 | + $this->log->warn("Featured image file $path doesn't exist for post $post_id."); |
|
397 | 397 | |
398 | - $attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' ); |
|
399 | - if ( $attachment_image_src ) { |
|
398 | + $attachment_image_src = wp_get_attachment_image_src($thumbnail_id, ''); |
|
399 | + if ($attachment_image_src) { |
|
400 | 400 | return array( |
401 | 401 | 'url' => $attachment_image_src[0], |
402 | 402 | 'width' => $attachment_image_src[1], |
@@ -410,27 +410,27 @@ discard block |
||
410 | 410 | } |
411 | 411 | |
412 | 412 | // Try to get the image editor and bail out if the editor cannot be instantiated. |
413 | - $original_file_editor = wp_get_image_editor( $path ); |
|
414 | - if ( is_wp_error( $original_file_editor ) ) { |
|
415 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." ); |
|
413 | + $original_file_editor = wp_get_image_editor($path); |
|
414 | + if (is_wp_error($original_file_editor)) { |
|
415 | + $this->log->warn("Cannot instantiate WP Image Editor on file $path for post $post_id."); |
|
416 | 416 | |
417 | 417 | return false; |
418 | 418 | } |
419 | 419 | |
420 | 420 | // Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling |
421 | 421 | // and we don't actually know the end values. |
422 | - $publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' ); |
|
422 | + $publisher_logo_path = $original_file_editor->generate_filename('-publisher-logo'); |
|
423 | 423 | |
424 | 424 | // If the file doesn't exist yet, create it. |
425 | - if ( ! file_exists( $publisher_logo_path ) ) { |
|
426 | - $original_file_editor->resize( 600, 60 ); |
|
427 | - $original_file_editor->save( $publisher_logo_path ); |
|
425 | + if ( ! file_exists($publisher_logo_path)) { |
|
426 | + $original_file_editor->resize(600, 60); |
|
427 | + $original_file_editor->save($publisher_logo_path); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | // Try to get the image editor and bail out if the editor cannot be instantiated. |
431 | - $publisher_logo_editor = wp_get_image_editor( $publisher_logo_path ); |
|
432 | - if ( is_wp_error( $publisher_logo_editor ) ) { |
|
433 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." ); |
|
431 | + $publisher_logo_editor = wp_get_image_editor($publisher_logo_path); |
|
432 | + if (is_wp_error($publisher_logo_editor)) { |
|
433 | + $this->log->warn("Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id."); |
|
434 | 434 | |
435 | 435 | return false; |
436 | 436 | } |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | |
441 | 441 | // Finally return the array with data. |
442 | 442 | return array( |
443 | - 'url' => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ), |
|
443 | + 'url' => $uploads_dir['baseurl'].substr($publisher_logo_path, strlen($uploads_dir['basedir'])), |
|
444 | 444 | 'width' => $size['width'], |
445 | 445 | 'height' => $size['height'], |
446 | 446 | ); |
@@ -453,9 +453,9 @@ discard block |
||
453 | 453 | * |
454 | 454 | * @return void |
455 | 455 | */ |
456 | - private function set_mentions_and_about( $references, $post, &$jsonld ) { |
|
456 | + private function set_mentions_and_about($references, $post, &$jsonld) { |
|
457 | 457 | |
458 | - if ( count( $references ) === 0 ) { |
|
458 | + if (count($references) === 0) { |
|
459 | 459 | return; |
460 | 460 | } |
461 | 461 | |
@@ -464,23 +464,23 @@ discard block |
||
464 | 464 | $about = array(); |
465 | 465 | |
466 | 466 | // If the entity is in the title, then it should be an `about`. |
467 | - foreach ( $references as $reference ) { |
|
467 | + foreach ($references as $reference) { |
|
468 | 468 | |
469 | - if ( ! $reference instanceof Reference ) { |
|
469 | + if ( ! $reference instanceof Reference) { |
|
470 | 470 | // This condition should never be reached. |
471 | 471 | continue; |
472 | 472 | } |
473 | 473 | |
474 | 474 | // Get the entity labels. |
475 | - $labels = Wordlift_Entity_Service::get_instance()->get_labels( $reference->get_id(), $reference->get_type() ); |
|
475 | + $labels = Wordlift_Entity_Service::get_instance()->get_labels($reference->get_id(), $reference->get_type()); |
|
476 | 476 | // Get the entity URI. |
477 | 477 | $item = array( |
478 | - '@id' => Wordlift_Entity_Service::get_instance()->get_uri( $reference->get_id(), $reference->get_type() ), |
|
478 | + '@id' => Wordlift_Entity_Service::get_instance()->get_uri($reference->get_id(), $reference->get_type()), |
|
479 | 479 | ); |
480 | 480 | |
481 | 481 | $escaped_labels = array_map( |
482 | - function ( $value ) { |
|
483 | - return preg_quote( $value, '/' ); |
|
482 | + function($value) { |
|
483 | + return preg_quote($value, '/'); |
|
484 | 484 | }, |
485 | 485 | $labels |
486 | 486 | ); |
@@ -488,13 +488,13 @@ discard block |
||
488 | 488 | $matches = false; |
489 | 489 | |
490 | 490 | // When the title is empty, then we shouldn't yield a match to about section. |
491 | - if ( array_filter( $escaped_labels ) ) { |
|
491 | + if (array_filter($escaped_labels)) { |
|
492 | 492 | // Check if the labels match any part of the title. |
493 | - $matches = 1 === preg_match( '/' . implode( '|', $escaped_labels ) . '/', $post->post_title ); |
|
493 | + $matches = 1 === preg_match('/'.implode('|', $escaped_labels).'/', $post->post_title); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | // If the title matches, assign the entity to the about, otherwise to the mentions. |
497 | - if ( $matches ) { |
|
497 | + if ($matches) { |
|
498 | 498 | $about[] = $item; |
499 | 499 | } else { |
500 | 500 | $mentions[] = $item; |
@@ -502,12 +502,12 @@ discard block |
||
502 | 502 | } |
503 | 503 | |
504 | 504 | // If we have abouts, assign them to the JSON-LD. |
505 | - if ( 0 < count( $about ) ) { |
|
505 | + if (0 < count($about)) { |
|
506 | 506 | $jsonld['about'] = $about; |
507 | 507 | } |
508 | 508 | |
509 | 509 | // If we have mentions, assign them to the JSON-LD. |
510 | - if ( 0 < count( $mentions ) ) { |
|
510 | + if (0 < count($mentions)) { |
|
511 | 511 | $jsonld['mentions'] = $mentions; |
512 | 512 | } |
513 | 513 | |
@@ -521,13 +521,13 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @return Reference[] |
523 | 523 | */ |
524 | - private function convert_references( $references ) { |
|
524 | + private function convert_references($references) { |
|
525 | 525 | return array_map( |
526 | - function ( $reference ) { |
|
526 | + function($reference) { |
|
527 | 527 | // Legacy code may still push numerical references to this |
528 | 528 | // $references variable, so convert it to post references. |
529 | - if ( is_numeric( $reference ) ) { |
|
530 | - return new Post_Reference( $reference ); |
|
529 | + if (is_numeric($reference)) { |
|
530 | + return new Post_Reference($reference); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | return $reference; |
@@ -13,64 +13,64 @@ |
||
13 | 13 | */ |
14 | 14 | class Wordlift_Debug_Service { |
15 | 15 | |
16 | - /** |
|
17 | - * The {@link Wordlift_Entity_Service} instance. |
|
18 | - * |
|
19 | - * @since 3.7.2 |
|
20 | - * @access private |
|
21 | - * @var Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
22 | - */ |
|
23 | - private $entity_service; |
|
16 | + /** |
|
17 | + * The {@link Wordlift_Entity_Service} instance. |
|
18 | + * |
|
19 | + * @since 3.7.2 |
|
20 | + * @access private |
|
21 | + * @var Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
22 | + */ |
|
23 | + private $entity_service; |
|
24 | 24 | |
25 | - /** |
|
26 | - * A {@link Wordlift_Uri_Service} instance. |
|
27 | - * |
|
28 | - * @since 3.10.0 |
|
29 | - * @access private |
|
30 | - * @var \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance. |
|
31 | - */ |
|
32 | - private $uri_service; |
|
25 | + /** |
|
26 | + * A {@link Wordlift_Uri_Service} instance. |
|
27 | + * |
|
28 | + * @since 3.10.0 |
|
29 | + * @access private |
|
30 | + * @var \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance. |
|
31 | + */ |
|
32 | + private $uri_service; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Wordlift_Debug_Service constructor. |
|
36 | - * |
|
37 | - * @since 3.7.2 |
|
38 | - * |
|
39 | - * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
40 | - * @param \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance. |
|
41 | - */ |
|
42 | - public function __construct( $entity_service, $uri_service ) { |
|
34 | + /** |
|
35 | + * Wordlift_Debug_Service constructor. |
|
36 | + * |
|
37 | + * @since 3.7.2 |
|
38 | + * |
|
39 | + * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
40 | + * @param \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance. |
|
41 | + */ |
|
42 | + public function __construct( $entity_service, $uri_service ) { |
|
43 | 43 | |
44 | - $this->entity_service = $entity_service; |
|
45 | - $this->uri_service = $uri_service; |
|
44 | + $this->entity_service = $entity_service; |
|
45 | + $this->uri_service = $uri_service; |
|
46 | 46 | |
47 | - add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) ); |
|
47 | + add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) ); |
|
48 | 48 | |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - public function dump_uri() { |
|
51 | + public function dump_uri() { |
|
52 | 52 | |
53 | - if ( ! isset( $_GET['id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
54 | - wp_send_json_error( 'id not set' ); |
|
55 | - } |
|
53 | + if ( ! isset( $_GET['id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
54 | + wp_send_json_error( 'id not set' ); |
|
55 | + } |
|
56 | 56 | |
57 | - $post_id = (int) $_GET['id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
57 | + $post_id = (int) $_GET['id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
58 | 58 | |
59 | - $post = get_post( $post_id ); |
|
59 | + $post = get_post( $post_id ); |
|
60 | 60 | |
61 | - $uri = $this->entity_service->get_uri( $post_id ); |
|
62 | - $build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type ); |
|
61 | + $uri = $this->entity_service->get_uri( $post_id ); |
|
62 | + $build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type ); |
|
63 | 63 | |
64 | - wp_send_json_success( |
|
65 | - array( |
|
66 | - 'uri' => $uri, |
|
67 | - 'post_title' => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ), |
|
68 | - 'post_title_ascii' => mb_convert_encoding( $post->post_title, 'ASCII' ), |
|
69 | - 'build_uri' => $build_uri, |
|
70 | - 'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ), |
|
71 | - ) |
|
72 | - ); |
|
64 | + wp_send_json_success( |
|
65 | + array( |
|
66 | + 'uri' => $uri, |
|
67 | + 'post_title' => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ), |
|
68 | + 'post_title_ascii' => mb_convert_encoding( $post->post_title, 'ASCII' ), |
|
69 | + 'build_uri' => $build_uri, |
|
70 | + 'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ), |
|
71 | + ) |
|
72 | + ); |
|
73 | 73 | |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -39,35 +39,35 @@ |
||
39 | 39 | * @param Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
40 | 40 | * @param \Wordlift_Uri_Service $uri_service A {@link Wordlift_Uri_Service} instance. |
41 | 41 | */ |
42 | - public function __construct( $entity_service, $uri_service ) { |
|
42 | + public function __construct($entity_service, $uri_service) { |
|
43 | 43 | |
44 | 44 | $this->entity_service = $entity_service; |
45 | 45 | $this->uri_service = $uri_service; |
46 | 46 | |
47 | - add_action( 'wp_ajax_wl_dump_uri', array( $this, 'dump_uri' ) ); |
|
47 | + add_action('wp_ajax_wl_dump_uri', array($this, 'dump_uri')); |
|
48 | 48 | |
49 | 49 | } |
50 | 50 | |
51 | 51 | public function dump_uri() { |
52 | 52 | |
53 | - if ( ! isset( $_GET['id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
54 | - wp_send_json_error( 'id not set' ); |
|
53 | + if ( ! isset($_GET['id'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
54 | + wp_send_json_error('id not set'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $post_id = (int) $_GET['id']; //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
58 | 58 | |
59 | - $post = get_post( $post_id ); |
|
59 | + $post = get_post($post_id); |
|
60 | 60 | |
61 | - $uri = $this->entity_service->get_uri( $post_id ); |
|
62 | - $build_uri = $this->uri_service->build_uri( $post->post_title, $post->post_type ); |
|
61 | + $uri = $this->entity_service->get_uri($post_id); |
|
62 | + $build_uri = $this->uri_service->build_uri($post->post_title, $post->post_type); |
|
63 | 63 | |
64 | 64 | wp_send_json_success( |
65 | 65 | array( |
66 | 66 | 'uri' => $uri, |
67 | - 'post_title' => sprintf( '%s (%s)', $post->post_title, mb_detect_encoding( $post->post_title ) ), |
|
68 | - 'post_title_ascii' => mb_convert_encoding( $post->post_title, 'ASCII' ), |
|
67 | + 'post_title' => sprintf('%s (%s)', $post->post_title, mb_detect_encoding($post->post_title)), |
|
68 | + 'post_title_ascii' => mb_convert_encoding($post->post_title, 'ASCII'), |
|
69 | 69 | 'build_uri' => $build_uri, |
70 | - 'build_uri_convert' => mb_convert_encoding( $build_uri, 'ASCII' ), |
|
70 | + 'build_uri_convert' => mb_convert_encoding($build_uri, 'ASCII'), |
|
71 | 71 | ) |
72 | 72 | ); |
73 | 73 |
@@ -11,58 +11,58 @@ |
||
11 | 11 | */ |
12 | 12 | class Wordlift_Property_Factory { |
13 | 13 | |
14 | - /** |
|
15 | - * The default {@link Wordlift_Property_Service}. |
|
16 | - * |
|
17 | - * @since 3.7.0 |
|
18 | - * @access private |
|
19 | - * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}. |
|
20 | - */ |
|
21 | - private $default_property_service; |
|
14 | + /** |
|
15 | + * The default {@link Wordlift_Property_Service}. |
|
16 | + * |
|
17 | + * @since 3.7.0 |
|
18 | + * @access private |
|
19 | + * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}. |
|
20 | + */ |
|
21 | + private $default_property_service; |
|
22 | 22 | |
23 | - private $property_services = array(); |
|
23 | + private $property_services = array(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * Wordlift_Property_Factory constructor. |
|
27 | - * |
|
28 | - * @since 3.7.0 |
|
29 | - * |
|
30 | - * @param \Wordlift_Property_Service $default_property_service |
|
31 | - */ |
|
32 | - public function __construct( $default_property_service ) { |
|
25 | + /** |
|
26 | + * Wordlift_Property_Factory constructor. |
|
27 | + * |
|
28 | + * @since 3.7.0 |
|
29 | + * |
|
30 | + * @param \Wordlift_Property_Service $default_property_service |
|
31 | + */ |
|
32 | + public function __construct( $default_property_service ) { |
|
33 | 33 | |
34 | - $this->default_property_service = $default_property_service; |
|
34 | + $this->default_property_service = $default_property_service; |
|
35 | 35 | |
36 | - } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Set the {@link Wordlift_Property_Service} which handles that meta key. |
|
40 | - * |
|
41 | - * @since 3.7.0 |
|
42 | - * |
|
43 | - * @param string $meta_key WordPress' meta key. |
|
44 | - * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance. |
|
45 | - */ |
|
46 | - public function register( $meta_key, $property_service ) { |
|
38 | + /** |
|
39 | + * Set the {@link Wordlift_Property_Service} which handles that meta key. |
|
40 | + * |
|
41 | + * @since 3.7.0 |
|
42 | + * |
|
43 | + * @param string $meta_key WordPress' meta key. |
|
44 | + * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance. |
|
45 | + */ |
|
46 | + public function register( $meta_key, $property_service ) { |
|
47 | 47 | |
48 | - $this->property_services[ $meta_key ] = $property_service; |
|
48 | + $this->property_services[ $meta_key ] = $property_service; |
|
49 | 49 | |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get the {@link Wordlift_Property_Service} which handles the specified meta key. |
|
54 | - * |
|
55 | - * @since 3.7.0 |
|
56 | - * |
|
57 | - * @param $meta_key |
|
58 | - * |
|
59 | - * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key. |
|
60 | - */ |
|
61 | - public function get( $meta_key ) { |
|
52 | + /** |
|
53 | + * Get the {@link Wordlift_Property_Service} which handles the specified meta key. |
|
54 | + * |
|
55 | + * @since 3.7.0 |
|
56 | + * |
|
57 | + * @param $meta_key |
|
58 | + * |
|
59 | + * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key. |
|
60 | + */ |
|
61 | + public function get( $meta_key ) { |
|
62 | 62 | |
63 | - $service = $this->property_services[ $meta_key ]; |
|
63 | + $service = $this->property_services[ $meta_key ]; |
|
64 | 64 | |
65 | - return $service ? $service : $this->default_property_service; |
|
66 | - } |
|
65 | + return $service ? $service : $this->default_property_service; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param \Wordlift_Property_Service $default_property_service |
31 | 31 | */ |
32 | - public function __construct( $default_property_service ) { |
|
32 | + public function __construct($default_property_service) { |
|
33 | 33 | |
34 | 34 | $this->default_property_service = $default_property_service; |
35 | 35 | |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * @param string $meta_key WordPress' meta key. |
44 | 44 | * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance. |
45 | 45 | */ |
46 | - public function register( $meta_key, $property_service ) { |
|
46 | + public function register($meta_key, $property_service) { |
|
47 | 47 | |
48 | - $this->property_services[ $meta_key ] = $property_service; |
|
48 | + $this->property_services[$meta_key] = $property_service; |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key. |
60 | 60 | */ |
61 | - public function get( $meta_key ) { |
|
61 | + public function get($meta_key) { |
|
62 | 62 | |
63 | - $service = $this->property_services[ $meta_key ]; |
|
63 | + $service = $this->property_services[$meta_key]; |
|
64 | 64 | |
65 | 65 | return $service ? $service : $this->default_property_service; |
66 | 66 | } |