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

274 lines 8.2 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_Factory453_Plugin {
18
19 /**
20 * @var Wbcr_Factory453_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 }
49
50 /**
51 * @return WINP_Plugin
52 */
53 public static function app() {
54 return self::$app;
55 }
56
57 /**
58 * @return bool
59 */
60 public function currentUserCan() {
61 return current_user_can( 'manage_options' );
62 }
63
64 /**
65 * Get Execute_Snippet object
66 *
67 * @return WINP_Execute_Snippet
68 */
69 public function getExecuteObject() {
70 require_once( WINP_PLUGIN_DIR . '/includes/class.execute.snippet.php' );
71
72 return new WINP_Execute_Snippet();
73 }
74
75 /**
76 * Get WINP_Api object
77 *
78 * @return WINP_Api
79 */
80 public function get_api_object() {
81 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.api.php' );
82
83 return new WINP_Api();
84 }
85
86 /**
87 * Get WINP_Common_Snippet object
88 *
89 * @return WINP_Common_Snippet
90 */
91 public function get_common_object() {
92 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.common.snippet.php' );
93
94 return new WINP_Common_Snippet();
95 }
96
97 /**
98 * @throws \Exception
99 * @since 2.2.0
100 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
101 */
102 /*public function plugins_loaded() {
103 $this->register_pages();
104 }*/
105
106 protected function initActivation() {
107 include_once( WINP_PLUGIN_DIR . '/admin/activation.php' );
108 $this->registerActivation( 'WINP_Activation' );
109 }
110
111 /**
112 * @throws \Exception
113 * @since 2.2.0
114 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
115 */
116 public function register_pages() {
117 require_once( WINP_PLUGIN_DIR . '/admin/pages/page.php' );
118
119 $this->registerPage( 'WINP_NewItemPage', WINP_PLUGIN_DIR . '/admin/pages/new-item.php' );
120 $this->registerPage( 'WINP_SettingsPage', WINP_PLUGIN_DIR . '/admin/pages/settings.php' );
121 $this->registerPage( 'WINP_SnippetLibraryPage', WINP_PLUGIN_DIR . '/admin/pages/snippet-library.php' );
122 $this->registerPage( 'WINP_License_Page', WINP_PLUGIN_DIR . '/admin/pages/license.php' );
123 $this->registerPage( 'WINP_AboutPage', WINP_PLUGIN_DIR . '/admin/pages/about.php' );
124 }
125
126 /**
127 * @throws \Exception
128 * @since 2.2.0
129 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
130 */
131 public function register_depence_pages() {
132 require_once( WINP_PLUGIN_DIR . '/admin/pages/page.php' );
133
134 if ( ! ( defined( 'WASP_PLUGIN_ACTIVE' ) && WASP_PLUGIN_ACTIVE ) ) {
135 $this->registerPage( 'WINP_ImportPage', WINP_PLUGIN_DIR . '/admin/pages/import.php' );
136 }
137 }
138
139 /**
140 * @throws \Exception
141 * @since 2.2.0
142 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
143 */
144 private function register_types() {
145 require_once( WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php' );
146 Wbcr_FactoryTypes410::register( 'WINP_SnippetsType', $this );
147
148 require_once( WINP_PLUGIN_DIR . '/admin/types/snippets-taxonomy.php' );
149 Wbcr_FactoryTaxonomies330::register( 'WINP_SnippetsTaxonomy', $this );
150 }
151
152 /**
153 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
154 * @since 2.2.0
155 */
156 private function register_shortcodes() {
157 $action = WINP_Plugin::app()->request->get( 'action', '' );
158 if ( ! ( 'edit' == $action && is_admin() ) ) {
159 if ( WINP_Plugin::app()->getOption( 'support_old_shortcodes' ) ) {
160 // todo: Deprecated
161 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-insert-php.php' );
162 }
163
164 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcodes.php' );
165 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-php.php' );
166 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-text.php' );
167 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-universal.php' );
168 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-css.php' );
169 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-js.php' );
170 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-html.php' );
171 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-ad.php' );
172
173 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodePhp', $this );
174 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeText', $this );
175 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeUniversal', $this );
176 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeCss', $this );
177 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeJs', $this );
178 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeHtml', $this );
179 WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeAdvert', $this );
180 }
181 }
182
183 /**
184 * Initialization and require files for backend and frontend.
185 *
186 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
187 * @since 2.2.0
188 */
189 private function load_global() {
190 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php' );
191 new WINP_Gutenberg_Snippet();
192
193 $this->getExecuteObject()->registerHooks();
194 $this->register_shortcodes();
195
196 /**
197 * Enables/Disable safe mode, in which the php code will not be executed.
198 */
199 add_action( 'plugins_loaded', function () {
200 if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) {
201 WINP_Helper::enable_safe_mode();
202 wp_safe_redirect( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) );
203 die();
204 }
205
206 if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) {
207 WINP_Helper::disable_safe_mode();
208 wp_safe_redirect( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) );
209 die();
210 }
211 }, - 1 );
212 }
213
214 /**
215 * Initialization and require files for backend.
216 *
217 * @throws \Exception
218 * @since 2.2.0
219 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
220 */
221 private function load_backend() {
222 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php' );
223 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.filter.snippet.php' );
224 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.actions.snippet.php' );
225 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.import.snippet.php' );
226 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.notices.php' );
227 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.request.php' );
228 require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/metabox.php' );
229 require_once( WINP_PLUGIN_DIR . '/admin/boot.php' );
230
231 $this->get_common_object()->registerHooks();
232
233 $this->register_types();
234
235 new WINP_Filter_List();
236 new WINP_Export_Snippet();
237 new WINP_Import_Snippet();
238 new WINP_WarningNotices();
239
240 # Required for i18n to be loaded properly
241 add_action( 'plugins_loaded', [ $this, 'register_pages' ] );
242
243 # Required for compatibility with the premium plugin.
244 # We set the priority to 30 to wait for the premium plugin to load.
245 add_action( 'plugins_loaded', [ $this, 'register_depence_pages' ], 30 );
246
247 add_action( 'wbcr_factory_forms_450_register_controls', function () {
248 $colorControls = array(
249 [
250 'type' => 'winp-dropdown',
251 'class' => 'WINP_FactoryForms_Dropdown',
252 'include' => WINP_PLUGIN_DIR . '/includes/controls/class.dropdown.php'
253 ],
254 );
255 $this->forms->registerControls( $colorControls );
256 } );
257 }
258
259 /**
260 * Метод проверяет активацию премиум плагина и наличие действующего лицензионного ключа
261 *
262 * @return bool
263 */
264 public function is_premium() {
265 if ( $this->premium->is_active() && $this->premium->is_activate() //&& $this->premium->is_install_package()
266 ) {
267 return true;
268 } else {
269 return false;
270 }
271 }
272
273 }
274 }