PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.2.7
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.2.7
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 +167 -74 2.1.912.2.7 View file →
@@ -1,10 +1,11 @@
1 1 <?php
2 2 /**
3 3 * PHP snippets plugin base
4 - * @author Webcraftic <wordpress.webraftic@gmail.com>
4 + *
5 + * @author Webcraftic <wordpress.webraftic@gmail.com>
5 6 * @copyright (c) 19.02.2018, Webcraftic
6 - * @version 1.0
7 + * @version 1.0
7 8 */
8 9
9 10 // Exit if accessed directly
10 11 if ( ! defined( 'ABSPATH' ) ) {
@@ -11,42 +12,42 @@
11 12 exit;
12 13 }
13 14
14 15 if ( ! class_exists( 'WINP_Plugin' ) ) {
15 -
16 - class WINP_Plugin extends Wbcr_Factory410_Plugin {
17 -
16 +
17 + class WINP_Plugin extends Wbcr_Factory419_Plugin {
18 +
18 19 /**
19 - * @var Wbcr_Factory410_Plugin
20 + * @var Wbcr_Factory419_Plugin
20 21 */
21 22 private static $app;
22 -
23 +
23 24 /**
24 25 * @param string $plugin_path
25 - * @param array $data
26 + * @param array $data
26 27 *
27 28 * @throws Exception
28 29 */
29 30 public function __construct( $plugin_path, $data ) {
30 31 parent::__construct( $plugin_path, $data );
31 -
32 +
32 33 self::$app = $this;
33 -
34 - self::app()->setTextDomain( 'insert-php', WINP_PLUGIN_DIR );
35 - $this->setModules();
36 -
37 - $this->globalScripts();
38 -
34 +
35 + $this->load_global();
36 +
39 37 if ( is_admin() ) {
40 38 $this->initActivation();
41 - $this->adminScripts();
42 -
43 - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
39 +
40 + if ( WINP_Helper::doing_ajax() ) {
44 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' );
45 44 }
45 +
46 + $this->load_backend();
46 47 }
47 48 }
48 -
49 +
49 50 /**
50 51 * @return WINP_Plugin
51 52 */
52 53 public static function app() {
@@ -51,9 +52,9 @@
51 52 */
52 53 public static function app() {
53 54 return self::$app;
54 55 }
55 -
56 +
56 57 /**
57 58 * @return bool
58 59 */
59 60 public function currentUserCan() {
@@ -58,10 +59,9 @@
58 59 */
59 60 public function currentUserCan() {
60 61 return current_user_can( 'manage_options' );
61 62 }
62 -
63 -
63 +
64 64 /**
65 65 * Get Execute_Snippet object
66 66 *
67 67 * @return WINP_Execute_Snippet
@@ -67,92 +67,185 @@
67 67 * @return WINP_Execute_Snippet
68 68 */
69 69 public function getExecuteObject() {
70 70 require_once( WINP_PLUGIN_DIR . '/includes/class.execute.snippet.php' );
71 -
71 +
72 72 return new WINP_Execute_Snippet();
73 73 }
74 -
75 - protected function setModules() {
76 - $this->load( array(
77 - array( 'libs/factory/bootstrap', 'factory_bootstrap_410', 'admin' ),
78 - array( 'libs/factory/forms', 'factory_forms_411', 'admin' ),
79 - array( 'libs/factory/pages', 'factory_pages_411', 'admin' ),
80 - array( 'libs/factory/types', 'factory_types_405' ),
81 - array( 'libs/factory/taxonomies', 'factory_taxonomies_325' ),
82 - array( 'libs/factory/metaboxes', 'factory_metaboxes_404', 'admin' ),
83 - array( 'libs/factory/viewtables', 'factory_viewtables_405', 'admin' ),
84 - array( 'libs/factory/shortcodes', 'factory_shortcodes_325', 'all' ),
85 - array( 'libs/factory/notices', 'factory_notices_408', 'admin' )
86 - ) );
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();
87 84 }
88 -
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 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
99 + * @since 2.2.0
100 + * @throws \Exception
101 + */
102 + /*public function plugins_loaded() {
103 + $this->register_pages();
104 + }*/
105 +
89 106 protected function initActivation() {
90 107 include_once( WINP_PLUGIN_DIR . '/admin/activation.php' );
91 108 $this->registerActivation( 'WINP_Activation' );
92 109 }
93 -
94 - private function registerPages() {
110 +
111 + /**
112 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
113 + * @since 2.2.0
114 + * @throws \Exception
115 + */
116 + public function register_pages() {
117 + require_once( WINP_PLUGIN_DIR . '/admin/pages/page.php' );
118 +
95 119 $this->registerPage( 'WINP_NewItemPage', WINP_PLUGIN_DIR . '/admin/pages/new-item.php' );
96 - $this->registerPage( 'WINP_ImportPage', WINP_PLUGIN_DIR . '/admin/pages/import.php' );
97 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' );
98 123 $this->registerPage( 'WINP_AboutPage', WINP_PLUGIN_DIR . '/admin/pages/about.php' );
99 124 }
100 -
101 - private function registerTypes() {
102 - $this->registerType( 'WSC_TasksItemType', WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php' );
103 -
125 +
126 + /**
127 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
128 + * @since 2.2.0
129 + * @throws \Exception
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 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
141 + * @since 2.2.0
142 + * @throws \Exception
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 +
104 148 require_once( WINP_PLUGIN_DIR . '/admin/types/snippets-taxonomy.php' );
105 - Wbcr_FactoryTaxonomies325::register( 'WINP_SnippetsTaxonomy', $this );
149 + Wbcr_FactoryTaxonomies330::register( 'WINP_SnippetsTaxonomy', $this );
106 150 }
107 -
151 +
152 + /**
153 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
154 + * @since 2.2.0
155 + */
108 156 private function register_shortcodes() {
109 157 $is_cron = WINP_Helper::doing_cron();
110 158 $is_rest = WINP_Helper::doing_rest_api();
111 -
112 - if ( ! ( isset( $_GET['action'] ) && $_GET['action'] == 'edit' && is_admin() ) && ! $is_cron && ! $is_rest ) {
159 +
160 + $action = WINP_Plugin::app()->request->get( 'action', '' );
161 + if ( ! ( 'edit' == $action && is_admin() ) && ! $is_cron && ! $is_rest ) {
162 + if ( WINP_Plugin::app()->getOption( 'support_old_shortcodes' ) ) {
163 + // todo: Deprecated
164 + require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-insert-php.php' );
165 + }
166 +
113 167 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcodes.php' );
114 168 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-php.php' );
115 169 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-text.php' );
116 170 require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-universal.php' );
117 -
118 - Wbcr_FactoryShortcodes325::register( 'WINP_SnippetShortcodePhp', $this );
119 - Wbcr_FactoryShortcodes325::register( 'WINP_SnippetShortcodeText', $this );
120 - Wbcr_FactoryShortcodes325::register( 'WINP_SnippetShortcodeUniversal', $this );
171 + require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-css.php' );
172 + require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-js.php' );
173 + require_once( WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-html.php' );
174 +
175 + WINP_Helper::register_shortcode( 'WINP_SnippetShortcodePhp', $this );
176 + WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeText', $this );
177 + WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeUniversal', $this );
178 + WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeCss', $this );
179 + WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeJs', $this );
180 + WINP_Helper::register_shortcode( 'WINP_SnippetShortcodeHtml', $this );
121 181 }
122 182 }
123 -
124 -
125 - private function globalScripts() {
126 - $this->registerGutenberg();
183 +
184 + /**
185 + * Initialization and require files for backend and frontend.
186 + *
187 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
188 + * @since 2.2.0
189 + */
190 + private function load_global() {
191 + require_once( WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php' );
192 + new WINP_Gutenberg_Snippet();
193 +
127 194 $this->getExecuteObject()->registerHooks();
128 195 $this->register_shortcodes();
129 -
130 - require_once( WINP_PLUGIN_DIR . '/admin/boot.php' );
196 +
197 + /**
198 + * Enables/Disable safe mode, in which the php code will not be executed.
199 + */
200 + add_action( 'plugins_loaded', function () {
201 + if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) {
202 + WINP_Helper::enable_safe_mode();
203 + wp_safe_redirect( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) );
204 + die();
205 + }
206 +
207 + if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) {
208 + WINP_Helper::disable_safe_mode();
209 + wp_safe_redirect( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) );
210 + die();
211 + }
212 + }, - 1 );
131 213 }
132 -
133 - private function adminScripts() {
214 +
215 + /**
216 + * Initialization and require files for backend.
217 + *
218 + * @author Alexander Kovalev <alex.kovalevv@gmail.com>
219 + * @since 2.2.0
220 + * @throws \Exception
221 + */
222 + private function load_backend() {
134 223 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php' );
135 224 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.filter.snippet.php' );
136 - require_once( WINP_PLUGIN_DIR . '/admin/includes/class.export.snippet.php' );
225 + require_once( WINP_PLUGIN_DIR . '/admin/includes/class.actions.snippet.php' );
137 226 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.import.snippet.php' );
138 227 require_once( WINP_PLUGIN_DIR . '/admin/includes/class.notices.php' );
139 -
140 - $this->registerTypes();
141 - $this->registerPages();
142 -
228 + require_once( WINP_PLUGIN_DIR . '/admin/includes/class.request.php' );
229 + require_once( WINP_PLUGIN_DIR . '/admin/includes/class.dashboard.widget.php' );
230 + require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/metabox.php' );
231 + require_once( WINP_PLUGIN_DIR . '/admin/boot.php' );
232 +
233 + $this->get_common_object()->registerHooks();
234 +
235 + $this->register_types();
236 +
143 237 new WINP_Filter_List();
144 238 new WINP_Export_Snippet();
145 239 new WINP_Import_Snippet();
146 240 new WINP_WarningNotices();
147 - }
148 -
149 - /**
150 - * Register Gutenberg related scripts.
151 - */
152 - private function registerGutenberg() {
153 - require_once( WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php' );
154 -
155 - new WINP_Gutenberg_Snippet();
241 + new WINP_Dashboard_Widget();
242 +
243 + # Required for i18n to be loaded properly
244 + add_action( 'plugins_loaded', [ $this, 'register_pages' ] );
245 +
246 + # Required for compatibility with the premium plugin.
247 + # We set the priority to 30 to wait for the premium plugin to load.
248 + add_action( 'plugins_loaded', [ $this, 'register_depence_pages' ], 30 );
156 249 }
157 250 }
158 251 }