Passed
Push — master ( 1551ad...2434f2 )
by Nirjhar
02:16
created

PLUGIN_BUILD::shortcode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 3
rs 10
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) exit;
3
4
/**
5
 * Main plugin object to define the plugin
6
 */
7
if ( ! class_exists( 'PLUGIN_BUILD' ) ) {
8
9
	final class PLUGIN_BUILD {
10
11
		/**
12
		 * @var String
13
		 */
14
		protected $version = '1.2.1';
15
16
17
		/**
18
		 * Plugin Instance.
19
		 *
20
		 * @var PLUGIN_BUILD the PLUGIN Instance
21
		 */
22
		protected static $_instance;
23
24
25
		/**
26
		 * Text domain to be used throughout the plugin
27
		 *
28
		 * @var String
29
		 */
30
		protected static $text_domain = 'textdomain';
31
32
33
		/**
34
		 * Minimum PHP version allowed for the plugin
35
		 *
36
		 * @var String
37
		 */
38
		protected static $php_ver_allowed = '5.3';
39
40
41
		/**
42
		 * DB tabble used in plugin
43
		 *
44
		 * @var String
45
		 */
46
		protected static $plugin_table = 'plugin_db_table_name';
47
48
49
		/**
50
		 * Plugin listing page links, along with Deactivate
51
		 *
52
		 * @var Array
53
		 */
54
		protected static $plugin_page_links = array(
55
			array(
56
				'slug' => '',
57
				'label' => ''
58
			) );
59
60
61
		/**
62
		 * Main Plugin Instance.
63
		 *
64
		 * @return PLUGIN_BUILD
65
		 */
66
		public static function instance() {
67
68
			if ( is_null( self::$_instance ) ) {
69
				self::$_instance = new self();
70
				self::$_instance->init();
71
			}
72
73
			return self::$_instance;
74
		}
75
76
77
		/**
78
		 * Install plugin setup
79
		 *
80
		 * @return Void
81
		 */
82
		public function installation() {
83
84
			if (class_exists('PLUGIN_INSTALL')) {
85
86
				$install = new PLUGIN_INSTALL();
87
				$install->text_domain = self::$text_domain;
88
				$install->php_ver_allowed = self::$php_ver_allowed;
89
				$install->plugin_page_links = self::$plugin_page_links;
90
				$install->execute();
91
			}
92
		}
93
94
95
		/**
96
		 * Custom corn class, register it while activation
97
		 *
98
		 * @return Void
99
		 */
100
		public function cron_activation() {
101
102
			if ( class_exists( 'PLUGIN_CRON' ) ) {
103
104
				$cron = new PLUGIN_CRON();
105
				$schedule = $cron->schedule_task(
0 ignored issues
show
Unused Code introduced by
The assignment to $schedule is dead and can be removed.
Loading history...
106
							array(
107
							'timestamp' => current_time('timestamp'),
0 ignored issues
show
Bug introduced by
The function current_time was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
							'timestamp' => /** @scrutinizer ignore-call */ current_time('timestamp'),
Loading history...
108
							//'schedule' can be 'hourly', 'daily', 'weekly' or anything custom as defined in PLUGIN_CRON
109
							'recurrence' => 'schedule',
110
							// Use custom_corn_hook to hook into any cron process, anywhere in the plugin.
111
							'hook' => 'custom_cron_hook'
112
						) );
113
			}
114
115
		}
116
117
118
		/**
119
		 * Install plugin data
120
		 *
121
		 * @return Void
122
		 */
123
		public function db_install() {
124
125
			if ( class_exists( 'PLUGIN_DB' ) ) {
126
127
				$db = new PLUGIN_DB();
128
				$db->table = self::$plugin_table;
129
				$db->sql = "ID mediumint(9) NOT NULL AUTO_INCREMENT,
130
							date date NOT NULL,
131
							UNIQUE KEY ID (ID)";
132
				$db->build();
133
			}
134
135
			if (get_option( '_plugin_db_exist') == '0' ) {
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

135
			if (/** @scrutinizer ignore-call */ get_option( '_plugin_db_exist') == '0' ) {
Loading history...
136
				add_action( 'admin_notices', array( $this, 'db_error_msg' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

136
				/** @scrutinizer ignore-call */ 
137
    add_action( 'admin_notices', array( $this, 'db_error_msg' ) );
Loading history...
137
			}
138
139
			$options = array(
140
				array( 'option_name', '__value__' ),
141
			);
142
			foreach ( $options as $value ) {
143
				update_option( $value[0], $value[1] );
0 ignored issues
show
Bug introduced by
The function update_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

143
				/** @scrutinizer ignore-call */ 
144
    update_option( $value[0], $value[1] );
Loading history...
144
			}
145
		}
146
147
148
		/**
149
		 * Notice of DB
150
		 *
151
		 * @return string
152
		 */
153
		public function db_error_msg() { ?>
154
155
			<div class="notice notice-error is-dismissible">
156
				<p><?php _e( 'Database table Not installed correctly.', 'textdomain' ); ?></p>
0 ignored issues
show
Bug introduced by
The function _e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

156
				<p><?php /** @scrutinizer ignore-call */ _e( 'Database table Not installed correctly.', 'textdomain' ); ?></p>
Loading history...
157
 			</div>
158
			<?php
159
		}
160
161
162
		/**
163
		 * Uninstall plugin data
164
		 *
165
		 * @return Void
166
		 */
167
		public function db_uninstall() {
168
169
			$table_name = self::$plugin_table;
170
171
			global $wpdb;
172
			$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$table_name" );
173
174
			$options = array(
175
				'_plugin_db_exist'
176
			);
177
			foreach ( $options as $value ) {
178
				delete_option( $value );
0 ignored issues
show
Bug introduced by
The function delete_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

178
				/** @scrutinizer ignore-call */ 
179
    delete_option( $value );
Loading history...
179
			}
180
		}
181
182
183
		/**
184
		 * CRON callback
185
		 *
186
		 * @return Void
187
		 */
188
		public function do_cron_job_function() {
189
190
			//Do cron function
191
		}
192
193
194
		/**
195
		 * Run CRON action
196
		 *
197
		 * @return Void
198
		 */
199
		public function custom_cron_hook_cb() {
200
201
			add_action( 'custom_cron_hook', array( $this, 'do_cron_job_function' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

201
			/** @scrutinizer ignore-call */ 
202
   add_action( 'custom_cron_hook', array( $this, 'do_cron_job_function' ) );
Loading history...
202
		}
203
204
205
		/**
206
		 * Uninstall CRON hook
207
		 *
208
		 * @return Void
209
		 */
210
		public function cron_uninstall() {
211
212
			wp_clear_scheduled_hook( 'custom_cron_hook' );
0 ignored issues
show
Bug introduced by
The function wp_clear_scheduled_hook was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

212
			/** @scrutinizer ignore-call */ 
213
   wp_clear_scheduled_hook( 'custom_cron_hook' );
Loading history...
213
		}
214
215
216
		/**
217
		 * Include scripts
218
		 *
219
		 * @return Void
220
		 */
221
		public function scripts() {
222
223
			if ( class_exists( 'PLUGIN_SCRIPT' ) ) new PLUGIN_SCRIPT();
224
		}
225
226
227
		/**
228
		 * Include settings pages
229
		 *
230
		 * @return Void
231
		 */
232
		public function settings() {
233
234
			if ( class_exists( 'PLUGIN_SETTINGS' ) ) new PLUGIN_SETTINGS();
235
		}
236
237
238
		/**
239
		 * Include widget classes
240
		 *
241
		 * @return Void
242
		 */
243
		public function widgets() {
244
245
			if ( class_exists( 'PLUGIN_WIDGET' ) ) new PLUGIN_WIDGET();
246
		}
247
248
249
		/**
250
		 *Include metabox classes
251
		 *
252
		 * @return Void
253
		 */
254
		public function metabox() {
255
256
			if ( class_exists( 'PLUGIN_METABOX' ) ) new PLUGIN_METABOX();
257
		}
258
259
260
		/**
261
		 * Include shortcode classes
262
		 *
263
		 * @return Void
264
		 */
265
		public function shortcode() {
266
267
			if ( class_exists( 'PLUGIN_SHORTCODE' ) ) new PLUGIN_SHORTCODE();
268
		}
269
270
271
		/**
272
		 * Add the functionality files
273
		 * Available classes: PLUGIN_INSTALL, PLUGIN_DB, PLUGIN_METABOX, PLUGIN_QUERY, PLUGIN_SETTINGS, PLUGIN_SHORTCODE, PLUGIN_WIDGET
274
		 *
275
		 * @return Void
276
		 */
277
		public function functionality() {
278
279
			require_once( 'src/install.php' );
280
			require_once( 'src/db.php' );
281
			require_once( 'src/query.php' );
282
			require_once( 'src/settings.php' );
283
			require_once( 'src/widget.php' );
284
			require_once( 'src/metabox.php' );
285
			require_once( 'src/shortcode.php' );
286
		}
287
288
289
		/**
290
		 * Call the dependency files
291
		 * Available classes: PLUGIN_CORN, PLUGIN_API, PLUGIN_TABLE, PLUGIN_AJAX, PLUGIN_UPLOAD, PLUGIN_SCRIPT
292
		 *
293
		 * @return Void
294
		 */
295
		public function helpers() {
296
297
			require_once( 'lib/cron.php' );
298
			require_once( 'lib/api.php' );
299
			require_once( 'lib/table.php' );
300
			require_once( 'lib/ajax.php' );
301
			require_once( 'lib/upload.php' );
302
			require_once( 'lib/script.php' );
303
		}
304
305
306
		/**
307
		 * Instantiate the plugin
308
		 *
309
		 * @return Void
310
		 */
311
		public function init() {
312
313
			$this->helpers();
314
			$this->functionality();
315
316
			register_activation_hook( PLUGIN_FILE, array( $this, 'db_install' ) );
0 ignored issues
show
Bug introduced by
The function register_activation_hook was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

316
			/** @scrutinizer ignore-call */ 
317
   register_activation_hook( PLUGIN_FILE, array( $this, 'db_install' ) );
Loading history...
317
			register_activation_hook( PLUGIN_FILE, array($this, 'cron_activation' ) );
318
319
			//remove the DB and CORN upon uninstallation
320
			//$this won't work here.
321
			register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'db_uninstall' ) );
0 ignored issues
show
Bug introduced by
The function register_uninstall_hook was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

321
			/** @scrutinizer ignore-call */ 
322
   register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'db_uninstall' ) );
Loading history...
322
			register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'cron_uninstall' ) );
323
324
			add_action( 'init', array( $this, 'installation' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

324
			/** @scrutinizer ignore-call */ 
325
   add_action( 'init', array( $this, 'installation' ) );
Loading history...
325
			add_action( 'init', array( $this, 'custom_cron_hook_cb' ) );
326
327
			$this->scripts();
328
			$this->widgets();
329
			$this->metabox();
330
			$this->shortcode();
331
			$this->settings();
332
		}
333
	}
334
} ?>
335