@@ -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 | } |
@@ -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 | } |
@@ -18,46 +18,46 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Post_Image_Storage extends Wordlift_Storage { |
20 | 20 | |
21 | - /** |
|
22 | - * Get the property value. |
|
23 | - * |
|
24 | - * @param int $post_id The {@link WP_Post}'s id. |
|
25 | - * |
|
26 | - * @return array|string|null A single string, or an array of values or null |
|
27 | - * if the property isn't recognized. |
|
28 | - * @since 3.15.0 |
|
29 | - */ |
|
30 | - public function get( $post_id ) { |
|
31 | - |
|
32 | - // Prepare the return array. |
|
33 | - $image_urls = array(); |
|
34 | - |
|
35 | - // If there is a featured image it has the priority. |
|
36 | - $featured_image_id = get_post_thumbnail_id( $post_id ); |
|
37 | - if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) { |
|
38 | - $image_url = wp_get_attachment_url( $featured_image_id ); |
|
39 | - |
|
40 | - $image_urls[] = $image_url; |
|
41 | - } |
|
42 | - |
|
43 | - $images = get_children( |
|
44 | - array( |
|
45 | - 'post_parent' => $post_id, |
|
46 | - 'post_type' => 'attachment', |
|
47 | - 'post_mime_type' => 'image', |
|
48 | - ) |
|
49 | - ); |
|
50 | - |
|
51 | - // Collect the URLs. |
|
52 | - foreach ( $images as $attachment_id => $attachment ) { |
|
53 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
54 | - // Ensure the URL isn't collected already. |
|
55 | - if ( ! in_array( $image_url, $image_urls, true ) ) { |
|
56 | - array_push( $image_urls, $image_url ); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - return $image_urls; |
|
61 | - } |
|
21 | + /** |
|
22 | + * Get the property value. |
|
23 | + * |
|
24 | + * @param int $post_id The {@link WP_Post}'s id. |
|
25 | + * |
|
26 | + * @return array|string|null A single string, or an array of values or null |
|
27 | + * if the property isn't recognized. |
|
28 | + * @since 3.15.0 |
|
29 | + */ |
|
30 | + public function get( $post_id ) { |
|
31 | + |
|
32 | + // Prepare the return array. |
|
33 | + $image_urls = array(); |
|
34 | + |
|
35 | + // If there is a featured image it has the priority. |
|
36 | + $featured_image_id = get_post_thumbnail_id( $post_id ); |
|
37 | + if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) { |
|
38 | + $image_url = wp_get_attachment_url( $featured_image_id ); |
|
39 | + |
|
40 | + $image_urls[] = $image_url; |
|
41 | + } |
|
42 | + |
|
43 | + $images = get_children( |
|
44 | + array( |
|
45 | + 'post_parent' => $post_id, |
|
46 | + 'post_type' => 'attachment', |
|
47 | + 'post_mime_type' => 'image', |
|
48 | + ) |
|
49 | + ); |
|
50 | + |
|
51 | + // Collect the URLs. |
|
52 | + foreach ( $images as $attachment_id => $attachment ) { |
|
53 | + $image_url = wp_get_attachment_url( $attachment_id ); |
|
54 | + // Ensure the URL isn't collected already. |
|
55 | + if ( ! in_array( $image_url, $image_urls, true ) ) { |
|
56 | + array_push( $image_urls, $image_url ); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + return $image_urls; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | * if the property isn't recognized. |
28 | 28 | * @since 3.15.0 |
29 | 29 | */ |
30 | - public function get( $post_id ) { |
|
30 | + public function get($post_id) { |
|
31 | 31 | |
32 | 32 | // Prepare the return array. |
33 | 33 | $image_urls = array(); |
34 | 34 | |
35 | 35 | // If there is a featured image it has the priority. |
36 | - $featured_image_id = get_post_thumbnail_id( $post_id ); |
|
37 | - if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) { |
|
38 | - $image_url = wp_get_attachment_url( $featured_image_id ); |
|
36 | + $featured_image_id = get_post_thumbnail_id($post_id); |
|
37 | + if (is_numeric($featured_image_id) && 0 < $featured_image_id) { |
|
38 | + $image_url = wp_get_attachment_url($featured_image_id); |
|
39 | 39 | |
40 | 40 | $image_urls[] = $image_url; |
41 | 41 | } |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | ); |
50 | 50 | |
51 | 51 | // Collect the URLs. |
52 | - foreach ( $images as $attachment_id => $attachment ) { |
|
53 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
52 | + foreach ($images as $attachment_id => $attachment) { |
|
53 | + $image_url = wp_get_attachment_url($attachment_id); |
|
54 | 54 | // Ensure the URL isn't collected already. |
55 | - if ( ! in_array( $image_url, $image_urls, true ) ) { |
|
56 | - array_push( $image_urls, $image_url ); |
|
55 | + if ( ! in_array($image_url, $image_urls, true)) { |
|
56 | + array_push($image_urls, $image_url); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 |
@@ -18,53 +18,53 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Post_Meta_Uri_Storage extends Wordlift_Post_Meta_Storage { |
20 | 20 | |
21 | - /** |
|
22 | - * The {@link Wordlift_Entity_Service} instance. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * @access private |
|
26 | - * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
27 | - */ |
|
28 | - private $entity_service; |
|
21 | + /** |
|
22 | + * The {@link Wordlift_Entity_Service} instance. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * @access private |
|
26 | + * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
27 | + */ |
|
28 | + private $entity_service; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Create a {@link Wordlift_Post_Meta_Uri_Storage} instance. |
|
32 | - * |
|
33 | - * @since 3.15.0 |
|
34 | - * |
|
35 | - * @param string $meta_key The meta key to read data from. |
|
36 | - * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
37 | - */ |
|
38 | - public function __construct( $meta_key, $entity_service ) { |
|
39 | - parent::__construct( $meta_key ); |
|
30 | + /** |
|
31 | + * Create a {@link Wordlift_Post_Meta_Uri_Storage} instance. |
|
32 | + * |
|
33 | + * @since 3.15.0 |
|
34 | + * |
|
35 | + * @param string $meta_key The meta key to read data from. |
|
36 | + * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
37 | + */ |
|
38 | + public function __construct( $meta_key, $entity_service ) { |
|
39 | + parent::__construct( $meta_key ); |
|
40 | 40 | |
41 | - $this->entity_service = $entity_service; |
|
41 | + $this->entity_service = $entity_service; |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the value for the specified meta key. |
|
47 | - * |
|
48 | - * The value is expected to be an entity post, for which the URI is loaded |
|
49 | - * and returned. |
|
50 | - * |
|
51 | - * @since 3.15.0 |
|
52 | - * |
|
53 | - * @param int $post_id The {@link WP_Post}'s id. |
|
54 | - * |
|
55 | - * @return array An array of URIs (or an empty array if nothing is set). |
|
56 | - */ |
|
57 | - public function get( $post_id ) { |
|
58 | - $values = parent::get( $post_id ); |
|
45 | + /** |
|
46 | + * Get the value for the specified meta key. |
|
47 | + * |
|
48 | + * The value is expected to be an entity post, for which the URI is loaded |
|
49 | + * and returned. |
|
50 | + * |
|
51 | + * @since 3.15.0 |
|
52 | + * |
|
53 | + * @param int $post_id The {@link WP_Post}'s id. |
|
54 | + * |
|
55 | + * @return array An array of URIs (or an empty array if nothing is set). |
|
56 | + */ |
|
57 | + public function get( $post_id ) { |
|
58 | + $values = parent::get( $post_id ); |
|
59 | 59 | |
60 | - $entity_service = $this->entity_service; |
|
60 | + $entity_service = $this->entity_service; |
|
61 | 61 | |
62 | - return array_map( |
|
63 | - function ( $item ) use ( $entity_service ) { |
|
64 | - return $entity_service->get_uri( $item ); |
|
65 | - }, |
|
66 | - $values |
|
67 | - ); |
|
68 | - } |
|
62 | + return array_map( |
|
63 | + function ( $item ) use ( $entity_service ) { |
|
64 | + return $entity_service->get_uri( $item ); |
|
65 | + }, |
|
66 | + $values |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * @param string $meta_key The meta key to read data from. |
36 | 36 | * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
37 | 37 | */ |
38 | - public function __construct( $meta_key, $entity_service ) { |
|
39 | - parent::__construct( $meta_key ); |
|
38 | + public function __construct($meta_key, $entity_service) { |
|
39 | + parent::__construct($meta_key); |
|
40 | 40 | |
41 | 41 | $this->entity_service = $entity_service; |
42 | 42 | |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return array An array of URIs (or an empty array if nothing is set). |
56 | 56 | */ |
57 | - public function get( $post_id ) { |
|
58 | - $values = parent::get( $post_id ); |
|
57 | + public function get($post_id) { |
|
58 | + $values = parent::get($post_id); |
|
59 | 59 | |
60 | 60 | $entity_service = $this->entity_service; |
61 | 61 | |
62 | 62 | return array_map( |
63 | - function ( $item ) use ( $entity_service ) { |
|
64 | - return $entity_service->get_uri( $item ); |
|
63 | + function($item) use ($entity_service) { |
|
64 | + return $entity_service->get_uri($item); |
|
65 | 65 | }, |
66 | 66 | $values |
67 | 67 | ); |
@@ -18,52 +18,52 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Post_Taxonomy_Storage extends Wordlift_Storage { |
20 | 20 | |
21 | - /** |
|
22 | - * The taxonomy name. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * @access private |
|
26 | - * @var string $taxonomy The taxonomy name. |
|
27 | - */ |
|
28 | - private $taxonomy; |
|
21 | + /** |
|
22 | + * The taxonomy name. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * @access private |
|
26 | + * @var string $taxonomy The taxonomy name. |
|
27 | + */ |
|
28 | + private $taxonomy; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified |
|
32 | - * taxonomy name. |
|
33 | - * |
|
34 | - * @since 3.15.0 |
|
35 | - * |
|
36 | - * @param string $taxonomy The taxonomy name. |
|
37 | - */ |
|
38 | - public function __construct( $taxonomy ) { |
|
30 | + /** |
|
31 | + * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified |
|
32 | + * taxonomy name. |
|
33 | + * |
|
34 | + * @since 3.15.0 |
|
35 | + * |
|
36 | + * @param string $taxonomy The taxonomy name. |
|
37 | + */ |
|
38 | + public function __construct( $taxonomy ) { |
|
39 | 39 | |
40 | - $this->taxonomy = $taxonomy; |
|
41 | - } |
|
40 | + $this->taxonomy = $taxonomy; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get the taxonomy's terms associated with the specified {@link WP_Post}. |
|
45 | - * |
|
46 | - * @since 3.15.0 |
|
47 | - * |
|
48 | - * @param int $post_id The {@link WP_Post}'s id. |
|
49 | - * |
|
50 | - * @return array|WP_Error An array of terms or {@link WP_Error} in case of error. |
|
51 | - */ |
|
52 | - public function get( $post_id ) { |
|
43 | + /** |
|
44 | + * Get the taxonomy's terms associated with the specified {@link WP_Post}. |
|
45 | + * |
|
46 | + * @since 3.15.0 |
|
47 | + * |
|
48 | + * @param int $post_id The {@link WP_Post}'s id. |
|
49 | + * |
|
50 | + * @return array|WP_Error An array of terms or {@link WP_Error} in case of error. |
|
51 | + */ |
|
52 | + public function get( $post_id ) { |
|
53 | 53 | |
54 | - return wp_get_post_terms( |
|
55 | - $post_id, |
|
56 | - $this->taxonomy, |
|
57 | - array( |
|
58 | - 'hide_empty' => false, |
|
59 | - // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
60 | - // An issue has been opened with the AAM plugin author as well. |
|
61 | - // |
|
62 | - // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
63 | - // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
64 | - 'fields' => 'all', |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
54 | + return wp_get_post_terms( |
|
55 | + $post_id, |
|
56 | + $this->taxonomy, |
|
57 | + array( |
|
58 | + 'hide_empty' => false, |
|
59 | + // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
60 | + // An issue has been opened with the AAM plugin author as well. |
|
61 | + // |
|
62 | + // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
63 | + // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
64 | + 'fields' => 'all', |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param string $taxonomy The taxonomy name. |
37 | 37 | */ |
38 | - public function __construct( $taxonomy ) { |
|
38 | + public function __construct($taxonomy) { |
|
39 | 39 | |
40 | 40 | $this->taxonomy = $taxonomy; |
41 | 41 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @return array|WP_Error An array of terms or {@link WP_Error} in case of error. |
51 | 51 | */ |
52 | - public function get( $post_id ) { |
|
52 | + public function get($post_id) { |
|
53 | 53 | |
54 | 54 | return wp_get_post_terms( |
55 | 55 | $post_id, |
@@ -18,37 +18,37 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Post_Schema_Class_Storage extends Wordlift_Storage { |
20 | 20 | |
21 | - /** |
|
22 | - * Get the schema class for the specified {@link WP_Post}. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * |
|
26 | - * @param int $post_id The {@link WP_Post}'s id. |
|
27 | - * |
|
28 | - * @return string|array An array of schema classes. |
|
29 | - */ |
|
30 | - public function get( $post_id ) { |
|
31 | - |
|
32 | - // Get the type names (CamelCase). |
|
33 | - $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id ); |
|
34 | - |
|
35 | - // If we don't find any type use the legacy function to get the URI. |
|
36 | - if ( empty( $names ) ) { |
|
37 | - $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id ); |
|
38 | - |
|
39 | - return $type['uri']; |
|
40 | - } |
|
41 | - |
|
42 | - // Prepend the `schema.org` base URI. |
|
43 | - $uris = array_map( |
|
44 | - function ( $item ) { |
|
45 | - return "http://schema.org/$item"; |
|
46 | - }, |
|
47 | - $names |
|
48 | - ); |
|
49 | - |
|
50 | - // Finally return the schema uri. |
|
51 | - return 1 === count( $uris ) ? $uris[0] : $uris; |
|
52 | - } |
|
21 | + /** |
|
22 | + * Get the schema class for the specified {@link WP_Post}. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * |
|
26 | + * @param int $post_id The {@link WP_Post}'s id. |
|
27 | + * |
|
28 | + * @return string|array An array of schema classes. |
|
29 | + */ |
|
30 | + public function get( $post_id ) { |
|
31 | + |
|
32 | + // Get the type names (CamelCase). |
|
33 | + $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id ); |
|
34 | + |
|
35 | + // If we don't find any type use the legacy function to get the URI. |
|
36 | + if ( empty( $names ) ) { |
|
37 | + $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id ); |
|
38 | + |
|
39 | + return $type['uri']; |
|
40 | + } |
|
41 | + |
|
42 | + // Prepend the `schema.org` base URI. |
|
43 | + $uris = array_map( |
|
44 | + function ( $item ) { |
|
45 | + return "http://schema.org/$item"; |
|
46 | + }, |
|
47 | + $names |
|
48 | + ); |
|
49 | + |
|
50 | + // Finally return the schema uri. |
|
51 | + return 1 === count( $uris ) ? $uris[0] : $uris; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } |
@@ -27,28 +27,28 @@ |
||
27 | 27 | * |
28 | 28 | * @return string|array An array of schema classes. |
29 | 29 | */ |
30 | - public function get( $post_id ) { |
|
30 | + public function get($post_id) { |
|
31 | 31 | |
32 | 32 | // Get the type names (CamelCase). |
33 | - $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id ); |
|
33 | + $names = Wordlift_Entity_Type_Service::get_instance()->get_names($post_id); |
|
34 | 34 | |
35 | 35 | // If we don't find any type use the legacy function to get the URI. |
36 | - if ( empty( $names ) ) { |
|
37 | - $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id ); |
|
36 | + if (empty($names)) { |
|
37 | + $type = Wordlift_Entity_Type_Service::get_instance()->get($post_id); |
|
38 | 38 | |
39 | 39 | return $type['uri']; |
40 | 40 | } |
41 | 41 | |
42 | 42 | // Prepend the `schema.org` base URI. |
43 | 43 | $uris = array_map( |
44 | - function ( $item ) { |
|
44 | + function($item) { |
|
45 | 45 | return "http://schema.org/$item"; |
46 | 46 | }, |
47 | 47 | $names |
48 | 48 | ); |
49 | 49 | |
50 | 50 | // Finally return the schema uri. |
51 | - return 1 === count( $uris ) ? $uris[0] : $uris; |
|
51 | + return 1 === count($uris) ? $uris[0] : $uris; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -21,56 +21,56 @@ |
||
21 | 21 | */ |
22 | 22 | class Wordlift_Post_Related_Storage extends Wordlift_Storage { |
23 | 23 | |
24 | - /** |
|
25 | - * The {@link Wordlift_Entity_Service} instance. |
|
26 | - * |
|
27 | - * @since 3.15.0 |
|
28 | - * @access private |
|
29 | - * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
30 | - */ |
|
31 | - private $entity_service; |
|
24 | + /** |
|
25 | + * The {@link Wordlift_Entity_Service} instance. |
|
26 | + * |
|
27 | + * @since 3.15.0 |
|
28 | + * @access private |
|
29 | + * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
30 | + */ |
|
31 | + private $entity_service; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Create a {@link Wordlift_Post_Related_Storage} instance. |
|
35 | - * |
|
36 | - * @since 3.15.0 |
|
37 | - * |
|
38 | - * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
39 | - */ |
|
40 | - public function __construct( $entity_service ) { |
|
33 | + /** |
|
34 | + * Create a {@link Wordlift_Post_Related_Storage} instance. |
|
35 | + * |
|
36 | + * @since 3.15.0 |
|
37 | + * |
|
38 | + * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
39 | + */ |
|
40 | + public function __construct( $entity_service ) { |
|
41 | 41 | |
42 | - $this->entity_service = $entity_service; |
|
42 | + $this->entity_service = $entity_service; |
|
43 | 43 | |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the property value. |
|
48 | - * |
|
49 | - * There is no filter for entities or posts, the returned data here can |
|
50 | - * be used for `relations` and `references` according to the client. |
|
51 | - * |
|
52 | - * @since 3.15.0 |
|
53 | - * |
|
54 | - * @param int $post_id The {@link WP_Post}'s id. |
|
55 | - * |
|
56 | - * @return array|string|null A single string, or an array of values or null |
|
57 | - * if the property isn't recognized. |
|
58 | - */ |
|
59 | - public function get( $post_id ) { |
|
46 | + /** |
|
47 | + * Get the property value. |
|
48 | + * |
|
49 | + * There is no filter for entities or posts, the returned data here can |
|
50 | + * be used for `relations` and `references` according to the client. |
|
51 | + * |
|
52 | + * @since 3.15.0 |
|
53 | + * |
|
54 | + * @param int $post_id The {@link WP_Post}'s id. |
|
55 | + * |
|
56 | + * @return array|string|null A single string, or an array of values or null |
|
57 | + * if the property isn't recognized. |
|
58 | + */ |
|
59 | + public function get( $post_id ) { |
|
60 | 60 | |
61 | - // get related entities. |
|
62 | - $related = wl_core_get_related_entity_ids( $post_id ); |
|
61 | + // get related entities. |
|
62 | + $related = wl_core_get_related_entity_ids( $post_id ); |
|
63 | 63 | |
64 | - // A reference to the entity service. |
|
65 | - $entity_service = $this->entity_service; |
|
64 | + // A reference to the entity service. |
|
65 | + $entity_service = $this->entity_service; |
|
66 | 66 | |
67 | - // Map the related posts' ids to URIs. |
|
68 | - return array_map( |
|
69 | - function ( $item ) use ( $entity_service ) { |
|
70 | - return $entity_service->get_uri( $item ); |
|
71 | - }, |
|
72 | - $related |
|
73 | - ); |
|
74 | - } |
|
67 | + // Map the related posts' ids to URIs. |
|
68 | + return array_map( |
|
69 | + function ( $item ) use ( $entity_service ) { |
|
70 | + return $entity_service->get_uri( $item ); |
|
71 | + }, |
|
72 | + $related |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
39 | 39 | */ |
40 | - public function __construct( $entity_service ) { |
|
40 | + public function __construct($entity_service) { |
|
41 | 41 | |
42 | 42 | $this->entity_service = $entity_service; |
43 | 43 | |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | * @return array|string|null A single string, or an array of values or null |
57 | 57 | * if the property isn't recognized. |
58 | 58 | */ |
59 | - public function get( $post_id ) { |
|
59 | + public function get($post_id) { |
|
60 | 60 | |
61 | 61 | // get related entities. |
62 | - $related = wl_core_get_related_entity_ids( $post_id ); |
|
62 | + $related = wl_core_get_related_entity_ids($post_id); |
|
63 | 63 | |
64 | 64 | // A reference to the entity service. |
65 | 65 | $entity_service = $this->entity_service; |
66 | 66 | |
67 | 67 | // Map the related posts' ids to URIs. |
68 | 68 | return array_map( |
69 | - function ( $item ) use ( $entity_service ) { |
|
70 | - return $entity_service->get_uri( $item ); |
|
69 | + function($item) use ($entity_service) { |
|
70 | + return $entity_service->get_uri($item); |
|
71 | 71 | }, |
72 | 72 | $related |
73 | 73 | ); |
@@ -14,77 +14,77 @@ |
||
14 | 14 | */ |
15 | 15 | class Wordlift_Tinymce_Adapter { |
16 | 16 | |
17 | - /** |
|
18 | - * The {@link Wordlift} plugin instance. |
|
19 | - * |
|
20 | - * @since 3.12.0 |
|
21 | - * @access private |
|
22 | - * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
23 | - */ |
|
24 | - private $plugin; |
|
17 | + /** |
|
18 | + * The {@link Wordlift} plugin instance. |
|
19 | + * |
|
20 | + * @since 3.12.0 |
|
21 | + * @access private |
|
22 | + * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
23 | + */ |
|
24 | + private $plugin; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Wordlift_Tinymce_Adapter constructor. |
|
28 | - * |
|
29 | - * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
30 | - */ |
|
31 | - public function __construct( $plugin ) { |
|
26 | + /** |
|
27 | + * Wordlift_Tinymce_Adapter constructor. |
|
28 | + * |
|
29 | + * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
30 | + */ |
|
31 | + public function __construct( $plugin ) { |
|
32 | 32 | |
33 | - $this->plugin = $plugin; |
|
33 | + $this->plugin = $plugin; |
|
34 | 34 | |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook. |
|
39 | - * |
|
40 | - * @param array $plugins The existing plugins array. |
|
41 | - * |
|
42 | - * @return array The modified plugins array. |
|
43 | - * @since 3.12.0 |
|
44 | - */ |
|
45 | - public function mce_external_plugins( $plugins ) { |
|
37 | + /** |
|
38 | + * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook. |
|
39 | + * |
|
40 | + * @param array $plugins The existing plugins array. |
|
41 | + * |
|
42 | + * @return array The modified plugins array. |
|
43 | + * @since 3.12.0 |
|
44 | + */ |
|
45 | + public function mce_external_plugins( $plugins ) { |
|
46 | 46 | |
47 | - /** |
|
48 | - * Bail out if you are on Media Library |
|
49 | - * |
|
50 | - * @since 3.27.1 |
|
51 | - * |
|
52 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1122 |
|
53 | - */ |
|
54 | - if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) { |
|
55 | - return $plugins; |
|
56 | - } |
|
47 | + /** |
|
48 | + * Bail out if you are on Media Library |
|
49 | + * |
|
50 | + * @since 3.27.1 |
|
51 | + * |
|
52 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1122 |
|
53 | + */ |
|
54 | + if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) { |
|
55 | + return $plugins; |
|
56 | + } |
|
57 | 57 | |
58 | - /* |
|
58 | + /* |
|
59 | 59 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
60 | 60 | * |
61 | 61 | * @since 3.20.3 |
62 | 62 | * |
63 | 63 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
64 | 64 | */ |
65 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
66 | - return $plugins; |
|
67 | - } |
|
65 | + if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
66 | + return $plugins; |
|
67 | + } |
|
68 | 68 | |
69 | - // Get WordLift's version as a cache killer. |
|
70 | - $version = $this->plugin->get_version(); |
|
69 | + // Get WordLift's version as a cache killer. |
|
70 | + $version = $this->plugin->get_version(); |
|
71 | 71 | |
72 | - // User can edit? |
|
73 | - $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
72 | + // User can edit? |
|
73 | + $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
74 | 74 | |
75 | - // If user can't edit or rich editing isn't enabled, bail out. |
|
76 | - if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
77 | - return $plugins; |
|
78 | - } |
|
75 | + // If user can't edit or rich editing isn't enabled, bail out. |
|
76 | + if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
77 | + return $plugins; |
|
78 | + } |
|
79 | 79 | |
80 | - // Add our own JavaScript file to TinyMCE's extensions. |
|
81 | - // DO NOT use the minified version, it'll yield errors with AngularJS. |
|
82 | - $plugins['wordlift'] = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
83 | - $plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
84 | - $plugins['wl_tinymce'] = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
85 | - $plugins['wl_tinymce_2'] = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version; |
|
80 | + // Add our own JavaScript file to TinyMCE's extensions. |
|
81 | + // DO NOT use the minified version, it'll yield errors with AngularJS. |
|
82 | + $plugins['wordlift'] = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
83 | + $plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
84 | + $plugins['wl_tinymce'] = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
85 | + $plugins['wl_tinymce_2'] = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version; |
|
86 | 86 | |
87 | - return $plugins; |
|
88 | - } |
|
87 | + return $plugins; |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
30 | 30 | */ |
31 | - public function __construct( $plugin ) { |
|
31 | + public function __construct($plugin) { |
|
32 | 32 | |
33 | 33 | $this->plugin = $plugin; |
34 | 34 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @return array The modified plugins array. |
43 | 43 | * @since 3.12.0 |
44 | 44 | */ |
45 | - public function mce_external_plugins( $plugins ) { |
|
45 | + public function mce_external_plugins($plugins) { |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Bail out if you are on Media Library |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @see https://github.com/insideout10/wordlift-plugin/issues/1122 |
53 | 53 | */ |
54 | - if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) { |
|
54 | + if (isset(get_current_screen()->base) && get_current_screen()->base === 'upload') { |
|
55 | 55 | return $plugins; |
56 | 56 | } |
57 | 57 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
64 | 64 | */ |
65 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
65 | + if ( ! apply_filters('wl_can_see_classification_box', true)) { |
|
66 | 66 | return $plugins; |
67 | 67 | } |
68 | 68 | |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | $version = $this->plugin->get_version(); |
71 | 71 | |
72 | 72 | // User can edit? |
73 | - $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
73 | + $can_edit = current_user_can('edit_posts') || current_user_can('edit_pages'); |
|
74 | 74 | |
75 | 75 | // If user can't edit or rich editing isn't enabled, bail out. |
76 | - if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
76 | + if ( ! $can_edit || ! get_user_option('rich_editing')) { |
|
77 | 77 | return $plugins; |
78 | 78 | } |
79 | 79 | |
80 | 80 | // Add our own JavaScript file to TinyMCE's extensions. |
81 | 81 | // DO NOT use the minified version, it'll yield errors with AngularJS. |
82 | - $plugins['wordlift'] = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
83 | - $plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
84 | - $plugins['wl_tinymce'] = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
85 | - $plugins['wl_tinymce_2'] = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version; |
|
82 | + $plugins['wordlift'] = plugin_dir_url(__DIR__).'js/wordlift-reloaded.js?ver='.$version; |
|
83 | + $plugins['wl_shortcodes'] = plugin_dir_url(__DIR__).'admin/js/wordlift_shortcode_tinymce_plugin.js?ver='.$version; |
|
84 | + $plugins['wl_tinymce'] = plugin_dir_url(__DIR__).'admin/js/1/tinymce.js?ver='.$version; |
|
85 | + $plugins['wl_tinymce_2'] = plugin_dir_url(__DIR__).'js/dist/tiny-mce.js?ver='.$version; |
|
86 | 86 | |
87 | 87 | return $plugins; |
88 | 88 | } |