Siteorigin_Panels   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 166
rs 10
c 0
b 0
f 0
wmc 18
cbo 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 6 2
A __construct() 0 9 3
A __clone() 0 3 1
A admin_init() 0 11 2
A widget_object() 0 6 3
A container_selectors() 0 4 1
A activate_events() 0 4 1
A deactivate_events() 0 4 1
A enable_pages() 0 9 2
A additional_fields() 0 4 1
A disable_compat() 0 4 1
1
<?php
2
/**
3
 * Black Studio TinyMCE Widget - Compatibility with Page Builder (SiteOrigin Panels)
4
 *
5
 * @package Black_Studio_TinyMCE_Widget
6
 */
7
8
namespace Black_Studio_TinyMCE_Widget\Compatibility\Plugin;
9
10
// Exit if accessed directly.
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
if ( ! class_exists( 'Black_Studio_TinyMCE_Widget\\Compatibility\\Plugin\\Siteorigin_Panels', false ) ) {
16
17
	/**
18
	 * Class that provides compatibility code for Page Builder (SiteOrigin Panels)
19
	 *
20
	 * @package Black_Studio_TinyMCE_Widget
21
	 * @since 2.4.0
22
	 */
23
	final class Siteorigin_Panels {
24
25
		/**
26
		 * The single instance of the class
27
		 *
28
		 * @var object
29
		 * @since 3.0.0
30
		 */
31
		protected static $_instance = null;
32
33
		/**
34
		 * Return the single class instance
35
		 *
36
		 * @return object
37
		 * @since 2.4.0
38
		 */
39
		public static function instance() {
40
			if ( is_null( self::$_instance ) ) {
41
				self::$_instance = new self();
42
			}
43
			return self::$_instance;
44
		}
45
46
		/**
47
		 * Class constructor
48
		 *
49
		 * @uses is_admin()
50
		 * @uses add_action()
51
		 *
52
		 * @since 3.0.0
53
		 */
54
		protected function __construct() {
55
			if ( is_admin() ) {
56
				add_action( 'admin_init', array( $this, 'disable_compat' ), 7 );
57
				add_action( 'admin_init', array( $this, 'admin_init' ) );
58
			}
59
			if ( ! function_exists( 'is_plugin_active' ) ) {
60
				include_once ABSPATH . 'wp-admin/includes/plugin.php';
61
			}
62
		}
63
64
		/**
65
		 * Prevent the class from being cloned
66
		 *
67
		 * @return void
68
		 * @since 3.0.0
69
		 */
70
		protected function __clone() {
71
			_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; uh?' ), '3.0' );
72
		}
73
74
		/**
75
		 * Initialize compatibility for Page Builder (SiteOrigin Panels)
76
		 *
77
		 * @uses add_filter()
78
		 * @uses remove_filter()
79
		 * @uses is_plugin_active()
80
		 *
81
		 * @return void
82
		 * @since 3.0.0
83
		 */
84
		public function admin_init() {
85
			if ( is_plugin_active( 'siteorigin-panels/siteorigin-panels.php' ) ) {
86
				add_filter( 'siteorigin_panels_widget_object', array( $this, 'widget_object' ), 10 );
87
				add_filter( 'black_studio_tinymce_container_selectors', array( $this, 'container_selectors' ) );
88
				add_filter( 'black_studio_tinymce_activate_events', array( $this, 'activate_events' ) );
89
				add_filter( 'black_studio_tinymce_deactivate_events', array( $this, 'deactivate_events' ) );
90
				add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'enable_pages' ) );
91
				add_filter( 'black_studio_tinymce_widget_additional_fields', array( $this, 'additional_fields' ) );
92
				remove_filter( 'widget_text', array( bstw()->text_filters(), 'wpautop' ), 8 );
93
			}
94
		}
95
96
		/**
97
		 * Remove widget number to prevent translation when using Page Builder (SiteOrigin Panels) + WPML String Translation
98
		 *
99
		 * @param object $widget Widget object.
100
		 * @return object
101
		 * @since 3.0.0
102
		 */
103
		public function widget_object( $widget ) {
104
			if ( isset( $widget->id_base ) && 'black-studio-tinymce' === $widget->id_base ) {
105
				$widget->number = '';
106
			}
107
			return $widget;
108
		}
109
110
		/**
111
		 * Add selector for widget detection for Page Builder (SiteOrigin Panels)
112
		 *
113
		 * @param string[] $selectors Array of selectors.
114
		 * @return string[]
115
		 * @since 3.0.0
116
		 */
117
		public function container_selectors( $selectors ) {
118
			$selectors[] = 'div.panel-dialog';
119
			return $selectors;
120
		}
121
122
		/**
123
		 * Add activate events for Page Builder (SiteOrigin Panels)
124
		 *
125
		 * @param string[] $events Array of events.
126
		 * @return string[]
127
		 * @since 3.0.0
128
		 */
129
		public function activate_events( $events ) {
130
			$events[] = 'panelsopen';
131
			return $events;
132
		}
133
134
		/**
135
		 * Add deactivate events for Page Builder (SiteOrigin Panels)
136
		 *
137
		 * @param string[] $events Array of events.
138
		 * @return string[]
139
		 * @since 3.0.0
140
		 */
141
		public function deactivate_events( $events ) {
142
			$events[] = 'panelsdone';
143
			return $events;
144
		}
145
146
		/**
147
		 * Add pages filter to enable editor for Page Builder (SiteOrigin Panels)
148
		 *
149
		 * @param string[] $pages Array of pages.
150
		 * @return string[]
151
		 * @since 3.0.0
152
		 */
153
		public function enable_pages( $pages ) {
154
			$page    = filter_input( INPUT_GET, 'page' );
155
			$pages[] = 'post-new.php';
156
			$pages[] = 'post.php';
157
			if ( 'so_panels_home_page' === $page ) {
158
				$pages[] = 'themes.php';
159
			}
160
			return $pages;
161
		}
162
163
		/**
164
		 * Add widget field for Page Builder (SiteOrigin Panels)
165
		 *
166
		 * @param string[] $fields Array of fields.
167
		 * @return string[]
168
		 * @since 3.0.0
169
		 */
170
		public function additional_fields( $fields ) {
171
			$fields[] = 'panels_info';
172
			return $fields;
173
		}
174
175
		/**
176
		 * Disable old compatibility code provided by Page Builder (SiteOrigin Panels)
177
		 *
178
		 * @uses remove_action()
179
		 *
180
		 * @return void
181
		 * @since 3.0.0
182
		 */
183
		public function disable_compat() {
184
			remove_action( 'admin_init', 'siteorigin_panels_black_studio_tinymce_admin_init' );
185
			remove_action( 'admin_enqueue_scripts', 'siteorigin_panels_black_studio_tinymce_admin_enqueue', 15 );
186
		}
187
188
	} // END class
189
190
} // END class_exists
191