PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.6.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.6.1
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 2.7.1 All 27 releases
← All changes | includes/class.plugin.php +126 -236 trunk2.6.1 View file →
@@ -1,9 +1,11 @@
1 1 <?php
2 2 /**
3 3 * PHP snippets plugin base
4 4 *
5 - * @package Woody_Code_Snippets
5 + * @author Webcraftic <WordPress.webraftic@gmail.com>
6 + * @copyright (c) 19.02.2018, Webcraftic
7 + * @version 1.0
6 8 */
7 9
8 10 // Exit if accessed directly
9 11 if ( ! defined( 'ABSPATH' ) ) {
@@ -11,116 +13,79 @@
11 13 }
12 14
13 15 if ( ! class_exists( 'WINP_Plugin' ) ) {
14 16
15 - class WINP_Plugin {
17 + class WINP_Plugin extends Wbcr_Factory475_Plugin {
16 18
17 19 /**
18 - * Custom license provider (overrides parent's premium property)
19 - *
20 - * @var WINP_License
20 + * @var Wbcr_Factory475_Plugin
21 21 */
22 - public $premium;
23 -
24 - /**
25 - * @var WINP_Plugin
26 - */
27 22 private static $app;
28 23
29 24 /**
30 - * Snippets custom post type instance.
25 + * @param string $plugin_path
26 + * @param array $data
31 27 *
32 - * @var WINP_SnippetsType
28 + * @throws Exception
33 29 */
34 - private $snippets_type;
30 + public function __construct( $plugin_path, $data ) {
31 + parent::__construct( $plugin_path, $data );
35 32
36 - /**
37 - * @throws Exception
38 - */
39 - public function __construct() {
40 33 self::$app = $this;
41 34
42 - // Initialize custom license provider.
43 - require_once WINP_PLUGIN_DIR . '/includes/class.license.php';
44 - $this->premium = new WINP_License();
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 -
57 35 $this->load_global();
58 36
59 - if ( is_admin() || WINP_Helper::doing_rest_api() ) {
37 + if ( is_admin() ) {
38 + $this->initActivation();
60 39
61 40 if ( WINP_Helper::doing_ajax() ) {
62 41 require WINP_PLUGIN_DIR . '/admin/ajax/ajax.php';
42 + require WINP_PLUGIN_DIR . '/admin/ajax/check-license.php';
63 43 require WINP_PLUGIN_DIR . '/admin/ajax/snippet-library.php';
64 44 }
65 45
66 46 $this->load_backend();
67 47 }
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 - }
48 + add_action( 'init', function () {
49 + if(WINP_Plugin::app()->premium->is_active()){
50 + update_option( 'insert_php_logger_flag', 'yes' );
74 51 }
75 - );
76 -
77 - add_filter( WINP_PLUGIN_NAMESPACE . '_logger_data', [ $this, 'get_logger_data' ] );
78 - add_filter( 'themeisle_sdk_blackfriday_data', [ $this, 'add_black_friday_data' ] );
52 + } );
53 + add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] );
54 + add_filter( 'themeisle_sdk_ran_promos', [ __CLASS__, 'sdk_hide_promo_notice' ] );
79 55 }
80 56
81 57 /**
82 - * Get plugin instance
58 + * Hide SDK promo notice for pro uses.
83 59 *
84 - * @return WINP_Plugin
60 + * @access public
85 61 */
86 - public static function app() {
87 - return self::$app;
62 + public static function sdk_hide_promo_notice( $should_show ) {
63 + return WINP_Plugin::app()->premium->is_active();
88 64 }
89 -
90 65 /**
91 - * Survey data.
66 + * Register product into SDK.
92 67 *
93 - * @return array<string, mixed>
68 + * @param array $products All products.
69 + *
70 + * @return array Registered product.
94 71 */
95 - public function get_survey_data() {
96 - $install_time = get_option( WINP_PLUGIN_NAMESPACE . '_install', time() );
97 - $days_since_install = round( ( time() - $install_time ) / DAY_IN_SECONDS );
98 - $total_snippets = wp_count_posts( WINP_SNIPPETS_POST_TYPE );
99 - $total_snippets = isset( $total_snippets->publish ) ? $total_snippets->publish : 0;
72 + public static function register_sdk( $products ) {
73 + $products[] = WINP_PLUGIN_FILE;
100 74
101 - $data = [
102 - 'environmentId' => 'cmiooosih4vm0ad01eihjub64',
103 - 'attributes' => [
104 - 'free_version' => WINP_PLUGIN_VERSION,
105 - 'pro_version' => defined( 'WASP_PLUGIN_VERSION' ) ? WASP_PLUGIN_VERSION : '',
106 - 'install_days_number' => $days_since_install,
107 - 'license_status' => self::app()->premium->is_active(),
108 - 'total_snippets' => $total_snippets,
109 - ],
110 - ];
111 -
112 - if ( self::app()->premium->is_active() ) {
113 - $data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', self::app()->premium->get_key() );
114 - }
115 -
116 - return $data;
75 + return $products;
117 76 }
77 + /**
78 + * @return WINP_Plugin
79 + */
80 + public static function app() {
81 + return self::$app;
82 + }
118 83
119 84 /**
120 85 * @return bool
121 86 */
122 - public function current_user_car() {
87 + public function currentUserCan() {
123 88 return current_user_can( 'manage_options' );
124 89 }
125 90
126 91 /**
@@ -127,12 +92,12 @@
127 92 * Get Execute_Snippet object
128 93 *
129 94 * @return WINP_Execute_Snippet
130 95 */
131 - public function get_execute_object() {
96 + public function getExecuteObject() {
132 97 require_once WINP_PLUGIN_DIR . '/includes/class.execute.snippet.php';
133 98
134 - return WINP_Execute_Snippet::app();
99 + return new WINP_Execute_Snippet();
135 100 }
136 101
137 102 /**
138 103 * Get WINP_Api object
@@ -139,9 +104,8 @@
139 104 *
140 105 * @return WINP_Api
141 106 */
142 107 public function get_api_object() {
143 - require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php';
144 108 require_once WINP_PLUGIN_DIR . '/admin/includes/class.api.php';
145 109
146 110 return new WINP_Api();
147 111 }
@@ -157,57 +121,69 @@
157 121 return new WINP_Common_Snippet();
158 122 }
159 123
160 124 /**
161 - * Plugin activation hook.
162 - * Creates demo snippets on first activation and sets up capabilities.
163 - *
164 - * @return void
125 + * @throws \Exception
126 + * @since 2.2.0
127 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
165 128 */
166 - public function activation_hook() {
167 - // Add custom capabilities to administrator role.
168 - $this->snippets_type->add_capabilities();
129 + /*
130 + public function plugins_loaded() {
131 + $this->register_pages();
132 + }*/
169 133
170 - // Create demo snippets with examples of use.
171 - if ( ! get_option( 'wbcr_inp_demo_snippets_created' ) ) {
172 - WINP_Helper::create_demo_snippets();
173 - }
134 + protected function initActivation() {
135 + include_once WINP_PLUGIN_DIR . '/admin/activation.php';
136 + $this->registerActivation( 'WINP_Activation' );
137 + }
174 138
175 - WINP_Helper::flush_page_cache();
139 + /**
140 + * @throws \Exception
141 + * @since 2.2.0
142 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
143 + */
144 + public function register_pages() {
145 + require_once WINP_PLUGIN_DIR . '/admin/pages/page.php';
146 +
147 + $this->registerPage( 'WINP_NewItemPage', WINP_PLUGIN_DIR . '/admin/pages/new-item.php' );
148 + $this->registerPage( 'WINP_SettingsPage', WINP_PLUGIN_DIR . '/admin/pages/settings.php' );
149 + $this->registerPage( 'WINP_SnippetLibraryPage', WINP_PLUGIN_DIR . '/admin/pages/snippet-library.php' );
150 + $this->registerPage( 'WINP_License_Page', WINP_PLUGIN_DIR . '/admin/pages/license.php' );
151 + $this->registerPage( 'WINP_AboutPage', WINP_PLUGIN_DIR . '/admin/pages/about.php' );
176 152 }
177 153
178 154 /**
179 - * Plugin deactivation hook.
180 - * Removes custom capabilities.
181 - *
182 - * @return void
155 + * @throws \Exception
156 + * @since 2.2.0
157 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
183 158 */
184 - public function deactivation_hook() {
185 - // Remove custom capabilities from administrator role.
186 - $this->snippets_type->remove_capabilities();
159 + public function register_depence_pages() {
160 + require_once WINP_PLUGIN_DIR . '/admin/pages/page.php';
161 +
162 + if ( ! ( defined( 'WASP_PLUGIN_ACTIVE' ) && WASP_PLUGIN_ACTIVE ) ) {
163 + $this->registerPage( 'WINP_ImportPage', WINP_PLUGIN_DIR . '/admin/pages/import.php' );
164 + }
187 165 }
188 166
189 167 /**
190 - * Register custom post types and taxonomies.
191 - *
192 - * @throws \Exception Exception.
168 + * @throws \Exception
193 169 * @since 2.2.0
170 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
194 171 */
195 172 private function register_types() {
196 173 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php';
197 - $this->snippets_type = new WINP_SnippetsType();
174 + Wbcr_FactoryTypes415::register( 'WINP_SnippetsType', $this );
198 175
199 176 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-taxonomy.php';
200 - new WINP_SnippetsTaxonomy();
177 + Wbcr_FactoryTaxonomies335::register( 'WINP_SnippetsTaxonomy', $this );
201 178 }
202 179
203 180 /**
204 - * Register shortcodes.
205 - *
181 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
206 182 * @since 2.2.0
207 183 */
208 184 private function register_shortcodes() {
209 - $action = WINP_HTTP::get( 'action', '' );
185 + $action = self::app()->request->get( 'action', '' );
210 186 if ( ! ( 'edit' == $action && is_admin() ) ) {
211 187 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcodes.php';
212 188 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-php.php';
213 189 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-text.php';
@@ -229,19 +205,35 @@
229 205
230 206 /**
231 207 * Initialization and require files for backend and frontend.
232 208 *
209 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
233 210 * @since 2.2.0
234 211 */
235 212 private function load_global() {
236 213 require_once WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php';
237 - require_once WINP_PLUGIN_DIR . '/includes/class.admin-bar.php';
238 214
239 215 new WINP_Gutenberg_Snippet();
240 - WINP_Admin_Bar::instance();
241 216
242 - $this->get_execute_object()->register_hooks();
217 + $this->getExecuteObject()->registerHooks();
243 218 $this->register_shortcodes();
219 +
220 + /**
221 + * Enables/Disable safe mode, in which the php code will not be executed.
222 + */
223 + add_action( 'plugins_loaded', function () {
224 + if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) {
225 + WINP_Helper::enable_safe_mode();
226 + wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) ) );
227 + die();
228 + }
229 +
230 + if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) {
231 + WINP_Helper::disable_safe_mode();
232 + wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) ) );
233 + die();
234 + }
235 + }, - 1 );
244 236 }
245 237
246 238 /**
247 239 * Initialization and require files for backend.
@@ -247,40 +239,46 @@
247 239 * Initialization and require files for backend.
248 240 *
249 241 * @throws \Exception
250 242 * @since 2.2.0
243 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
251 244 */
252 245 private function load_backend() {
253 246 require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php';
254 247 require_once WINP_PLUGIN_DIR . '/admin/includes/class.filter.snippet.php';
255 248 require_once WINP_PLUGIN_DIR . '/admin/includes/class.actions.snippet.php';
249 + require_once WINP_PLUGIN_DIR . '/admin/includes/class.import.snippet.php';
256 250 require_once WINP_PLUGIN_DIR . '/admin/includes/class.notices.php';
257 - require_once WINP_PLUGIN_DIR . '/admin/includes/class.admin.notices.php';
258 251 require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php';
252 + require_once WINP_PLUGIN_DIR . '/admin/metaboxes/metabox.php';
259 253 require_once WINP_PLUGIN_DIR . '/admin/boot.php';
260 254
261 - $this->get_common_object()->register_hooks();
255 + $this->get_common_object()->registerHooks();
256 +
262 257 $this->register_types();
263 258
264 259 new WINP_Filter_List();
265 - new WINP_Actions_Snippet();
266 - WINP_Notices::instance();
267 - new WINP_Admin_Notices();
260 + new WINP_Export_Snippet();
261 + new WINP_Import_Snippet();
262 + new WINP_WarningNotices();
268 263
269 - if ( ! defined( 'E2E_TESTING' ) ) {
270 - add_filter(
271 - 'themeisle-sdk/survey/' . WINP_PLUGIN_SLUG,
272 - function ( $data, $page_slug ) {
273 - if ( empty( $page_slug ) ) {
274 - return $data;
275 - }
264 + # Required for i18n to be loaded properly
265 + add_action( 'plugins_loaded', [ $this, 'register_pages' ] );
276 266
277 - return $this->get_survey_data();
278 - },
279 - 10,
280 - 2
281 - );
282 - }
267 + # Required for compatibility with the premium plugin.
268 + # We set the priority to 30 to wait for the premium plugin to load.
269 + add_action( 'plugins_loaded', [ $this, 'register_depence_pages' ], 30 );
270 +
271 + add_action( 'wbcr_factory_forms_475_register_controls', function () {
272 + $colorControls = [
273 + [
274 + 'type' => 'winp-dropdown',
275 + 'class' => 'WINP_FactoryForms_Dropdown',
276 + 'include' => WINP_PLUGIN_DIR . '/includes/controls/class.dropdown.php',
277 + ],
278 + ];
279 + $this->forms->registerControls( $colorControls );
280 + } );
283 281 }
284 282
285 283 /**
286 284 * Метод проверяет активацию премиум плагина и наличие действующего лицензионного ключа
@@ -287,122 +285,14 @@
287 285 *
288 286 * @return bool
289 287 */
290 288 public function is_premium() {
291 - return $this->premium->is_active();
292 - }
293 -
294 - /**
295 - * Logger data.
296 - *
297 - * @return array<string, mixed>
298 - */
299 - public function get_logger_data() {
300 - $settings = WINP_Settings::get_instance()->get_settings();
301 -
302 - // Each settings has a lot of keys, we only want name and value items. So map them.
303 - $settings = array_map(
304 - function ( $setting ) {
305 - return [
306 - 'name' => isset( $setting['name'] ) ? $setting['name'] : '',
307 - 'value' => isset( $setting['value'] ) ? $setting['value'] : '',
308 - ];
309 - },
310 - $settings
311 - );
312 -
313 - $total_snippets = wp_count_posts( WINP_SNIPPETS_POST_TYPE );
314 - $total_snippets = isset( $total_snippets->publish ) ? $total_snippets->publish : 0;
315 -
316 - // Count snippets by type.
317 - $snippet_types = [ 'php', 'css', 'js', 'text', 'html', 'advert', 'universal' ];
318 - $types_count = [];
319 -
320 - foreach ( $snippet_types as $type ) {
321 - $count = get_posts(
322 - [
323 - 'post_type' => WINP_SNIPPETS_POST_TYPE,
324 - 'post_status' => 'publish',
325 - 'meta_key' => 'wbcr_inp_snippet_type',
326 - 'meta_value' => $type,
327 - 'posts_per_page' => -1,
328 - 'fields' => 'ids',
329 - ]
330 - );
331 -
332 - if ( ! empty( $count ) ) {
333 - $types_count[ $type ] = count( $count );
334 - }
289 + if ( $this->premium->is_active() && $this->premium->is_activate() //&& $this->premium->is_install_package()
290 + ) {
291 + return true;
292 + } else {
293 + return false;
335 294 }
336 -
337 - return [
338 - 'settings' => $settings,
339 - 'stats' => [
340 - 'total_snippets' => $total_snippets,
341 - 'types' => $types_count,
342 - ],
343 - ];
344 295 }
345 296
346 - /**
347 - * Set the black friday data.
348 - *
349 - * @param array<string, mixed> $configs The configuration array for the loaded products.
350 - *
351 - * @return array<string, mixed> The configurations.
352 - */
353 - public function add_black_friday_data( $configs ) {
354 - $config = $configs['default'];
355 -
356 - $message = __( 'Conditional logic, revision history, import/export. Manage your custom code properly. Exclusively for existing Woody users.', 'insert-php' );
357 - $cta_label = __( 'Get Woody Pro', 'insert-php' );
358 -
359 - $plan = apply_filters( 'product_woody_license_plan', 0 );
360 - $status = apply_filters( 'product_woody_license_status', 'invalid' );
361 - $license = apply_filters( 'product_woody_license_key', false );
362 - $pro_product_slug = defined( 'WASP_PLUGIN_FILE' ) ? basename( dirname( WASP_PLUGIN_FILE ) ) : '';
363 -
364 - $is_pro = 'valid' === $status;
365 - $is_expired = 'expired' === $status || 'active-expired' === $status;
366 -
367 - if ( $is_pro ) {
368 - // translators: %s is the discount percentage.
369 - $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - up to %s off', 'insert-php' ), '30%' );
370 - // translators: %1$s - discount, %2$s - discount.
371 - $message = sprintf( __( 'Upgrade your Woody Pro plan: %1$s off this week. Already on the plan you need? Renew early and save up to %2$s.', 'insert-php' ), '30%', '20%' );
372 - $cta_label = __( 'See your options', 'insert-php' );
373 - } elseif ( $is_expired ) {
374 - // translators: %s is the discount percentage.
375 - $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'insert-php' ), '50%' );
376 - $message = __( 'Your Woody Pro features are still here, just locked. Renew at a reduced rate this week.', 'insert-php' );
377 - $cta_label = __( 'Reactivate now', 'insert-php' );
378 - } else {
379 - // translators: %s - discount.
380 - $config['title'] = sprintf( __( 'Woody Pro: %s off this week', 'insert-php' ), '60%' );
381 - // translators: %s is the discount percentage.
382 - $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'insert-php' ), '60%' );
383 - }
384 -
385 - $url_params = [
386 - 'utm_term' => $is_pro ? 'plan-' . $plan : 'free',
387 - 'lkey' => ! empty( $license ) ? $license : false,
388 - 'expired' => $is_expired ? '1' : false,
389 - ];
390 -
391 - if ( ( $is_pro || $is_expired ) && ! empty( $pro_product_slug ) ) {
392 - $config['plugin_meta_targets'] = [ $pro_product_slug ];
393 - }
394 -
395 - $config['cta_label'] = $cta_label;
396 - $config['message'] = $message;
397 -
398 - $config['sale_url'] = add_query_arg(
399 - $url_params,
400 - tsdk_translate_link( tsdk_utmify( 'https://themeisle.link/woody-bf', 'bfcm', 'woody' ) )
401 - );
402 -
403 - $configs[ WINP_PLUGIN_SLUG ] = $config;
404 -
405 - return $configs;
406 - }
407 297 }
408 298 }