Completed
Push — develop ( d984a8...acdc8f )
by Marco
02:12
created

black-studio-tinymce-widget.php ➔ bstw_multiple_notice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/*
3
Plugin Name: Black Studio TinyMCE Widget
4
Plugin URI: https://wordpress.org/plugins/black-studio-tinymce-widget/
5
Description: Adds a new "Visual Editor" widget type based on the native WordPress TinyMCE editor.
6
Version: 2.2.9
7
Author: Black Studio
8
Author URI: http://www.blackstudio.it
9
Requires at least: 3.1
10
Tested up to: 4.5
11
License: GPLv3
12
Text Domain: black-studio-tinymce-widget
13
Domain Path: /languages
14
*/
15
16
// Exit if accessed directly
17
if ( ! defined( 'ABSPATH' ) ) {
18
	exit;
19
}
20
21
/**
22
 * Main plugin class
23
 *
24
 * @package Black_Studio_TinyMCE_Widget
25
 * @since 2.0.0
26
 */
27
28
if ( ! class_exists( 'Black_Studio_TinyMCE_Plugin' ) ) {
29
30
	final class Black_Studio_TinyMCE_Plugin {
31
32
		/**
33
		 * Plugin version
34
		 *
35
		 * @var string
36
		 * @since 2.0.0
37
		 */
38
		public static $version = '2.2.9';
39
40
		/**
41
		 * The single instance of the plugin class
42
		 *
43
		 * @var object
44
		 * @since 2.0.0
45
		 */
46
		protected static $_instance = null;
47
48
		/**
49
		 * Instance of admin class
50
		 *
51
		 * @var object
52
		 * @since 2.0.0
53
		 */
54
		protected static $admin = null;
55
56
		/**
57
		 * Instance of admin pointer class
58
		 *
59
		 * @var object
60
		 * @since 2.1.0
61
		 */
62
		protected static $admin_pointer = null;
63
64
		/**
65
		 * Instance of compatibility class
66
		 *
67
		 * @var object
68
		 * @since 2.0.0
69
		 */
70
		protected static $compatibility = null;
71
72
		/**
73
		 * Instance of the text filters class
74
		 *
75
		 * @var object
76
		 * @since 2.0.0
77
		 */
78
		protected static $text_filters = null;
79
80
		/**
81
		 * Return the main plugin instance
82
		 *
83
		 * @return object
84
		 * @since 2.0.0
85
		 */
86
		public static function instance() {
87
			if ( is_null( self::$_instance ) ) {
88
				self::$_instance = new self();
89
			}
90
			return self::$_instance;
91
		}
92
93
		/**
94
		 * Return the instance of the admin class
95
		 *
96
		 * @return object
97
		 * @since 2.0.0
98
		 */
99
		public static function admin() {
100
			return self::$admin;
101
		}
102
103
		/**
104
		 * Return the instance of the admin pointer class
105
		 *
106
		 * @return object
107
		 * @since 2.1.0
108
		 */
109
		public static function admin_pointer() {
110
			return self::$admin_pointer;
111
		}
112
113
		/**
114
		 * Return the instance of the compatibility class
115
		 *
116
		 * @return object
117
		 * @since 2.0.0
118
		 */
119
		public static function compatibility() {
120
			return self::$compatibility;
121
		}
122
123
		/**
124
		 * Return the instance of the text filters class
125
		 *
126
		 * @return object
127
		 * @since 2.0.0
128
		 */
129
		public static function text_filters() {
130
			return self::$text_filters;
131
		}
132
133
		/**
134
		 * Get plugin version
135
		 *
136
		 * @return string
137
		 * @since 2.0.0
138
		 */
139
		public static function get_version() {
140
			return self::$version;
141
		}
142
143
		/**
144
		 * Get plugin basename
145
		 *
146
		 * @uses plugin_basename()
147
		 *
148
		 * @return string
149
		 * @since 2.0.0
150
		 */
151
		public static function get_basename() {
152
			return plugin_basename( __FILE__ );
153
		}
154
155
		/**
156
		 * Class constructor
157
		 *
158
		 * @uses is_admin()
159
		 * @uses add_action()
160
		 * @uses add_filter()
161
		 * @uses get_option()
162
		 * @uses get_bloginfo()
163
		 *
164
		 * @global object $wp_embed
165
		 * @since 2.0.0
166
		 */
167
		protected function __construct() {
168
			// Include required files
169
			include_once( plugin_dir_path( __FILE__ ) . 'includes/class-widget.php' );
170
			// Include and instantiate admin class on admin pages
171
			if ( is_admin() ) {
172
				include_once( plugin_dir_path( __FILE__ ) . 'includes/class-admin.php' );
173
				self::$admin = Black_Studio_TinyMCE_Admin::instance();
174
				include_once( plugin_dir_path( __FILE__ ) . 'includes/class-admin-pointer.php' );
175
				self::$admin_pointer = Black_Studio_TinyMCE_Admin_Pointer::instance();
176
			}
177
			// Include and instantiate text filter class on frontend pages
178
			else {
179
				include_once( plugin_dir_path( __FILE__ ) . 'includes/class-text-filters.php' );
180
				self::$text_filters = Black_Studio_TinyMCE_Text_Filters::instance();
181
			}
182
			// Register action and filter hooks
183
			add_action( 'plugins_loaded', array( $this, 'load_compatibility' ), 50 );
184
			add_action( 'widgets_init', array( $this, 'widgets_init' ) );
185
		}
186
187
		/**
188
		 * Prevent the class from being cloned
189
		 *
190
		 * @return void
191
		 * @since 2.0.0
192
		 */
193
		protected function __clone() {
194
			_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; uh?' ), '2.0' );
195
		}
196
197
		/**
198
		 * Load compatibility class
199
		 *
200
		 * @uses apply_filters()
201
		 * @uses get_bloginfo()
202
		 * @uses plugin_dir_path()
203
		 *
204
		 * @return void
205
		 * @since 2.0.0
206
		 */
207
		public function load_compatibility() {
208
			// Compatibility load flag (for both deprecated functions and code for compatibility with other plugins)
209
			$load_compatibility = apply_filters( 'black_studio_tinymce_load_compatibility', true );
210
			if ( $load_compatibility ) {
211
				include_once( plugin_dir_path( __FILE__ ) . 'compat/class-compatibility.php' );
212
				self::$compatibility = Black_Studio_TinyMCE_Compatibility::instance();
213
			}
214
		}
215
216
		/**
217
		 * Widget initialization
218
		 *
219
		 * @uses is_blog_installed()
220
		 * @uses register_widget()
221
		 *
222
		 * @return null|void
223
		 * @since 2.0.0
224
		 */
225
		public function widgets_init() {
226
			if ( ! is_blog_installed() ) {
227
				return;
228
			}
229
			register_widget( 'WP_Widget_Black_Studio_TinyMCE' );
230
		}
231
232
		/**
233
		 * Check if a widget is a Black Studio Tinyme Widget instance
234
		 *
235
		 * @param object $widget
236
		 * @return boolean
237
		 * @since 2.0.0
238
		 */
239
		public function check_widget( $widget ) {
240
			return 'object' == gettype( $widget ) && ( 'WP_Widget_Black_Studio_TinyMCE' == get_class( $widget ) || is_subclass_of( $widget , 'WP_Widget_Black_Studio_TinyMCE' ) );
241
		}
242
243
	} // END class Black_Studio_TinyMCE_Plugin
244
245
} // END class_exists check
246
247
248
if ( ! function_exists( 'bstw' ) ) {
249
250
	/**
251
	 * Return the main instance to prevent the need to use globals
252
	 *
253
	 * @return object
254
	 * @since 2.0.0
255
	 */
256
	function bstw() {
257
		return Black_Studio_TinyMCE_Plugin::instance();
258
	}
259
260
	/* Create the main instance */
261
	bstw();
262
263
} // END function_exists bstw check
264
else {
265
266
	/* Check for multiple plugin instances */
267
	if ( ! function_exists( 'bstw_multiple_notice' ) ) {
268
269
		/**
270
		 * Show admin notice when multiple instances of the plugin are detected
271
		 *
272
		 * @return void
273
		 * @since 2.1.0
274
		 */
275
		function bstw_multiple_notice() {
276
			global $pagenow;
277
			if ( 'widgets.php' == $pagenow ) {
278
				echo '<div class="error">';
279
				/* translators: error message shown when multiple instance of the plugin are detected */
280
				echo '<p>' . esc_html( __( 'ERROR: Multiple instances of the Black Studio TinyMCE Widget plugin were detected. Please activate only one instance at a time.', 'black-studio-tinymce-widget' ) ) . '</p>';
281
				echo '</div>';
282
			}
283
		}
284
		add_action( 'admin_notices', 'bstw_multiple_notice' );
285
286
	} // END function_exists bstw_multiple_notice check
287
288
} // END else function_exists bstw check
289