PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
← All changes | includes/class.plugin.php +179 -110 2.4.102.7.1 View file →
@@ -1,11 +1,9 @@
1 1 <?php
2 2 /**
3 3 * PHP snippets plugin base
4 4 *
5 - * @author Webcraftic <WordPress.webraftic@gmail.com>
6 - * @copyright (c) 19.02.2018, Webcraftic
7 - * @version 1.0
5 + * @package Woody_Code_Snippets
8 6 */
9 7
10 8 // Exit if accessed directly
11 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -13,42 +11,76 @@
13 11 }
14 12
15 13 if ( ! class_exists( 'WINP_Plugin' ) ) {
16 14
17 - class WINP_Plugin extends Wbcr_Factory466_Plugin {
15 + class WINP_Plugin {
18 16
19 17 /**
20 - * @var Wbcr_Factory466_Plugin
18 + * Custom license provider (overrides parent's premium property)
19 + *
20 + * @var WINP_License
21 21 */
22 + public $premium;
23 +
24 + /**
25 + * @var WINP_Plugin
26 + */
22 27 private static $app;
23 28
24 29 /**
25 - * @param string $plugin_path
26 - * @param array $data
30 + * Snippets custom post type instance.
27 31 *
32 + * @var WINP_SnippetsType
33 + */
34 + private $snippets_type;
35 +
36 + /**
28 37 * @throws Exception
29 38 */
30 - public function __construct( $plugin_path, $data ) {
31 - parent::__construct( $plugin_path, $data );
39 + public function __construct() {
40 + self::$app = $this;
32 41
33 - self::$app = $this;
42 + // Initialize custom license provider.
43 + require_once WINP_PLUGIN_DIR . '/includes/class.license.php';
44 + $this->premium = new WINP_License();
34 45
46 + require_once WINP_PLUGIN_DIR . '/includes/class.rest.php';
47 + new WINP_Rest();
48 +
49 + require_once WINP_PLUGIN_DIR . '/admin/pages/class.settings.php';
50 + require_once WINP_PLUGIN_DIR . '/admin/pages/class.new-item.php';
51 + require_once WINP_PLUGIN_DIR . '/admin/pages/class.snippet-library.php';
52 +
53 + WINP_Settings::get_instance();
54 + WINP_NewItem::get_instance();
55 + WINP_SnippetLibrary::get_instance();
56 +
35 57 $this->load_global();
36 58
37 59 if ( is_admin() ) {
38 - $this->initActivation();
39 60
40 61 if ( WINP_Helper::doing_ajax() ) {
41 62 require WINP_PLUGIN_DIR . '/admin/ajax/ajax.php';
42 - require WINP_PLUGIN_DIR . '/admin/ajax/check-license.php';
43 63 require WINP_PLUGIN_DIR . '/admin/ajax/snippet-library.php';
44 64 }
45 65
46 66 $this->load_backend();
47 67 }
68 + add_action(
69 + 'init',
70 + function () {
71 + if ( WINP_Plugin::app()->premium->is_active() ) {
72 + update_option( WINP_PLUGIN_NAMESPACE . '_logger_flag', 'yes' );
73 + }
74 + }
75 + );
76 +
77 + add_filter( WINP_PLUGIN_NAMESPACE . '_logger_data', [ $this, 'get_logger_data' ] );
48 78 }
49 79
50 80 /**
81 + * Get plugin instance
82 + *
51 83 * @return WINP_Plugin
52 84 */
53 85 public static function app() {
54 86 return self::$app;
@@ -54,11 +86,40 @@
54 86 return self::$app;
55 87 }
56 88
57 89 /**
90 + * Survey data.
91 + *
92 + * @return array<string, mixed>
93 + */
94 + public function get_survey_data() {
95 + $install_time = get_option( WINP_PLUGIN_NAMESPACE . '_install', time() );
96 + $days_since_install = round( ( time() - $install_time ) / DAY_IN_SECONDS );
97 + $total_snippets = wp_count_posts( WINP_SNIPPETS_POST_TYPE );
98 + $total_snippets = isset( $total_snippets->publish ) ? $total_snippets->publish : 0;
99 +
100 + $data = [
101 + 'environmentId' => 'cmiooosih4vm0ad01eihjub64',
102 + 'attributes' => [
103 + 'free_version' => WINP_PLUGIN_VERSION,
104 + 'pro_version' => defined( 'WASP_PLUGIN_VERSION' ) ? WASP_PLUGIN_VERSION : '',
105 + 'install_days_number' => $days_since_install,
106 + 'license_status' => self::app()->premium->is_active(),
107 + 'total_snippets' => $total_snippets,
108 + ],
109 + ];
110 +
111 + if ( self::app()->premium->is_active() ) {
112 + $data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', self::app()->premium->get_key() );
113 + }
114 +
115 + return $data;
116 + }
117 +
118 + /**
58 119 * @return bool
59 120 */
60 - public function currentUserCan() {
121 + public function current_user_car() {
61 122 return current_user_can( 'manage_options' );
62 123 }
63 124
64 125 /**
@@ -65,12 +126,12 @@
65 126 * Get Execute_Snippet object
66 127 *
67 128 * @return WINP_Execute_Snippet
68 129 */
69 - public function getExecuteObject() {
130 + public function get_execute_object() {
70 131 require_once WINP_PLUGIN_DIR . '/includes/class.execute.snippet.php';
71 132
72 - return new WINP_Execute_Snippet();
133 + return WINP_Execute_Snippet::app();
73 134 }
74 135
75 136 /**
76 137 * Get WINP_Api object
@@ -77,8 +138,9 @@
77 138 *
78 139 * @return WINP_Api
79 140 */
80 141 public function get_api_object() {
142 + require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php';
81 143 require_once WINP_PLUGIN_DIR . '/admin/includes/class.api.php';
82 144
83 145 return new WINP_Api();
84 146 }
@@ -94,75 +156,58 @@
94 156 return new WINP_Common_Snippet();
95 157 }
96 158
97 159 /**
98 - * @throws \Exception
99 - * @since 2.2.0
100 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
160 + * Plugin activation hook.
161 + * Creates demo snippets on first activation and sets up capabilities.
162 + *
163 + * @return void
101 164 */
102 - /*
103 - public function plugins_loaded() {
104 - $this->register_pages();
105 - }*/
106 -
107 - protected function initActivation() {
108 - include_once WINP_PLUGIN_DIR . '/admin/activation.php';
109 - $this->registerActivation( 'WINP_Activation' );
165 + public function activation_hook() {
166 + // Add custom capabilities to administrator role.
167 + $this->snippets_type->add_capabilities();
168 +
169 + // Create demo snippets with examples of use.
170 + if ( ! get_option( 'wbcr_inp_demo_snippets_created' ) ) {
171 + WINP_Helper::create_demo_snippets();
172 + }
173 +
174 + WINP_Helper::flush_page_cache();
110 175 }
111 176
112 177 /**
113 - * @throws \Exception
114 - * @since 2.2.0
115 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
178 + * Plugin deactivation hook.
179 + * Removes custom capabilities.
180 + *
181 + * @return void
116 182 */
117 - public function register_pages() {
118 - require_once WINP_PLUGIN_DIR . '/admin/pages/page.php';
119 -
120 - $this->registerPage( 'WINP_NewItemPage', WINP_PLUGIN_DIR . '/admin/pages/new-item.php' );
121 - $this->registerPage( 'WINP_SettingsPage', WINP_PLUGIN_DIR . '/admin/pages/settings.php' );
122 - $this->registerPage( 'WINP_SnippetLibraryPage', WINP_PLUGIN_DIR . '/admin/pages/snippet-library.php' );
123 - $this->registerPage( 'WINP_License_Page', WINP_PLUGIN_DIR . '/admin/pages/license.php' );
124 - $this->registerPage( 'WINP_AboutPage', WINP_PLUGIN_DIR . '/admin/pages/about.php' );
183 + public function deactivation_hook() {
184 + // Remove custom capabilities from administrator role.
185 + $this->snippets_type->remove_capabilities();
125 186 }
126 187
127 188 /**
128 - * @throws \Exception
189 + * Register custom post types and taxonomies.
190 + *
191 + * @throws \Exception Exception.
129 192 * @since 2.2.0
130 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
131 193 */
132 - public function register_depence_pages() {
133 - require_once WINP_PLUGIN_DIR . '/admin/pages/page.php';
134 -
135 - if ( ! ( defined( 'WASP_PLUGIN_ACTIVE' ) && WASP_PLUGIN_ACTIVE ) ) {
136 - $this->registerPage( 'WINP_ImportPage', WINP_PLUGIN_DIR . '/admin/pages/import.php' );
137 - }
138 - }
139 -
140 - /**
141 - * @throws \Exception
142 - * @since 2.2.0
143 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
144 - */
145 194 private function register_types() {
146 195 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php';
147 - Wbcr_FactoryTypes413::register( 'WINP_SnippetsType', $this );
196 + $this->snippets_type = new WINP_SnippetsType();
148 197
149 198 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-taxonomy.php';
150 - Wbcr_FactoryTaxonomies333::register( 'WINP_SnippetsTaxonomy', $this );
199 + new WINP_SnippetsTaxonomy();
151 200 }
152 201
153 202 /**
154 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
203 + * Register shortcodes.
204 + *
155 205 * @since 2.2.0
156 206 */
157 207 private function register_shortcodes() {
158 - $action = self::app()->request->get( 'action', '' );
208 + $action = WINP_HTTP::get( 'action', '' );
159 209 if ( ! ( 'edit' == $action && is_admin() ) ) {
160 - if ( self::app()->getOption( 'support_old_shortcodes' ) ) {
161 - // todo: Deprecated
162 - require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-insert-php.php';
163 - }
164 -
165 210 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcodes.php';
166 211 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-php.php';
167 212 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-text.php';
168 213 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-universal.php';
@@ -183,35 +228,19 @@
183 228
184 229 /**
185 230 * Initialization and require files for backend and frontend.
186 231 *
187 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
188 232 * @since 2.2.0
189 233 */
190 234 private function load_global() {
191 235 require_once WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php';
236 + require_once WINP_PLUGIN_DIR . '/includes/class.admin-bar.php';
192 237
193 238 new WINP_Gutenberg_Snippet();
239 + WINP_Admin_Bar::instance();
194 240
195 - $this->getExecuteObject()->registerHooks();
241 + $this->get_execute_object()->register_hooks();
196 242 $this->register_shortcodes();
197 -
198 - /**
199 - * Enables/Disable safe mode, in which the php code will not be executed.
200 - */
201 - add_action( 'plugins_loaded', function () {
202 - if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) {
203 - WINP_Helper::enable_safe_mode();
204 - wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) ) );
205 - die();
206 - }
207 -
208 - if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) {
209 - WINP_Helper::disable_safe_mode();
210 - wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) ) );
211 - die();
212 - }
213 - }, - 1 );
214 243 }
215 244
216 245 /**
217 246 * Initialization and require files for backend.
@@ -217,46 +246,40 @@
217 246 * Initialization and require files for backend.
218 247 *
219 248 * @throws \Exception
220 249 * @since 2.2.0
221 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
222 250 */
223 251 private function load_backend() {
224 252 require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php';
225 253 require_once WINP_PLUGIN_DIR . '/admin/includes/class.filter.snippet.php';
226 254 require_once WINP_PLUGIN_DIR . '/admin/includes/class.actions.snippet.php';
227 - require_once WINP_PLUGIN_DIR . '/admin/includes/class.import.snippet.php';
228 255 require_once WINP_PLUGIN_DIR . '/admin/includes/class.notices.php';
256 + require_once WINP_PLUGIN_DIR . '/admin/includes/class.admin.notices.php';
229 257 require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php';
230 - require_once WINP_PLUGIN_DIR . '/admin/metaboxes/metabox.php';
231 258 require_once WINP_PLUGIN_DIR . '/admin/boot.php';
232 259
233 - $this->get_common_object()->registerHooks();
234 -
260 + $this->get_common_object()->register_hooks();
235 261 $this->register_types();
236 262
237 263 new WINP_Filter_List();
238 - new WINP_Export_Snippet();
239 - new WINP_Import_Snippet();
240 - new WINP_WarningNotices();
264 + new WINP_Actions_Snippet();
265 + WINP_Notices::instance();
266 + new WINP_Admin_Notices();
241 267
242 - # Required for i18n to be loaded properly
243 - add_action( 'plugins_loaded', [ $this, 'register_pages' ] );
268 + if ( ! defined( 'E2E_TESTING' ) ) {
269 + add_filter(
270 + 'themeisle-sdk/survey/' . WINP_PLUGIN_SLUG,
271 + function ( $data, $page_slug ) {
272 + if ( empty( $page_slug ) ) {
273 + return $data;
274 + }
244 275
245 - # Required for compatibility with the premium plugin.
246 - # We set the priority to 30 to wait for the premium plugin to load.
247 - add_action( 'plugins_loaded', [ $this, 'register_depence_pages' ], 30 );
248 -
249 - add_action( 'wbcr_factory_forms_463_register_controls', function () {
250 - $colorControls = [
251 - [
252 - 'type' => 'winp-dropdown',
253 - 'class' => 'WINP_FactoryForms_Dropdown',
254 - 'include' => WINP_PLUGIN_DIR . '/includes/controls/class.dropdown.php',
255 - ],
256 - ];
257 - $this->forms->registerControls( $colorControls );
258 - } );
276 + return $this->get_survey_data();
277 + },
278 + 10,
279 + 2
280 + );
281 + }
259 282 }
260 283
261 284 /**
262 285 * Метод проверяет активацию премиум плагина и наличие действующего лицензионного ключа
@@ -263,14 +286,60 @@
263 286 *
264 287 * @return bool
265 288 */
266 289 public function is_premium() {
267 - if ( $this->premium->is_active() && $this->premium->is_activate() //&& $this->premium->is_install_package()
268 - ) {
269 - return true;
270 - } else {
271 - return false;
290 + return $this->premium->is_active();
291 + }
292 +
293 + /**
294 + * Logger data.
295 + *
296 + * @return array<string, mixed>
297 + */
298 + public function get_logger_data() {
299 + $settings = WINP_Settings::get_instance()->get_settings();
300 +
301 + // Each settings has a lot of keys, we only want name and value items. So map them.
302 + $settings = array_map(
303 + function ( $setting ) {
304 + return [
305 + 'name' => isset( $setting['name'] ) ? $setting['name'] : '',
306 + 'value' => isset( $setting['value'] ) ? $setting['value'] : '',
307 + ];
308 + },
309 + $settings
310 + );
311 +
312 + $total_snippets = wp_count_posts( WINP_SNIPPETS_POST_TYPE );
313 + $total_snippets = isset( $total_snippets->publish ) ? $total_snippets->publish : 0;
314 +
315 + // Count snippets by type.
316 + $snippet_types = [ 'php', 'css', 'js', 'text', 'html', 'advert', 'universal' ];
317 + $types_count = [];
318 +
319 + foreach ( $snippet_types as $type ) {
320 + $count = get_posts(
321 + [
322 + 'post_type' => WINP_SNIPPETS_POST_TYPE,
323 + 'post_status' => 'publish',
324 + 'meta_key' => 'wbcr_inp_snippet_type',
325 + 'meta_value' => $type,
326 + 'posts_per_page' => -1,
327 + 'fields' => 'ids',
328 + ]
329 + );
330 +
331 + if ( ! empty( $count ) ) {
332 + $types_count[ $type ] = count( $count );
333 + }
272 334 }
335 +
336 + return [
337 + 'settings' => $settings,
338 + 'stats' => [
339 + 'total_snippets' => $total_snippets,
340 + 'types' => $types_count,
341 + ],
342 + ];
273 343 }
274 -
275 344 }
276 345 }