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 +178 -131 2.6.02.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,79 +11,115 @@
13 11 }
14 12
15 13 if ( ! class_exists( 'WINP_Plugin' ) ) {
16 14
17 - class WINP_Plugin extends Wbcr_Factory475_Plugin {
15 + class WINP_Plugin {
18 16
19 17 /**
20 - * @var Wbcr_Factory475_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 }
48 - add_action( 'init', function () {
49 - if(WINP_Plugin::app()->premium->is_active()){
50 - update_option( 'insert_php_logger_flag', 'yes' );
51 - }
52 - } );
53 - add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] );
54 - add_filter( 'themeisle_sdk_ran_promos', [ __CLASS__, 'sdk_hide_promo_notice' ] );
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' ] );
55 78 }
56 79
57 80 /**
58 - * Hide SDK promo notice for pro uses.
59 - *
60 - * @access public
81 + * Get plugin instance
82 + *
83 + * @return WINP_Plugin
61 84 */
62 - public static function sdk_hide_promo_notice( $should_show ) {
63 - return WINP_Plugin::app()->premium->is_active();
85 + public static function app() {
86 + return self::$app;
64 87 }
88 +
65 89 /**
66 - * Register product into SDK.
67 - *
68 - * @param array $products All products.
69 - *
70 - * @return array Registered product.
90 + * Survey data.
91 + *
92 + * @return array<string, mixed>
71 93 */
72 - public static function register_sdk( $products ) {
73 - $products[] = WINP_PLUGIN_FILE;
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;
74 99
75 - return $products;
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;
76 116 }
77 - /**
78 - * @return WINP_Plugin
79 - */
80 - public static function app() {
81 - return self::$app;
82 - }
83 117
84 118 /**
85 119 * @return bool
86 120 */
87 - public function currentUserCan() {
121 + public function current_user_car() {
88 122 return current_user_can( 'manage_options' );
89 123 }
90 124
91 125 /**
@@ -92,12 +126,12 @@
92 126 * Get Execute_Snippet object
93 127 *
94 128 * @return WINP_Execute_Snippet
95 129 */
96 - public function getExecuteObject() {
130 + public function get_execute_object() {
97 131 require_once WINP_PLUGIN_DIR . '/includes/class.execute.snippet.php';
98 132
99 - return new WINP_Execute_Snippet();
133 + return WINP_Execute_Snippet::app();
100 134 }
101 135
102 136 /**
103 137 * Get WINP_Api object
@@ -104,8 +138,9 @@
104 138 *
105 139 * @return WINP_Api
106 140 */
107 141 public function get_api_object() {
142 + require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php';
108 143 require_once WINP_PLUGIN_DIR . '/admin/includes/class.api.php';
109 144
110 145 return new WINP_Api();
111 146 }
@@ -121,69 +156,57 @@
121 156 return new WINP_Common_Snippet();
122 157 }
123 158
124 159 /**
125 - * @throws \Exception
126 - * @since 2.2.0
127 - * @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
128 164 */
129 - /*
130 - public function plugins_loaded() {
131 - $this->register_pages();
132 - }*/
133 -
134 - protected function initActivation() {
135 - include_once WINP_PLUGIN_DIR . '/admin/activation.php';
136 - $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();
137 175 }
138 176
139 177 /**
140 - * @throws \Exception
141 - * @since 2.2.0
142 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
178 + * Plugin deactivation hook.
179 + * Removes custom capabilities.
180 + *
181 + * @return void
143 182 */
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' );
183 + public function deactivation_hook() {
184 + // Remove custom capabilities from administrator role.
185 + $this->snippets_type->remove_capabilities();
152 186 }
153 187
154 188 /**
155 - * @throws \Exception
189 + * Register custom post types and taxonomies.
190 + *
191 + * @throws \Exception Exception.
156 192 * @since 2.2.0
157 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
158 193 */
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 - }
165 - }
166 -
167 - /**
168 - * @throws \Exception
169 - * @since 2.2.0
170 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
171 - */
172 194 private function register_types() {
173 195 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php';
174 - Wbcr_FactoryTypes415::register( 'WINP_SnippetsType', $this );
196 + $this->snippets_type = new WINP_SnippetsType();
175 197
176 198 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-taxonomy.php';
177 - Wbcr_FactoryTaxonomies335::register( 'WINP_SnippetsTaxonomy', $this );
199 + new WINP_SnippetsTaxonomy();
178 200 }
179 201
180 202 /**
181 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
203 + * Register shortcodes.
204 + *
182 205 * @since 2.2.0
183 206 */
184 207 private function register_shortcodes() {
185 - $action = self::app()->request->get( 'action', '' );
208 + $action = WINP_HTTP::get( 'action', '' );
186 209 if ( ! ( 'edit' == $action && is_admin() ) ) {
187 210 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcodes.php';
188 211 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-php.php';
189 212 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-text.php';
@@ -205,35 +228,19 @@
205 228
206 229 /**
207 230 * Initialization and require files for backend and frontend.
208 231 *
209 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
210 232 * @since 2.2.0
211 233 */
212 234 private function load_global() {
213 235 require_once WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php';
236 + require_once WINP_PLUGIN_DIR . '/includes/class.admin-bar.php';
214 237
215 238 new WINP_Gutenberg_Snippet();
239 + WINP_Admin_Bar::instance();
216 240
217 - $this->getExecuteObject()->registerHooks();
241 + $this->get_execute_object()->register_hooks();
218 242 $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 );
236 243 }
237 244
238 245 /**
239 246 * Initialization and require files for backend.
@@ -239,46 +246,40 @@
239 246 * Initialization and require files for backend.
240 247 *
241 248 * @throws \Exception
242 249 * @since 2.2.0
243 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
244 250 */
245 251 private function load_backend() {
246 252 require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php';
247 253 require_once WINP_PLUGIN_DIR . '/admin/includes/class.filter.snippet.php';
248 254 require_once WINP_PLUGIN_DIR . '/admin/includes/class.actions.snippet.php';
249 - require_once WINP_PLUGIN_DIR . '/admin/includes/class.import.snippet.php';
250 255 require_once WINP_PLUGIN_DIR . '/admin/includes/class.notices.php';
256 + require_once WINP_PLUGIN_DIR . '/admin/includes/class.admin.notices.php';
251 257 require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php';
252 - require_once WINP_PLUGIN_DIR . '/admin/metaboxes/metabox.php';
253 258 require_once WINP_PLUGIN_DIR . '/admin/boot.php';
254 259
255 - $this->get_common_object()->registerHooks();
256 -
260 + $this->get_common_object()->register_hooks();
257 261 $this->register_types();
258 262
259 263 new WINP_Filter_List();
260 - new WINP_Export_Snippet();
261 - new WINP_Import_Snippet();
262 - new WINP_WarningNotices();
264 + new WINP_Actions_Snippet();
265 + WINP_Notices::instance();
266 + new WINP_Admin_Notices();
263 267
264 - # Required for i18n to be loaded properly
265 - 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 + }
266 275
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 - } );
276 + return $this->get_survey_data();
277 + },
278 + 10,
279 + 2
280 + );
281 + }
281 282 }
282 283
283 284 /**
284 285 * Метод проверяет активацию премиум плагина и наличие действующего лицензионного ключа
@@ -285,14 +286,60 @@
285 286 *
286 287 * @return bool
287 288 */
288 289 public function is_premium() {
289 - if ( $this->premium->is_active() && $this->premium->is_activate() //&& $this->premium->is_install_package()
290 - ) {
291 - return true;
292 - } else {
293 - 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 + }
294 334 }
335 +
336 + return [
337 + 'settings' => $settings,
338 + 'stats' => [
339 + 'total_snippets' => $total_snippets,
340 + 'types' => $types_count,
341 + ],
342 + ];
295 343 }
296 -
297 344 }
298 345 }