Completed
Push — master ( 829da2...8585d5 )
by David
03:05
created

Wordlift::define_public_hooks()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * The file that defines the core plugin class
5
 *
6
 * A class definition that includes attributes and functions used across both the
7
 * public-facing side of the site and the admin area.
8
 *
9
 * @link       http://wordlift.it
10
 * @since      1.0.0
11
 *
12
 * @package    Wordlift
13
 * @subpackage Wordlift/includes
14
 */
15
16
/**
17
 * The core plugin class.
18
 *
19
 * This is used to define internationalization, admin-specific hooks, and
20
 * public-facing site hooks.
21
 *
22
 * Also maintains the unique identifier of this plugin as well as the current
23
 * version of the plugin.
24
 *
25
 * @since      1.0.0
26
 * @package    Wordlift
27
 * @subpackage Wordlift/includes
28
 * @author     WordLift <[email protected]>
29
 */
30
class Wordlift {
31
32
	/**
33
	 * The loader that's responsible for maintaining and registering all hooks that power
34
	 * the plugin.
35
	 *
36
	 * @since    1.0.0
37
	 * @access   protected
38
	 * @var      Wordlift_Loader $loader Maintains and registers all hooks for the plugin.
39
	 */
40
	protected $loader;
41
42
	/**
43
	 * The unique identifier of this plugin.
44
	 *
45
	 * @since    1.0.0
46
	 * @access   protected
47
	 * @var      string $plugin_name The string used to uniquely identify this plugin.
48
	 */
49
	protected $plugin_name;
50
51
	/**
52
	 * The current version of the plugin.
53
	 *
54
	 * @since    1.0.0
55
	 * @access   protected
56
	 * @var      string $version The current version of the plugin.
57
	 */
58
	protected $version;
59
60
	/**
61
	 * The Thumbnail service.
62
	 *
63
	 * @since 3.1.5
64
	 * @access private
65
	 * @var \Wordlift_Thumbnail_Service $thumbnail_service The Thumbnail service.
66
	 */
67
	private $thumbnail_service;
68
69
	/**
70
	 * The UI service.
71
	 *
72
	 * @since 3.2.0
73
	 * @access private
74
	 * @var \Wordlift_UI_Service $ui_service The UI service.
75
	 */
76
	private $ui_service;
77
78
	/**
79
	 * The Schema service.
80
	 *
81
	 * @since 3.3.0
82
	 * @access private
83
	 * @var \Wordlift_Schema_Service $schema_service The Schema service.
84
	 */
85
	private $schema_service;
86
87
	/**
88
	 * The Entity service.
89
	 *
90
	 * @since 3.1.0
91
	 * @access private
92
	 * @var \Wordlift_Entity_Service $entity_service The Entity service.
93
	 */
94
	private $entity_service;
95
96
	/**
97
	 * The Topic Taxonomy service.
98
	 *
99
	 * @since 3.5.0
100
	 * @access private
101
	 * @var \Wordlift_Topic_Taxonomy_Service The Topic Taxonomy service.
102
	 */
103
	private $topic_taxonomy_service;
104
105
	/**
106
	 * The User service.
107
	 *
108
	 * @since 3.1.7
109
	 * @access private
110
	 * @var \Wordlift_User_Service $user_service The User service.
111
	 */
112
	private $user_service;
113
114
	/**
115
	 * The Timeline service.
116
	 *
117
	 * @since 3.1.0
118
	 * @access private
119
	 * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
120
	 */
121
	private $timeline_service;
122
123
	/**
124
	 * The Redirect service.
125
	 *
126
	 * @since 3.2.0
127
	 * @access private
128
	 * @var \Wordlift_Redirect_Service $redirect_service The Redirect service.
129
	 */
130
	private $redirect_service;
131
132
	/**
133
	 * The Notice service.
134
	 *
135
	 * @since 3.3.0
136
	 * @access private
137
	 * @var \Wordlift_Notice_Service $notice_service The Notice service.
138
	 */
139
	private $notice_service;
140
141
	/**
142
	 * The Entity list customization.
143
	 *
144
	 * @since 3.3.0
145
	 * @access private
146
	 * @var \Wordlift_List_Service $entity_list_service The Entity list service.
147
	 */
148
	private $entity_list_service;
149
150
	/**
151
	 * The Entity Types Taxonomy Walker.
152
	 *
153
	 * @since 3.1.0
154
	 * @access private
155
	 * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
156
	 */
157
	private $entity_types_taxonomy_walker;
158
159
	/**
160
	 * The ShareThis service.
161
	 *
162
	 * @since 3.2.0
163
	 * @access private
164
	 * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
165
	 */
166
	private $sharethis_service;
167
168
	/**
169
	 * The PrimaShop adapter.
170
	 *
171
	 * @since 3.2.3
172
	 * @access private
173
	 * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter.
174
	 */
175
	private $primashop_adapter;
176
177
	/**
178
	 * The WordLift Dashboard adapter.
179
	 *
180
	 * @since 3.4.0
181
	 * @access private
182
	 * @var \Wordlift_Dashboard_Service $dashboard_service The WordLift Dashboard service;
183
	 */
184
	private $dashboard_service;
185
186
	/**
187
	 * The entity type service.
188
	 *
189
	 * @since 3.6.0
190
	 * @access private
191
	 * @var \Wordlift_Entity_Type_Service
192
	 */
193
	private $entity_type_service;
194
195
	/**
196
	 * The entity link service used to mangle links to entities with a custom slug or even w/o a slug.
197
	 *
198
	 * @since 3.6.0
199
	 * @access private
200
	 * @var \Wordlift_Entity_Link_Service
201
	 */
202
	private $entity_link_service;
203
204
	/**
205
	 * The page service instance which processes the page output in order to insert schema.org microdata to export the
206
	 * correct page title to Google+.
207
	 *
208
	 * @since 3.5.3
209
	 * @access private
210
	 * @var \Wordlift_Page_Service
211
	 */
212
	private $page_service;
213
214
	/**
215
	 * A {@link Wordlift_Sparql_Service} instance.
216
	 *
217
	 * @var 3.6.0
218
	 * @access private
219
	 * @var \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance.
220
	 */
221
	private $sparql_service;
222
223
	/**
224
	 * A {@link Wordlift_Import_Service} instance.
225
	 *
226
	 * @since 3.6.0
227
	 * @access private
228
	 * @var \Wordlift_Import_Service $import_service A {@link Wordlift_Import_Service} instance.
229
	 */
230
	private $import_service;
231
232
	/**
233
	 * A {@link Wordlift_Rebuild_Service} instance.
234
	 *
235
	 * @since 3.6.0
236
	 * @access private
237
	 * @var \Wordlift_Rebuild_Service $rebuild_service A {@link Wordlift_Rebuild_Service} instance.
238
	 */
239
	private $rebuild_service;
240
241
	/**
242
	 * The 'Download Your Data' page.
243
	 *
244
	 * @since 3.6.0
245
	 * @access private
246
	 * @var \Wordlift_Admin_Download_Your_Data_Page $download_your_data_page The 'Download Your Data' page.
247
	 */
248
	private $download_your_data_page;
249
250
	/**
251
	 * Define the core functionality of the plugin.
252
	 *
253
	 * Set the plugin name and the plugin version that can be used throughout the plugin.
254
	 * Load the dependencies, define the locale, and set the hooks for the admin area and
255
	 * the public-facing side of the site.
256
	 *
257
	 * @since    1.0.0
258
	 */
259
	public function __construct() {
260
261
		$this->plugin_name = 'wordlift';
262
		$this->version     = '3.6.0';
263
		$this->load_dependencies();
264
		$this->set_locale();
265
		$this->define_admin_hooks();
266
		$this->define_public_hooks();
267
268
	}
269
270
	/**
271
	 * Load the required dependencies for this plugin.
272
	 *
273
	 * Include the following files that make up the plugin:
274
	 *
275
	 * - Wordlift_Loader. Orchestrates the hooks of the plugin.
276
	 * - Wordlift_i18n. Defines internationalization functionality.
277
	 * - Wordlift_Admin. Defines all hooks for the admin area.
278
	 * - Wordlift_Public. Defines all hooks for the public side of the site.
279
	 *
280
	 * Create an instance of the loader which will be used to register the hooks
281
	 * with WordPress.
282
	 *
283
	 * @since    1.0.0
284
	 * @access   private
285
	 */
286
	private function load_dependencies() {
0 ignored issues
show
Coding Style introduced by
load_dependencies uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
287
288
		/**
289
		 * The class responsible for orchestrating the actions and filters of the
290
		 * core plugin.
291
		 */
292
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
293
294
		/**
295
		 * The class responsible for defining internationalization functionality
296
		 * of the plugin.
297
		 */
298
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
299
300
		/**
301
		 * Provide support functions to sanitize data.
302
		 */
303
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-sanitizer.php';
304
305
		/**
306
		 * The Redirect service.
307
		 */
308
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php';
309
310
		/**
311
		 * The Log service.
312
		 */
313
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
314
315
		/**
316
		 * The configuration service.
317
		 */
318
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-configuration-service.php';
319
320
		/**
321
		 * The entity post type service.
322
		 */
323
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-type-service.php';
324
325
		/**
326
		 * The entity link service.
327
		 */
328
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-link-service.php';
329
330
		/**
331
		 * The Query builder.
332
		 */
333
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
334
335
		/**
336
		 * The Schema service.
337
		 */
338
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
339
340
		/**
341
		 * The schema:url property service.
342
		 */
343
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-property-service.php';
344
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-url-property-service.php';
345
346
		/**
347
		 * The UI service.
348
		 */
349
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
350
351
		/**
352
		 * The Thumbnail service.
353
		 */
354
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
355
356
		/**
357
		 * The Entity Types Taxonomy service.
358
		 */
359
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
360
361
		/**
362
		 * The Entity service.
363
		 */
364
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
365
366
		/**
367
		 * The User service.
368
		 */
369
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
370
371
		/**
372
		 * The Timeline service.
373
		 */
374
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
375
376
		/**
377
		 * The Topic Taxonomy service.
378
		 */
379
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-topic-taxonomy-service.php';
380
381
382
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-page-service.php';
383
384
		/**
385
		 * The SPARQL service.
386
		 */
387
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-sparql-service.php';
388
389
		/**
390
		 * The WordLift import service.
391
		 */
392
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-import-service.php';
393
394
		/**
395
		 * The WordLift URI service.
396
		 */
397
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-uri-service.php';
398
399
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-listable.php';
400
401
		/**
402
		 * The WordLift rebuild service, used to rebuild the remote dataset using the local data.
403
		 */
404
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-rebuild-service.php';
405
406
		/**
407
		 * The class responsible for defining all actions that occur in the admin area.
408
		 */
409
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
410
411
		/**
412
		 * The class to customize the entity list admin page.
413
		 */
414
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-entity-list.php';
415
416
		/**
417
		 * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
418
		 */
419
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
420
421
		/**
422
		 * The Notice service.
423
		 */
424
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
425
426
		/**
427
		 * The PrimaShop adapter.
428
		 */
429
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-primashop-adapter.php';
430
431
		/**
432
		 * The WordLift Dashboard service.
433
		 */
434
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard.php';
435
436
		/**
437
		 * The admin 'Download Your Data' page.
438
		 */
439
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-download-your-data-page.php';
440
441
		/**
442
		 * The class responsible for defining all actions that occur in the public-facing
443
		 * side of the site.
444
		 */
445
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
446
447
		/**
448
		 * The shortcode abstract class.
449
		 */
450
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-shortcode.php';
451
452
		/**
453
		 * The Timeline shortcode.
454
		 */
455
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
456
457
		/**
458
		 * The Navigator shortcode.
459
		 */
460
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-navigator-shortcode.php';
461
462
		/**
463
		 * The chord shortcode.
464
		 */
465
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-chord-shortcode.php';
466
467
		/**
468
		 * The geomap shortcode.
469
		 */
470
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-geomap-shortcode.php';
471
472
		/**
473
		 * The ShareThis service.
474
		 */
475
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
476
477
		$this->loader = new Wordlift_Loader();
478
479
		// Instantiate a global logger.
480
		global $wl_logger;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
481
		$wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
482
483
		// Create the configuration service.
484
		$configuration_service = new Wordlift_Configuration_Service();
485
486
		// Create an entity type service instance. It'll be later bound to the init action.
487
		$this->entity_type_service = new Wordlift_Entity_Type_Service( Wordlift_Entity_Service::TYPE_NAME, $configuration_service->get_entity_base_path() );
488
489
		// Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions.
490
		$this->entity_link_service = new Wordlift_Entity_Link_Service( $this->entity_type_service, $configuration_service->get_entity_base_path() );
491
492
		// Create an instance of the UI service.
493
		$this->ui_service = new Wordlift_UI_Service();
494
495
		// Create an instance of the Thumbnail service. Later it'll be hooked to post meta events.
496
		$this->thumbnail_service = new Wordlift_Thumbnail_Service();
497
498
		$this->sparql_service = new Wordlift_Sparql_Service();
499
500
		// Create an instance of the Schema service.
501
		new Wordlift_Schema_Url_Property_Service( $this->sparql_service );
502
		$this->schema_service = new Wordlift_Schema_Service();
503
504
		// Create an instance of the Notice service.
505
		$this->notice_service = new Wordlift_Notice_Service();
506
507
		// Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
508
		$this->entity_service = new Wordlift_Entity_Service( $this->ui_service, $this->schema_service, $this->notice_service );
509
510
		// Create an instance of the User service.
511
		$this->user_service = new Wordlift_User_Service();
512
513
		// Create a new instance of the Timeline service and Timeline shortcode.
514
		$this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
515
516
		// Create a new instance of the Redirect service.
517
		$this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service );
518
519
		// Create a new instance of the Redirect service.
520
		$this->dashboard_service = new Wordlift_Dashboard_Service( $this->entity_service );
521
522
		// Initialize the shortcodes.
523
		new Wordlift_Navigator_Shortcode();
524
		new Wordlift_Chord_Shortcode();
525
		new Wordlift_Geomap_Shortcode();
526
		new Wordlift_Timeline_Shortcode();
527
528
		// Create entity list customization (wp-admin/edit.php)
529
		$this->entity_list_service = new Wordlift_Entity_List_Service( $this->entity_service );
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Wordlift_Entity_Lis...($this->entity_service) of type object<Wordlift_Entity_List_Service> is incompatible with the declared type object<Wordlift_List_Service> of property $entity_list_service.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
530
531
		$this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
532
533
		$this->topic_taxonomy_service = new Wordlift_Topic_Taxonomy_Service();
534
535
		// Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
536
		$this->sharethis_service = new Wordlift_ShareThis_Service();
537
538
		// Create an instance of the PrimaShop adapter.
539
		$this->primashop_adapter = new Wordlift_PrimaShop_Adapter();
540
541
		$this->page_service = new Wordlift_Page_Service();
542
543
		// Create an import service instance to hook later to WP's import function.
544
		$this->import_service = new Wordlift_Import_Service( $this->entity_type_service, $this->entity_service, $this->schema_service, $this->sparql_service, wl_configuration_get_redlink_dataset_uri() );
545
546
		$uri_service = new Wordlift_Uri_Service( $GLOBALS['wpdb'] );
547
548
		// Create a Rebuild Service instance, which we'll later bound to an ajax call.
549
		$this->rebuild_service = new Wordlift_Rebuild_Service( $this->sparql_service, $uri_service );
550
551
		//** WordPress Admin */
552
		$this->download_your_data_page = new Wordlift_Admin_Download_Your_Data_Page();
553
554
	}
555
556
	/**
557
	 * Define the locale for this plugin for internationalization.
558
	 *
559
	 * Uses the Wordlift_i18n class in order to set the domain and to register the hook
560
	 * with WordPress.
561
	 *
562
	 * @since    1.0.0
563
	 * @access   private
564
	 */
565
	private function set_locale() {
566
567
		$plugin_i18n = new Wordlift_i18n();
568
		$plugin_i18n->set_domain( $this->get_plugin_name() );
569
570
		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
571
572
	}
573
574
	/**
575
	 * Register all of the hooks related to the admin area functionality
576
	 * of the plugin.
577
	 *
578
	 * @since    1.0.0
579
	 * @access   private
580
	 */
581
	private function define_admin_hooks() {
582
583
		$plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
584
585
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
586
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
587
588
		// Hook the init action to the Topic Taxonomy service.
589
		$this->loader->add_action( 'init', $this->topic_taxonomy_service, 'init', 0 );
590
591
		// Hook the deleted_post_meta action to the Thumbnail service.
592
		$this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
593
594
		// Hook the added_post_meta action to the Thumbnail service.
595
		$this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 );
596
597
		// Hook the updated_post_meta action to the Thumbnail service.
598
		$this->loader->add_action( 'updated_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 );
599
600
		// Hook posts inserts (or updates) to the user service.
601
		$this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
602
603
		// Hook the AJAX wl_timeline action to the Timeline service.
604
		$this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
605
606
		// Register custom allowed redirect hosts.
607
		$this->loader->add_filter( 'allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts' );
608
		// Hook the AJAX wordlift_redirect action to the Redirect service.
609
		$this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' );
610
		// Hook the AJAX wordlift_redirect action to the Redirect service.
611
		$this->loader->add_action( 'wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats' );
612
		// Hook the AJAX wordlift_redirect action to the Redirect service.
613
		$this->loader->add_action( 'wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets' );
614
615
		// Hook save_post to the entity service to update custom fields (such as alternate labels).
616
		// We have a priority of 9 because we want to be executed before data is sent to Redlink.
617
		$this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 );
618
		$this->loader->add_action( 'save_post_entity', $this->entity_service, 'set_rating_for', 10, 1 );
619
620
		$this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
621
		$this->loader->add_action( 'in_admin_header', $this->entity_service, 'in_admin_header' );
622
623
		// Entity listing customization (wp-admin/edit.php)
624
		// Add custom columns
625
		$this->loader->add_filter( 'manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns' );
626
		$this->loader->add_filter( 'manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2 );
627
		// Add 4W selection
628
		$this->loader->add_action( 'restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope' );
629
		$this->loader->add_filter( 'posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope' );
630
631
		$this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
632
633
		// Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for
634
		// entities.
635
		$this->loader->add_filter( 'prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2 );
636
637
		// Filter imported post meta.
638
		$this->loader->add_filter( 'wp_import_post_meta', $this->import_service, 'wp_import_post_meta', 10, 3 );
639
640
		// Notify the import service when an import starts and ends.
641
		$this->loader->add_action( 'import_start', $this->import_service, 'import_start', 10, 0 );
642
		$this->loader->add_action( 'import_end', $this->import_service, 'import_end', 10, 0 );
643
644
		// Hook the AJAX wl_rebuild action to the Rebuild Service.
645
		$this->loader->add_action( 'wp_ajax_wl_rebuild', $this->rebuild_service, 'rebuild' );
646
647
		// Hook the menu to the Download Your Data page.
648
		$this->loader->add_action( 'admin_menu', $this->download_your_data_page, 'admin_menu', 100, 0 );
649
650
		// Hook the admin-ajax.php?action=wl_download_your_data&out=xyz links.
651
		$this->loader->add_action( 'wp_ajax_wl_download_your_data', $this->download_your_data_page, 'download_your_data', 10 );
652
653
	}
654
655
	/**
656
	 * Register all of the hooks related to the public-facing functionality
657
	 * of the plugin.
658
	 *
659
	 * @since    1.0.0
660
	 * @access   private
661
	 */
662
	private function define_public_hooks() {
663
664
		$plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
665
666
		// Register the entity post type.
667
		$this->loader->add_action( 'init', $this->entity_type_service, 'register' );
668
669
		// Bind the link generation and handling hooks to the entity link service.
670
		$this->loader->add_filter( 'post_type_link', $this->entity_link_service, 'post_type_link', 10, 4 );
671
		$this->loader->add_action( 'pre_get_posts', $this->entity_link_service, 'pre_get_posts', 10, 1 );
672
		$this->loader->add_filter( 'wp_unique_post_slug_is_bad_flat_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_flat_slug', 10, 3 );
673
		$this->loader->add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_hierarchical_slug', 10, 4 );
674
675
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
676
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
677
678
		// Hook the AJAX wl_timeline action to the Timeline service.
679
		$this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
680
681
		// Hook the ShareThis service.
682
		$this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
683
		$this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
684
685
		$this->loader->add_action( 'wp_head', $this->page_service, 'wp_head', PHP_INT_MAX );
686
		$this->loader->add_action( 'wp_footer', $this->page_service, 'wp_head', - PHP_INT_MAX );
687
688
	}
689
690
	/**
691
	 * Run the loader to execute all of the hooks with WordPress.
692
	 *
693
	 * @since    1.0.0
694
	 */
695
	public function run() {
696
		$this->loader->run();
697
	}
698
699
	/**
700
	 * The name of the plugin used to uniquely identify it within the context of
701
	 * WordPress and to define internationalization functionality.
702
	 *
703
	 * @since     1.0.0
704
	 * @return    string    The name of the plugin.
705
	 */
706
	public function get_plugin_name() {
707
		return $this->plugin_name;
708
	}
709
710
	/**
711
	 * The reference to the class that orchestrates the hooks with the plugin.
712
	 *
713
	 * @since     1.0.0
714
	 * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
715
	 */
716
	public function get_loader() {
717
		return $this->loader;
718
	}
719
720
	/**
721
	 * Retrieve the version number of the plugin.
722
	 *
723
	 * @since     1.0.0
724
	 * @return    string    The version number of the plugin.
725
	 */
726
	public function get_version() {
727
		return $this->version;
728
	}
729
730
}
731