Completed
Push — develop ( c91d29...a4aae9 )
by
unknown
03:24
created

Wordlift::get_version()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 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 User service.
98
	 *
99
	 * @since 3.1.7
100
	 * @access private
101
	 * @var \Wordlift_User_Service $user_service The User service.
102
	 */
103
	private $user_service;
104
105
	/**
106
	 * The Timeline service.
107
	 *
108
	 * @since 3.1.0
109
	 * @access private
110
	 * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
111
	 */
112
	private $timeline_service;
113
114
	/**
115
	 * The Redirect service.
116
	 *
117
	 * @since 3.2.0
118
	 * @access private
119
	 * @var \Wordlift_Redirect_Service $redirect_service The Redirect service.
120
	 */
121
	private $redirect_service;
122
123
	/**
124
	 * The Notice service.
125
	 *
126
	 * @since 3.3.0
127
	 * @access private
128
	 * @var \Wordlift_Notice_Service $notice_service The Notice service.
129
	 */
130
	private $notice_service;
131
	
132
	/**
133
	 * The Entity list customization.
134
	 *
135
	 * @since 3.3.0
136
	 * @access private
137
	 * @var \Wordlift_List_Service $entity_list_service The Entity list service.
138
	 */
139
	private $entity_list_service;
140
141
	/**
142
	 * The Entity Types Taxonomy Walker.
143
	 *
144
	 * @since 3.1.0
145
	 * @access private
146
	 * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
147
	 */
148
	private $entity_types_taxonomy_walker;
149
150
	/**
151
	 * The ShareThis service.
152
	 *
153
	 * @since 3.2.0
154
	 * @access private
155
	 * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
156
	 */
157
	private $sharethis_service;
158
159
	/**
160
	 * The PrimaShop adapter.
161
	 *
162
	 * @since 3.2.3
163
	 * @access private
164
	 * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter.
165
	 */
166
	private $primashop_adapter;
167
168
	/**
169
	 * The WordLift Dashboard adapter.
170
	 *
171
	 * @since 3.4.0
172
	 * @access private
173
	 * @var \Wordlift_Dashboard_Service $dashboard_service The WordLift Dashboard service;
174
	 */
175
	private $dashboard_service;
176
177
	/**
178
	 * Define the core functionality of the plugin.
179
	 *
180
	 * Set the plugin name and the plugin version that can be used throughout the plugin.
181
	 * Load the dependencies, define the locale, and set the hooks for the admin area and
182
	 * the public-facing side of the site.
183
	 *
184
	 * @since    1.0.0
185
	 */
186
	public function __construct() {
187
188
		$this->plugin_name = 'wordlift';
189
		$this->version = '3.4.0-dev';
190
		$this->load_dependencies();
191
		$this->set_locale();
192
		$this->define_admin_hooks();
193
		$this->define_public_hooks();
194
195
	}
196
197
	/**
198
	 * Load the required dependencies for this plugin.
199
	 *
200
	 * Include the following files that make up the plugin:
201
	 *
202
	 * - Wordlift_Loader. Orchestrates the hooks of the plugin.
203
	 * - Wordlift_i18n. Defines internationalization functionality.
204
	 * - Wordlift_Admin. Defines all hooks for the admin area.
205
	 * - Wordlift_Public. Defines all hooks for the public side of the site.
206
	 *
207
	 * Create an instance of the loader which will be used to register the hooks
208
	 * with WordPress.
209
	 *
210
	 * @since    1.0.0
211
	 * @access   private
212
	 */
213
	private function load_dependencies() {
214
215
		/**
216
		 * The class responsible for orchestrating the actions and filters of the
217
		 * core plugin.
218
		 */
219
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
220
221
		/**
222
		 * The class responsible for defining internationalization functionality
223
		 * of the plugin.
224
		 */
225
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
226
227
		/**
228
		 * The Redirect service.
229
		 */
230
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php';
231
232
		/**
233
		 * The Log service.
234
		 */
235
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
236
237
		/**
238
		 * The Query builder.
239
		 */
240
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
241
242
		/**
243
		 * The Schema service.
244
		 */
245
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
246
247
		/**
248
		 * The UI service.
249
		 */
250
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
251
252
		/**
253
		 * The Thumbnail service.
254
		 */
255
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
256
257
		/**
258
		 * The Entity Types Taxonomy service.
259
		 */
260
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
261
262
		/**
263
		 * The Entity service.
264
		 */
265
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
266
267
		/**
268
		 * The User service.
269
		 */
270
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
271
272
		/**
273
		 * The Timeline service.
274
		 */
275
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
276
277
		/**
278
		 * The class responsible for defining all actions that occur in the admin area.
279
		 */
280
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
281
		
282
		/**
283
		 * The class to customize the entity list admin page.
284
		 */
285
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-entity-list.php';
286
287
		/**
288
		 * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
289
		 */
290
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
291
292
		/**
293
		 * The Notice service.
294
		 */
295
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
296
297
		/**
298
		 * The PrimaShop adapter.
299
		 */
300
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-primashop-adapter.php';
301
302
		/**
303
		 * The WordLift Dashboard service.
304
		 */
305
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard.php';
306
307
		/**
308
		 * The class responsible for defining all actions that occur in the public-facing
309
		 * side of the site.
310
		 */
311
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
312
313
		/**
314
		 * The Timeline shortcode.
315
		 */
316
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
317
318
		/**
319
		 * The ShareThis service.
320
		 */
321
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
322
323
		$this->loader = new Wordlift_Loader();
324
325
		// Instantiate a global logger.
326
		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...
327
		$wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
328
329
		// Create an instance of the UI service.
330
		$this->ui_service = new Wordlift_UI_Service();
331
332
		// Create an instance of the Thumbnail service. Later it'll be hooked to post meta events.
333
		$this->thumbnail_service = new Wordlift_Thumbnail_Service();
334
335
		// Create an instance of the Schema service.
336
		$this->schema_service = new Wordlift_Schema_Service();
337
338
		// Create an instance of the Notice service.
339
		$this->notice_service = new Wordlift_Notice_Service();
340
341
		// Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
342
		$this->entity_service = new Wordlift_Entity_Service( $this->ui_service, $this->schema_service, $this->notice_service );
343
344
		// Create an instance of the User service.
345
		$this->user_service = new Wordlift_User_Service();
346
347
		// Create a new instance of the Timeline service and Timeline shortcode.
348
		$this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
349
350
		// Create a new instance of the Redirect service.
351
		$this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service );
352
353
		// Create a new instance of the Redirect service.
354
		$this->dashboard_service = new Wordlift_Dashboard_Service( $this->entity_service );
355
356
		// Create an instance of the Timeline shortcode.
357
		new Wordlift_Timeline_Shortcode();
358
		
359
		// Create entity list customization (wp-admin/edit.php)
360
		$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...
361
362
		$this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
363
364
		// Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
365
		$this->sharethis_service = new Wordlift_ShareThis_Service();
366
367
		// Create an instance of the PrimaShop adapter.
368
		$this->primashop_adapter = new Wordlift_PrimaShop_Adapter();
369
	}
370
371
	/**
372
	 * Define the locale for this plugin for internationalization.
373
	 *
374
	 * Uses the Wordlift_i18n class in order to set the domain and to register the hook
375
	 * with WordPress.
376
	 *
377
	 * @since    1.0.0
378
	 * @access   private
379
	 */
380
	private function set_locale() {
381
382
		$plugin_i18n = new Wordlift_i18n();
383
		$plugin_i18n->set_domain( $this->get_plugin_name() );
384
385
		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
386
387
	}
388
389
	/**
390
	 * Register all of the hooks related to the admin area functionality
391
	 * of the plugin.
392
	 *
393
	 * @since    1.0.0
394
	 * @access   private
395
	 */
396
	private function define_admin_hooks() {
397
398
		$plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
399
400
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
401
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
402
403
		// Hook the deleted_post_meta action to the Thumbnail service.
404
		$this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
405
406
		// Hook the added_post_meta action to the Thumbnail service.
407
		$this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 );
408
409
		// Hook posts inserts (or updates) to the user service.
410
		$this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
411
412
		// Hook the AJAX wl_timeline action to the Timeline service.
413
		$this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
414
415
		// Register custom allowed redirect hosts.
416
		$this->loader->add_filter( 'allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts' );
417
		// Hook the AJAX wordlift_redirect action to the Redirect service.
418
		$this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' );
419
		// Hook the AJAX wordlift_redirect action to the Redirect service.
420
		$this->loader->add_action( 'wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats' );
421
		// Hook the AJAX wordlift_redirect action to the Redirect service.
422
		$this->loader->add_action( 'wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets' );
423
424
		// Hook save_post to the entity service to update custom fields (such as alternate labels).
425
		// We have a priority of 9 because we want to be executed before data is sent to Redlink.
426
		$this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 );
427
		$this->loader->add_action( 'save_post_entity', $this->entity_service, 'set_rating_for', 10, 1 );
428
		
429
		$this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
430
		$this->loader->add_action( 'in_admin_header', $this->entity_service, 'in_admin_header' );
431
432
		// Entity listing customization (wp-admin/edit.php)
433
		// Add custom columns
434
		$this->loader->add_filter( 'manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns' );
435
		$this->loader->add_filter( 'manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2 );
436
		// Add 4W selection
437
		$this->loader->add_action( 'restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope' );
438
		$this->loader->add_filter( 'posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope' );
439
		
440
		$this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
441
442
		// Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for
443
		// entities.
444
		$this->loader->add_filter( 'prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2 );
445
	}
446
447
	/**
448
	 * Register all of the hooks related to the public-facing functionality
449
	 * of the plugin.
450
	 *
451
	 * @since    1.0.0
452
	 * @access   private
453
	 */
454
	private function define_public_hooks() {
455
456
		$plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
457
458
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
459
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
460
461
		// Hook the AJAX wl_timeline action to the Timeline service.
462
		$this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
463
464
		// Hook the ShareThis service.
465
		$this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
466
		$this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
467
	}
468
469
	/**
470
	 * Run the loader to execute all of the hooks with WordPress.
471
	 *
472
	 * @since    1.0.0
473
	 */
474
	public function run() {
475
		$this->loader->run();
476
	}
477
478
	/**
479
	 * The name of the plugin used to uniquely identify it within the context of
480
	 * WordPress and to define internationalization functionality.
481
	 *
482
	 * @since     1.0.0
483
	 * @return    string    The name of the plugin.
484
	 */
485
	public function get_plugin_name() {
486
		return $this->plugin_name;
487
	}
488
489
	/**
490
	 * The reference to the class that orchestrates the hooks with the plugin.
491
	 *
492
	 * @since     1.0.0
493
	 * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
494
	 */
495
	public function get_loader() {
496
		return $this->loader;
497
	}
498
499
	/**
500
	 * Retrieve the version number of the plugin.
501
	 *
502
	 * @since     1.0.0
503
	 * @return    string    The version number of the plugin.
504
	 */
505
	public function get_version() {
506
		return $this->version;
507
	}
508
509
}
510