Completed
Push — develop ( d513ba...161245 )
by David
05:02 queued 32s
created

Wordlift::get_plugin_name()   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 Entity service.
80
	 *
81
	 * @since 3.1.0
82
	 * @access private
83
	 * @var \Wordlift_Entity_Service $entity_service The Entity service.
84
	 */
85
	private $entity_service;
86
87
	/**
88
	 * The User service.
89
	 *
90
	 * @since 3.1.7
91
	 * @access private
92
	 * @var \Wordlift_User_Service $user_service The User service.
93
	 */
94
	private $user_service;
95
96
	/**
97
	 * The Timeline service.
98
	 *
99
	 * @since 3.1.0
100
	 * @access private
101
	 * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
102
	 */
103
	private $timeline_service;
104
105
	/**
106
	 * The Entity Types Taxonomy Walker.
107
	 *
108
	 * @since 3.1.0
109
	 * @access private
110
	 * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
111
	 */
112
	private $entity_types_taxonomy_walker;
113
114
	/**
115
	 * The ShareThis service.
116
	 *
117
	 * @since 3.2.0
118
	 * @access private
119
	 * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
120
	 */
121
	private $sharethis_service;
122
123
	/**
124
	 * Define the core functionality of the plugin.
125
	 *
126
	 * Set the plugin name and the plugin version that can be used throughout the plugin.
127
	 * Load the dependencies, define the locale, and set the hooks for the admin area and
128
	 * the public-facing side of the site.
129
	 *
130
	 * @since    1.0.0
131
	 */
132
	public function __construct() {
133
134
		$this->plugin_name = 'wordlift';
135
136
		$this->version = '3.2.0-dev';
137
138
		$this->load_dependencies();
139
		$this->set_locale();
140
		$this->define_admin_hooks();
141
		$this->define_public_hooks();
142
143
	}
144
145
	/**
146
	 * Load the required dependencies for this plugin.
147
	 *
148
	 * Include the following files that make up the plugin:
149
	 *
150
	 * - Wordlift_Loader. Orchestrates the hooks of the plugin.
151
	 * - Wordlift_i18n. Defines internationalization functionality.
152
	 * - Wordlift_Admin. Defines all hooks for the admin area.
153
	 * - Wordlift_Public. Defines all hooks for the public side of the site.
154
	 *
155
	 * Create an instance of the loader which will be used to register the hooks
156
	 * with WordPress.
157
	 *
158
	 * @since    1.0.0
159
	 * @access   private
160
	 */
161
	private function load_dependencies() {
162
163
		/**
164
		 * The class responsible for orchestrating the actions and filters of the
165
		 * core plugin.
166
		 */
167
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
168
169
		/**
170
		 * The class responsible for defining internationalization functionality
171
		 * of the plugin.
172
		 */
173
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
174
175
		/**
176
		 * The Log service.
177
		 */
178
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
179
180
		/**
181
		 * The Query builder.
182
		 */
183
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
184
185
		/**
186
		 * The Schema service.
187
		 */
188
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
189
190
		/**
191
		 * The UI service.
192
		 */
193
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
194
195
		/**
196
		 * The Thumbnail service.
197
		 */
198
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
199
200
		/**
201
		 * The Entity Types Taxonomy service.
202
		 */
203
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
204
205
		/**
206
		 * The Entity service.
207
		 */
208
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
209
210
		/**
211
		 * The User service.
212
		 */
213
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
214
215
		/**
216
		 * The Timeline service.
217
		 */
218
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
219
220
		/**
221
		 * The class responsible for defining all actions that occur in the admin area.
222
		 */
223
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
224
225
		/**
226
		 * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
227
		 */
228
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
229
230
		/**
231
		 * The Notice service.
232
		 */
233
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
234
235
		/**
236
		 * The class responsible for defining all actions that occur in the public-facing
237
		 * side of the site.
238
		 */
239
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
240
241
		/**
242
		 * The Timeline shortcode.
243
		 */
244
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
245
246
		/**
247
		 * The ShareThis service.
248
		 */
249
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
250
251
		$this->loader = new Wordlift_Loader();
252
253
		// Instantiate a global logger.
254
		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...
255
		$wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
256
257
		// Create an instance of the UI service.
258
		$this->ui_service = new Wordlift_UI_Service();
259
260
		// Create an instance of the Thumbnail service. Later it'll be hooked to post meta events.
261
		$this->thumbnail_service = new Wordlift_Thumbnail_Service();
262
263
		// Create an instance of the Schema service.
264
		new Wordlift_Schema_Service();
265
266
		// Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
267
		$this->entity_service = new Wordlift_Entity_Service( $this->ui_service );
268
269
		// Create an instance of the User service.
270
		$this->user_service = new Wordlift_User_Service();
271
272
		// Create a new instance of the Timeline service and Timeline shortcode.
273
		$this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
274
275
		// Create an instance of the Timeline shortcode.
276
		new Wordlift_Timeline_Shortcode();
277
278
		$this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
279
280
		// Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
281
		$this->sharethis_service = new Wordlift_ShareThis_Service();
282
283
		// Create an instance of the Notice service.
284
		new Wordlift_Notice_Service();
285
	}
286
287
	/**
288
	 * Define the locale for this plugin for internationalization.
289
	 *
290
	 * Uses the Wordlift_i18n class in order to set the domain and to register the hook
291
	 * with WordPress.
292
	 *
293
	 * @since    1.0.0
294
	 * @access   private
295
	 */
296
	private function set_locale() {
297
298
		$plugin_i18n = new Wordlift_i18n();
299
		$plugin_i18n->set_domain( $this->get_plugin_name() );
300
301
		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
302
303
	}
304
305
	/**
306
	 * Register all of the hooks related to the admin area functionality
307
	 * of the plugin.
308
	 *
309
	 * @since    1.0.0
310
	 * @access   private
311
	 */
312
	private function define_admin_hooks() {
313
314
		$plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
315
316
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
317
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
318
319
		// Hook the deleted_post_meta action to the Thumbnail service.
320
		$this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
321
322
		// Hook the added_post_meta action to the Thumbnail service.
323
		$this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 );
324
325
		// Hook posts inserts (or updates) to the user service.
326
		$this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
327
328
		// Hook the AJAX wl_timeline action to the Timeline service.
329
		$this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
330
331
		// Hook save_post to the entity service to update custom fields (such as alternate labels).
332
		// We have a priority of 9 because we want to be executed before data is sent to Redlink.
333
		$this->loader->add_filter( 'save_post', $this->entity_service, 'save_post', 9, 3 );
334
		$this->loader->add_filter( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
335
336
		$this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
337
338
	}
339
340
	/**
341
	 * Register all of the hooks related to the public-facing functionality
342
	 * of the plugin.
343
	 *
344
	 * @since    1.0.0
345
	 * @access   private
346
	 */
347
	private function define_public_hooks() {
348
349
		$plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
350
351
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
352
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
353
354
		// Hook the AJAX wl_timeline action to the Timeline service.
355
		$this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
356
357
		// Hook the ShareThis service.
358
		$this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
359
		$this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
360
	}
361
362
	/**
363
	 * Run the loader to execute all of the hooks with WordPress.
364
	 *
365
	 * @since    1.0.0
366
	 */
367
	public function run() {
368
		$this->loader->run();
369
	}
370
371
	/**
372
	 * The name of the plugin used to uniquely identify it within the context of
373
	 * WordPress and to define internationalization functionality.
374
	 *
375
	 * @since     1.0.0
376
	 * @return    string    The name of the plugin.
377
	 */
378
	public function get_plugin_name() {
379
		return $this->plugin_name;
380
	}
381
382
	/**
383
	 * The reference to the class that orchestrates the hooks with the plugin.
384
	 *
385
	 * @since     1.0.0
386
	 * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
387
	 */
388
	public function get_loader() {
389
		return $this->loader;
390
	}
391
392
	/**
393
	 * Retrieve the version number of the plugin.
394
	 *
395
	 * @since     1.0.0
396
	 * @return    string    The version number of the plugin.
397
	 */
398
	public function get_version() {
399
		return $this->version;
400
	}
401
402
}
403