PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.6.0
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.6.0
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
insert-php / includes / class.plugin.php

class.plugin.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.6.0, at includes/class.plugin.php

299 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PHP snippets plugin base
4 *
5 * @author Webcraftic <WordPress.webraftic@gmail.com>
6 * @copyright (c) 19.02.2018, Webcraftic
7 * @version 1.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 if ( ! class_exists( 'WINP_Plugin' ) ) {
16
17 class WINP_Plugin extends Wbcr_Factory475_Plugin {
18
19 /**
20 * @var Wbcr_Factory475_Plugin
21 */
22 private static $app;
23
24 /**
25 * @param string $plugin_path
26 * @param array $data
27 *
28 * @throws Exception
29 */
30 public function __construct( $plugin_path, $data ) {
31 parent::__construct( $plugin_path, $data );
32
33 self::$app = $this;
34
35 $this->load_global();
36
37 if ( is_admin() ) {
38 $this->initActivation();
39
40 if ( WINP_Helper::doing_ajax() ) {
41 require WINP_PLUGIN_DIR . '/admin/ajax/ajax.php';
42 require WINP_PLUGIN_DIR . '/admin/ajax/check-license.php';
43 require WINP_PLUGIN_DIR . '/admin/ajax/snippet-library.php';
44 }
45
46 $this->load_backend();
47 }
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' ] );
55 }
56
57 /**
58 * Hide SDK promo notice for pro uses.
59 *
60 * @access public
61 */
62 public static function sdk_hide_promo_notice( $should_show ) {
63 return WINP_Plugin::app()->premium->is_active();
64 }
65 /**
66 * Register product into SDK.
67 *
68 * @param array $products All products.
69 *
70 * @return array Registered product.
71 */
72 public static function register_sdk( $products ) {
73 $products[] = WINP_PLUGIN_FILE;
74
75 return $products;
76 }
77 /**
78 * @return WINP_Plugin
79 */
80 public static function app() {
81 return self::$app;
82 }
83
84 /**
85 * @return bool
86 */
87 public function currentUserCan() {
88 return current_user_can( 'manage_options' );
89 }
90
91 /**
92 * Get Execute_Snippet object
93 *
94 * @return WINP_Execute_Snippet
95 */
96 public function getExecuteObject() {
97 require_once WINP_PLUGIN_DIR . '/includes/class.execute.snippet.php';
98
99 return new WINP_Execute_Snippet();
100 }
101
102 /**
103 * Get WINP_Api object
104 *
105 * @return WINP_Api
106 */
107 public function get_api_object() {
108 require_once WINP_PLUGIN_DIR . '/admin/includes/class.api.php';
109
110 return new WINP_Api();
111 }
112
113 /**
114 * Get WINP_Common_Snippet object
115 *
116 * @return WINP_Common_Snippet
117 */
118 public function get_common_object() {
119 require_once WINP_PLUGIN_DIR . '/admin/includes/class.common.snippet.php';
120
121 return new WINP_Common_Snippet();
122 }
123
124 /**
125 * @throws \Exception
126 * @since 2.2.0
127 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
128 */
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' );
137 }
138
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' );
152 }
153
154 /**
155 * @throws \Exception
156 * @since 2.2.0
157 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
158 */
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 private function register_types() {
173 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php';
174 Wbcr_FactoryTypes415::register( 'WINP_SnippetsType', $this );
175
176 require_once WINP_PLUGIN_DIR . '/admin/types/snippets-taxonomy.php';
177 Wbcr_FactoryTaxonomies335::register( 'WINP_SnippetsTaxonomy', $this );
178 }
179
180 /**
181 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
182 * @since 2.2.0
183 */
184 private function register_shortcodes() {
185 $action = self::app()->request->get( 'action', '' );
186 if ( ! ( 'edit' == $action && is_admin() ) ) {
187 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcodes.php';
188 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-php.php';
189 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-text.php';
190 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-universal.php';
191 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-css.php';
192 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-js.php';
193 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-html.php';
194 require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-ad.php';
195
196 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodePhp', $this );
197 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeText', $this );
198 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeUniversal', $this );
199 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeCss', $this );
200 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeJs', $this );
201 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeHtml', $this );
202 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeAdvert', $this );
203 }
204 }
205
206 /**
207 * Initialization and require files for backend and frontend.
208 *
209 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
210 * @since 2.2.0
211 */
212 private function load_global() {
213 require_once WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php';
214
215 new WINP_Gutenberg_Snippet();
216
217 $this->getExecuteObject()->registerHooks();
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 );
236 }
237
238 /**
239 * Initialization and require files for backend.
240 *
241 * @throws \Exception
242 * @since 2.2.0
243 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
244 */
245 private function load_backend() {
246 require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php';
247 require_once WINP_PLUGIN_DIR . '/admin/includes/class.filter.snippet.php';
248 require_once WINP_PLUGIN_DIR . '/admin/includes/class.actions.snippet.php';
249 require_once WINP_PLUGIN_DIR . '/admin/includes/class.import.snippet.php';
250 require_once WINP_PLUGIN_DIR . '/admin/includes/class.notices.php';
251 require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php';
252 require_once WINP_PLUGIN_DIR . '/admin/metaboxes/metabox.php';
253 require_once WINP_PLUGIN_DIR . '/admin/boot.php';
254
255 $this->get_common_object()->registerHooks();
256
257 $this->register_types();
258
259 new WINP_Filter_List();
260 new WINP_Export_Snippet();
261 new WINP_Import_Snippet();
262 new WINP_WarningNotices();
263
264 # Required for i18n to be loaded properly
265 add_action( 'plugins_loaded', [ $this, 'register_pages' ] );
266
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 } );
281 }
282
283 /**
284 * Метод проверяет активацию премиум плагина и наличие действующего лицензионного ключа
285 *
286 * @return bool
287 */
288 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;
294 }
295 }
296
297 }
298 }
299