|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The plugin bootstrap file |
|
4
|
|
|
* |
|
5
|
|
|
* This file is read by WordPress to generate the plugin information in the plugin |
|
6
|
|
|
* admin area. This file also includes all of the dependencies used by the plugin, |
|
7
|
|
|
* registers the activation and deactivation functions, and defines a function |
|
8
|
|
|
* that starts the plugin. |
|
9
|
|
|
* |
|
10
|
|
|
* @link https://wordlift.io |
|
11
|
|
|
* @since 1.0.0 |
|
12
|
|
|
* @package Wordlift |
|
13
|
|
|
* |
|
14
|
|
|
* @wordpress-plugin |
|
15
|
|
|
* Plugin Name: WordLift |
|
16
|
|
|
* Plugin URI: https://wordlift.io |
|
17
|
|
|
* Description: WordLift brings the power of AI to organize content, attract new readers and get their attention. To activate the plugin <a href="https://wordlift.io/">visit our website</a>. |
|
18
|
|
|
* Version: 3.27.5 |
|
19
|
|
|
* Author: WordLift, Insideout10 |
|
20
|
|
|
* Author URI: https://wordlift.io |
|
21
|
|
|
* License: GPL-2.0+ |
|
22
|
|
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
|
23
|
|
|
* Text Domain: wordlift |
|
24
|
|
|
* Domain Path: /languages |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
use Wordlift\Api\Default_Api_Service; |
|
28
|
|
|
use Wordlift\Api\User_Agent; |
|
29
|
|
|
use Wordlift\Cache\Ttl_Cache; |
|
30
|
|
|
use Wordlift\Cache\Ttl_Cache_Cleaner; |
|
31
|
|
|
use Wordlift\Images_Licenses\Admin\Image_License_Page; |
|
32
|
|
|
use Wordlift\Images_Licenses\Cached_Image_License_Service; |
|
33
|
|
|
use Wordlift\Images_Licenses\Image_License_Cleanup_Service; |
|
34
|
|
|
use Wordlift\Images_Licenses\Image_License_Factory; |
|
35
|
|
|
use Wordlift\Images_Licenses\Image_License_Notifier; |
|
36
|
|
|
use Wordlift\Images_Licenses\Image_License_Scheduler; |
|
37
|
|
|
use Wordlift\Images_Licenses\Image_License_Service; |
|
38
|
|
|
use Wordlift\Images_Licenses\Tasks\Add_License_Caption_Or_Remove_Page; |
|
39
|
|
|
use Wordlift\Images_Licenses\Tasks\Add_License_Caption_Or_Remove_Task; |
|
40
|
|
|
use Wordlift\Images_Licenses\Tasks\Reload_Data_Page; |
|
41
|
|
|
use Wordlift\Images_Licenses\Tasks\Reload_Data_Task; |
|
42
|
|
|
use Wordlift\Images_Licenses\Tasks\Remove_All_Images_Page; |
|
43
|
|
|
use Wordlift\Images_Licenses\Tasks\Remove_All_Images_Task; |
|
44
|
|
|
use Wordlift\Post\Post_Adapter; |
|
45
|
|
|
use Wordlift\Tasks\Task_Ajax_Adapter; |
|
46
|
|
|
use Wordlift\Tasks\Task_Ajax_Adapters_Registry; |
|
47
|
|
|
|
|
48
|
|
|
// If this file is called directly, abort. |
|
49
|
|
|
if ( ! defined( 'WPINC' ) ) { |
|
50
|
|
|
die; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// Include WordLift constants. |
|
54
|
|
|
require_once( 'wordlift_constants.php' ); |
|
55
|
|
|
|
|
56
|
|
|
// Load modules. |
|
57
|
|
|
require_once( 'modules/core/wordlift_core.php' ); |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Log to the debug.log file. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string|mixed $log The log data. |
|
63
|
|
|
* |
|
64
|
|
|
* @since 3.0.0 |
|
65
|
|
|
* |
|
66
|
|
|
* @deprecated use Wordlift_Log_Service::get_instance()->info( $log ); |
|
67
|
|
|
* |
|
68
|
|
|
*/ |
|
69
|
|
|
function wl_write_log( $log ) { |
|
70
|
|
|
|
|
71
|
|
|
Wordlift_Log_Service::get_instance()->debug( $log ); |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Hide the WordLift Key from the provided text. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $text A text that may potentially contain a WL key. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string A text with the key hidden. |
|
81
|
|
|
* @deprecated |
|
82
|
|
|
* |
|
83
|
|
|
* @since 3.0.0 |
|
84
|
|
|
* |
|
85
|
|
|
*/ |
|
86
|
|
|
function wl_write_log_hide_key( $text ) { |
|
87
|
|
|
|
|
88
|
|
|
return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Enable microdata schema.org tagging. |
|
93
|
|
|
* see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/ |
|
94
|
|
|
*/ |
|
95
|
|
|
function wordlift_allowed_post_tags() { |
|
96
|
|
|
global $allowedposttags; |
|
97
|
|
|
|
|
98
|
|
|
$tags = array( 'span' ); |
|
99
|
|
|
$new_attributes = array( |
|
100
|
|
|
'itemscope' => array(), |
|
101
|
|
|
'itemtype' => array(), |
|
102
|
|
|
'itemprop' => array(), |
|
103
|
|
|
'itemid' => array(), |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
foreach ( $tags as $tag ) { |
|
107
|
|
|
if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
108
|
|
|
$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
// add allowed post tags. |
|
114
|
|
|
add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Register additional scripts for the admin UI. |
|
118
|
|
|
*/ |
|
119
|
|
|
function wordlift_admin_enqueue_scripts() { |
|
120
|
|
|
|
|
121
|
|
|
// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
122
|
|
|
wp_enqueue_script( 'wpdialogs' ); |
|
123
|
|
|
wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
124
|
|
|
|
|
125
|
|
|
wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
126
|
|
|
|
|
127
|
|
|
wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
128
|
|
|
|
|
129
|
|
|
// Disable auto-save for custom entity posts only |
|
130
|
|
|
if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
131
|
|
|
wp_dequeue_script( 'autosave' ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Hooked to *wp_kses_allowed_html* filter, adds microdata attributes. |
|
140
|
|
|
* |
|
141
|
|
|
* @param array $allowedtags The array with the currently configured elements and attributes. |
|
142
|
|
|
* @param string $context The context. |
|
143
|
|
|
* |
|
144
|
|
|
* @return array An array which contains allowed microdata attributes. |
|
145
|
|
|
*/ |
|
146
|
|
|
function wordlift_allowed_html( $allowedtags, $context ) { |
|
147
|
|
|
|
|
148
|
|
|
if ( 'post' !== $context ) { |
|
149
|
|
|
return $allowedtags; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return array_merge_recursive( $allowedtags, array( |
|
153
|
|
|
'span' => array( |
|
154
|
|
|
'itemscope' => true, |
|
155
|
|
|
'itemtype' => true, |
|
156
|
|
|
'itemid' => true, |
|
157
|
|
|
'itemprop' => true, |
|
158
|
|
|
), |
|
159
|
|
|
) ); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Get the coordinates for the specified post ID. |
|
166
|
|
|
* |
|
167
|
|
|
* @param int $post_id The post ID. |
|
168
|
|
|
* |
|
169
|
|
|
* @return array|null An array of coordinates or null. |
|
170
|
|
|
*/ |
|
171
|
|
|
function wl_get_coordinates( $post_id ) { |
|
172
|
|
|
|
|
173
|
|
|
$latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
174
|
|
|
$longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
175
|
|
|
|
|
176
|
|
|
// DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
177
|
|
|
// place on the globe:"The zero/zero point of this system is located in the |
|
178
|
|
|
// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
179
|
|
|
return array( |
|
180
|
|
|
'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
181
|
|
|
'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
182
|
|
|
); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Get all the images bound to a post. |
|
187
|
|
|
* |
|
188
|
|
|
* @param int $post_id The post ID. |
|
189
|
|
|
* |
|
190
|
|
|
* @return array An array of image URLs. |
|
191
|
|
|
* @deprecated use Wordlift_Storage_Factory::get_instance()->post_images()->get( $post_id ) |
|
192
|
|
|
* |
|
193
|
|
|
*/ |
|
194
|
|
|
function wl_get_image_urls( $post_id ) { |
|
195
|
|
|
|
|
196
|
|
|
return Wordlift_Storage_Factory::get_instance() |
|
197
|
|
|
->post_images() |
|
198
|
|
|
->get( $post_id ); |
|
199
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Get an attachment with the specified parent post ID and source URL. |
|
204
|
|
|
* |
|
205
|
|
|
* @param int $parent_post_id The parent post ID. |
|
206
|
|
|
* @param string $source_url The source URL. |
|
207
|
|
|
* |
|
208
|
|
|
* @return WP_Post|null A post instance or null if not found. |
|
209
|
|
|
*/ |
|
210
|
|
|
function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
211
|
|
|
|
|
212
|
|
|
// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
213
|
|
|
|
|
214
|
|
|
$posts = get_posts( array( |
|
215
|
|
|
'post_type' => 'attachment', |
|
216
|
|
|
'posts_per_page' => 1, |
|
217
|
|
|
'post_status' => 'any', |
|
218
|
|
|
'post_parent' => $parent_post_id, |
|
219
|
|
|
'meta_key' => 'wl_source_url', |
|
220
|
|
|
'meta_value' => $source_url, |
|
221
|
|
|
) ); |
|
222
|
|
|
|
|
223
|
|
|
// Return the found post. |
|
224
|
|
|
if ( 1 === count( $posts ) ) { |
|
225
|
|
|
return $posts[0]; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
// Return null. |
|
229
|
|
|
return null; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* Set the source URL. |
|
234
|
|
|
* |
|
235
|
|
|
* @param int $post_id The post ID. |
|
236
|
|
|
* @param string $source_url The source URL. |
|
237
|
|
|
*/ |
|
238
|
|
|
function wl_set_source_url( $post_id, $source_url ) { |
|
239
|
|
|
|
|
240
|
|
|
delete_post_meta( $post_id, 'wl_source_url' ); |
|
241
|
|
|
add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Sanitizes an URI path by replacing the non allowed characters with an underscore. |
|
246
|
|
|
* |
|
247
|
|
|
* @param string $path The path to sanitize. |
|
248
|
|
|
* @param string $char The replacement character (by default an underscore). |
|
249
|
|
|
* |
|
250
|
|
|
* @return string The sanitized path. |
|
251
|
|
|
* @uses sanitize_title() to manage not ASCII chars |
|
252
|
|
|
* @deprecated use Wordlift_Uri_Service::get_instance()->sanitize_path(); |
|
253
|
|
|
* @see https://codex.wordpress.org/Function_Reference/sanitize_title |
|
254
|
|
|
* |
|
255
|
|
|
*/ |
|
256
|
|
|
function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
257
|
|
|
|
|
258
|
|
|
return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Replaces the *itemid* attributes URIs with the WordLift URIs. |
|
263
|
|
|
* |
|
264
|
|
|
* @param string $content The post content. |
|
265
|
|
|
* |
|
266
|
|
|
* @return string The updated post content. |
|
267
|
|
|
*/ |
|
268
|
|
|
function wl_replace_item_id_with_uri( $content ) { |
|
269
|
|
|
|
|
270
|
|
|
$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
271
|
|
|
$log->trace( 'Replacing item IDs with URIs...' ); |
|
272
|
|
|
|
|
273
|
|
|
// Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
274
|
|
|
$content = stripslashes( $content ); |
|
275
|
|
|
|
|
276
|
|
|
// If any match are found. |
|
277
|
|
|
$matches = array(); |
|
278
|
|
|
if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
279
|
|
|
|
|
280
|
|
|
foreach ( $matches as $match ) { |
|
|
|
|
|
|
281
|
|
|
|
|
282
|
|
|
// Get the item ID. |
|
283
|
|
|
$item_id = $match[1]; |
|
284
|
|
|
|
|
285
|
|
|
// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
286
|
|
|
$post = Wordlift_Entity_Service::get_instance() |
|
|
|
|
|
|
287
|
|
|
->get_entity_post_by_uri( $item_id ); |
|
288
|
|
|
|
|
289
|
|
|
// If no entity is found, continue to the next one. |
|
290
|
|
|
if ( null === $post ) { |
|
291
|
|
|
continue; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
// Get the URI for that post. |
|
295
|
|
|
$uri = wl_get_entity_uri( $post->ID ); |
|
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
298
|
|
|
|
|
299
|
|
|
// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
300
|
|
|
if ( $item_id !== $uri ) { |
|
301
|
|
|
$uri_e = esc_html( $uri ); |
|
302
|
|
|
$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
303
|
|
|
} |
|
304
|
|
|
} |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
// Reapply slashes. |
|
308
|
|
|
$content = addslashes( $content ); |
|
309
|
|
|
|
|
310
|
|
|
return $content; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
314
|
|
|
|
|
315
|
|
|
require_once( 'wordlift_entity_functions.php' ); |
|
316
|
|
|
|
|
317
|
|
|
// add editor related methods. |
|
318
|
|
|
require_once( 'wordlift_editor.php' ); |
|
319
|
|
|
|
|
320
|
|
|
// add the WordLift entity custom type. |
|
321
|
|
|
require_once( 'wordlift_entity_type.php' ); |
|
322
|
|
|
|
|
323
|
|
|
// add callbacks on post save to notify data changes from wp to redlink triple store |
|
324
|
|
|
require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
325
|
|
|
|
|
326
|
|
|
require_once( 'modules/configuration/wordlift_configuration_settings.php' ); |
|
327
|
|
|
|
|
328
|
|
|
// Load modules |
|
329
|
|
|
require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
330
|
|
|
require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
331
|
|
|
require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
332
|
|
|
|
|
333
|
|
|
// Shortcodes |
|
334
|
|
|
|
|
335
|
|
|
require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
336
|
|
|
require_once( 'shortcodes/class-wordlift-shortcode-rest.php' ); |
|
337
|
|
|
require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
338
|
|
|
require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
339
|
|
|
require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
340
|
|
|
require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
341
|
|
|
require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
342
|
|
|
require_once( 'shortcodes/class-wordlift-products-navigator-shortcode-rest.php' ); |
|
343
|
|
|
|
|
344
|
|
|
require_once( 'widgets/wordlift_widget_geo.php' ); |
|
345
|
|
|
require_once( 'widgets/class-wordlift-chord-widget.php' ); |
|
346
|
|
|
require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
347
|
|
|
|
|
348
|
|
|
require_once( 'wordlift_redlink.php' ); |
|
349
|
|
|
|
|
350
|
|
|
// Add admin functions. |
|
351
|
|
|
// TODO: find a way to make 'admin' UI tests work. |
|
352
|
|
|
//if ( is_admin() ) { |
|
353
|
|
|
|
|
354
|
|
|
require_once( 'admin/wordlift_admin.php' ); |
|
355
|
|
|
require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
356
|
|
|
require_once( 'admin/wordlift_admin_save_post.php' ); |
|
357
|
|
|
|
|
358
|
|
|
// add the entities meta box. |
|
359
|
|
|
require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
360
|
|
|
|
|
361
|
|
|
// add the entity creation AJAX. |
|
362
|
|
|
require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
363
|
|
|
|
|
364
|
|
|
// Load the wl_chord TinyMCE button and configuration dialog. |
|
365
|
|
|
require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* The code that runs during plugin activation. |
|
369
|
|
|
* This action is documented in includes/class-wordlift-activator.php |
|
370
|
|
|
*/ |
|
371
|
|
|
function activate_wordlift() { |
|
372
|
|
|
|
|
373
|
|
|
$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
374
|
|
|
|
|
375
|
|
|
$log->info( 'Activating WordLift...' ); |
|
376
|
|
|
|
|
377
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
378
|
|
|
Wordlift_Activator::activate(); |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
382
|
|
|
* |
|
383
|
|
|
* @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
384
|
|
|
* @since 3.19.2 |
|
385
|
|
|
*/ |
|
386
|
|
|
Wordlift_Http_Api::activate(); |
|
387
|
|
|
|
|
388
|
|
|
// Ensure the post type is registered before flushing the rewrite rules. |
|
389
|
|
|
Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
390
|
|
|
flush_rewrite_rules(); |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* The code that runs during plugin deactivation. |
|
395
|
|
|
* This action is documented in includes/class-wordlift-deactivator.php |
|
396
|
|
|
*/ |
|
397
|
|
|
function deactivate_wordlift() { |
|
398
|
|
|
|
|
399
|
|
|
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
400
|
|
|
Wordlift_Deactivator::deactivate(); |
|
401
|
|
|
Wordlift_Http_Api::deactivate(); |
|
402
|
|
|
Ttl_Cache_Cleaner::deactivate(); |
|
403
|
|
|
flush_rewrite_rules(); |
|
404
|
|
|
|
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
408
|
|
|
register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* The core plugin class that is used to define internationalization, |
|
412
|
|
|
* admin-specific hooks, and public-facing site hooks. |
|
413
|
|
|
*/ |
|
414
|
|
|
require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
415
|
|
|
|
|
416
|
|
|
/** |
|
417
|
|
|
* Begins execution of the plugin. |
|
418
|
|
|
* |
|
419
|
|
|
* Since everything within the plugin is registered via hooks, |
|
420
|
|
|
* then kicking off the plugin from this point in the file does |
|
421
|
|
|
* not affect the page life cycle. |
|
422
|
|
|
* |
|
423
|
|
|
* @since 1.0.0 |
|
424
|
|
|
*/ |
|
425
|
|
|
function run_wordlift() { |
|
426
|
|
|
/** |
|
427
|
|
|
* Filter: wl_feature__enable__widgets. |
|
428
|
|
|
* |
|
429
|
|
|
* @param bool whether the widgets needed to be registered, defaults to true. |
|
430
|
|
|
* |
|
431
|
|
|
* @return bool |
|
432
|
|
|
* @since 3.27.6 |
|
433
|
|
|
*/ |
|
434
|
|
|
if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
435
|
|
|
add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
436
|
|
|
add_filter( 'widget_text', 'do_shortcode' ); |
|
437
|
|
|
add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
438
|
|
|
add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
439
|
|
|
add_filter( 'widget_text', 'do_shortcode' ); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Filter: wl_feature__enable__analysis |
|
445
|
|
|
* @param bool Whether to send api request to analysis or not |
|
446
|
|
|
* @return bool |
|
447
|
|
|
* @since 3.27.6 |
|
448
|
|
|
*/ |
|
449
|
|
|
if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
450
|
|
|
add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
451
|
|
|
} |
|
452
|
|
|
else { |
|
453
|
|
|
add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
/* |
|
457
|
|
|
* We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
|
458
|
|
|
* |
|
459
|
|
|
* @since 3.21.2 |
|
460
|
|
|
*/ |
|
461
|
|
|
wordlift_plugin_autoload_register(); |
|
462
|
|
|
|
|
463
|
|
|
$plugin = new Wordlift(); |
|
464
|
|
|
$plugin->run(); |
|
465
|
|
|
|
|
466
|
|
|
// Initialize the TTL Cache Cleaner. |
|
467
|
|
|
new Ttl_Cache_Cleaner(); |
|
468
|
|
|
|
|
469
|
|
|
// Load the new Post Adapter. |
|
470
|
|
|
new Post_Adapter(); |
|
471
|
|
|
|
|
472
|
|
|
// Licenses Images. |
|
473
|
|
|
$user_agent = User_Agent::get_user_agent(); |
|
474
|
|
|
$wordlift_key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
475
|
|
|
$api_service = new Default_Api_Service( 'https://api.wordlift.io', 60, $user_agent, $wordlift_key ); |
|
476
|
|
|
$image_license_factory = new Image_License_Factory(); |
|
477
|
|
|
$image_license_service = new Image_License_Service( $api_service, $image_license_factory ); |
|
478
|
|
|
$image_license_cache = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days. |
|
479
|
|
|
$cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache ); |
|
480
|
|
|
|
|
481
|
|
|
$image_license_scheduler = new Image_License_Scheduler( $image_license_service, $image_license_cache ); |
|
|
|
|
|
|
482
|
|
|
$image_license_cleanup_service = new Image_License_Cleanup_Service(); |
|
|
|
|
|
|
483
|
|
|
|
|
484
|
|
|
// Get the cached data. If we have cached data, we load the notifier. |
|
485
|
|
|
$image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES ); |
|
486
|
|
|
if ( null !== $image_license_data ) { |
|
487
|
|
|
$image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() ); |
|
488
|
|
|
new Image_License_Notifier( $image_license_data, $image_license_page ); |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
$remove_all_images_task = new Remove_All_Images_Task( $cached_image_license_service ); |
|
492
|
|
|
$remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task ); |
|
493
|
|
|
|
|
494
|
|
|
$reload_data_task = new Reload_Data_Task(); |
|
495
|
|
|
$reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task ); |
|
496
|
|
|
|
|
497
|
|
|
$add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service ); |
|
498
|
|
|
$add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task ); |
|
499
|
|
|
|
|
500
|
|
|
$remove_all_images_task_page = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() ); |
|
|
|
|
|
|
501
|
|
|
$reload_data_task_page = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() ); |
|
|
|
|
|
|
502
|
|
|
$add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() ); |
|
|
|
|
|
|
503
|
|
|
|
|
504
|
|
|
new Wordlift_Products_Navigator_Shortcode_REST(); |
|
505
|
|
|
|
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
run_wordlift(); |
|
509
|
|
|
|
|
510
|
|
|
/** |
|
511
|
|
|
* Register our autoload routine. |
|
512
|
|
|
* |
|
513
|
|
|
* @throws Exception |
|
514
|
|
|
* @since 3.21.2 |
|
515
|
|
|
*/ |
|
516
|
|
|
function wordlift_plugin_autoload_register() { |
|
517
|
|
|
|
|
518
|
|
|
spl_autoload_register( function ( $class_name ) { |
|
519
|
|
|
|
|
520
|
|
|
// Bail out if these are not our classes. |
|
521
|
|
|
if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
522
|
|
|
return false; |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
526
|
|
|
|
|
527
|
|
|
preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
528
|
|
|
|
|
529
|
|
|
$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
530
|
|
|
$file = 'class-' . $matches[2] . '.php'; |
|
531
|
|
|
|
|
532
|
|
|
$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
533
|
|
|
|
|
534
|
|
|
if ( ! file_exists( $full_path ) ) { |
|
535
|
|
|
echo( "Class $class_name not found at $full_path." ); |
|
536
|
|
|
|
|
537
|
|
|
return false; |
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
require_once $full_path; |
|
541
|
|
|
|
|
542
|
|
|
return true; |
|
543
|
|
|
} ); |
|
544
|
|
|
|
|
545
|
|
|
} |
|
546
|
|
|
|
|
547
|
|
|
function wl_block_categories( $categories, $post ) { |
|
|
|
|
|
|
548
|
|
|
return array_merge( |
|
549
|
|
|
$categories, |
|
550
|
|
|
array( |
|
551
|
|
|
array( |
|
552
|
|
|
'slug' => 'wordlift', |
|
553
|
|
|
'title' => __( 'WordLift', 'wordlift' ), |
|
554
|
|
|
), |
|
555
|
|
|
) |
|
556
|
|
|
); |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
add_filter( 'block_categories', 'wl_block_categories', 10, 2 ); |
|
560
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.