PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.9
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.9
2.7.9 2.7.8 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 All 30 releases
← All changes | insert_php.php +347 -175 2.2.4 → 2.7.9 View file →
@@ -1,175 +1,347 @@
1 -<?php
2 -/**
3 - * Plugin Name: Woody ad snippets (PHP snippets | Insert PHP)
4 - * Plugin URI: http://woody-ad-snippets.webcraftic.com/
5 - * Description: Executes PHP code, uses conditional logic to insert ads, text, media content and external service’s code. Ensures no content duplication.
6 - * Author: Will Bontrager Software, LLC <[email protected]>, Webcraftic <[email protected]>
7 - * Version: 2.2.4
8 - * Text Domain: insert-php
9 - * Domain Path: /languages/
10 - * Author URI: http://webcraftic.com
11 - */
12 -
13 -// Exit if accessed directly
14 -if ( ! defined( 'ABSPATH' ) ) {
15 - exit;
16 -}
17 -
18 -// @formatter:off
19 -
20 -
21 -/**
22 - * -----------------------------------------------------------------------------
23 - * CHECK REQUIREMENTS
24 - * Check compatibility with php and wp version of the user's site. As well as checking
25 - * compatibility with other plugins from Webcraftic.
26 - * -----------------------------------------------------------------------------
27 - */
28 -
29 -require_once( dirname( __FILE__ ) . '/libs/factory/core/includes/class-factory-requirements.php' );
30 -
31 -$plugin_info = array(
32 - 'prefix' => 'wbcr_inp_',
33 - 'plugin_name' => 'wbcr_insert_php',
34 - 'plugin_title' => __( 'Woody ad snippets', 'insert-php' ),
35 - 'plugin_text_domain' => 'insert-php',
36 -
37 - // PLUGIN SUPPORT
38 - 'support_details' => array(
39 - 'url' => 'https://r.freemius.com/3465/1916966/http://woody-ad-snippets.webcraftic.com',
40 - 'pages_map' => array(
41 - 'features' => 'premium-features', // {site}/premium-features
42 - 'pricing' => 'pricing', // {site}/prices
43 - 'support' => 'support', // {site}/support
44 - 'docs' => 'docs', // {site}/docs
45 - ),
46 - ),
47 -
48 - // PLUGIN UPDATED SETTINGS
49 - /*'has_updates' => false,
50 - 'updates_settings' => array(
51 - 'repository' => 'wordpress',
52 - 'slug' => 'woody-ad-snippets',
53 - 'maybe_rollback' => true,
54 - 'rollback_settings' => array(
55 - 'prev_stable_version' => '0.0.0',
56 - ),
57 - ),*/
58 -
59 - // PLUGIN PREMIUM SETTINGS
60 - 'has_premium' => true,
61 - 'license_settings' => array(
62 - 'provider' => 'freemius',
63 - 'slug' => 'woody-ad-snippets',
64 - 'plugin_id' => '3465',
65 - 'public_key' => 'pk_fc5703fe4f4fbc3e87f17fce5e0b8',
66 - 'price' => 19,
67 - 'has_updates' => true,
68 - 'updates_settings' => array(
69 - 'maybe_rollback' => true,
70 - 'rollback_settings' => array(
71 - 'prev_stable_version' => '0.0.0',
72 - ),
73 - ),
74 - ),
75 -
76 - // FRAMEWORK MODULES
77 - 'load_factory_modules' => array(
78 - array( 'libs/factory/bootstrap', 'factory_bootstrap_413', 'admin' ),
79 - array( 'libs/factory/forms', 'factory_forms_413', 'admin' ),
80 - array( 'libs/factory/pages', 'factory_pages_413', 'admin' ),
81 - array( 'libs/factory/types', 'factory_types_406' ),
82 - array( 'libs/factory/taxonomies', 'factory_taxonomies_326' ),
83 - array( 'libs/factory/metaboxes', 'factory_metaboxes_405', 'admin' ),
84 - array( 'libs/factory/viewtables', 'factory_viewtables_406', 'admin' ),
85 - array( 'libs/factory/shortcodes', 'factory_shortcodes_325', 'all' ),
86 - array( 'libs/factory/freemius', 'factory_freemius_102', 'all' ),
87 - ),
88 -);
89 -
90 -/**
91 - * Checks compatibility with WordPress, php and other plugins.
92 - */
93 -$wbcr_compatibility = new Wbcr_Factory413_Requirements( __FILE__, array_merge( $plugin_info, array(
94 - 'plugin_already_activate' => defined( 'WINP_PLUGIN_ACTIVE' ),
95 - 'required_php_version' => '5.4',
96 - 'required_wp_version' => '4.2.0',
97 -) ) );
98 -
99 -/**
100 - * If the plugin is compatible, it will continue its work, otherwise it will be stopped and the user will receive a warning.
101 - */
102 -if ( ! $wbcr_compatibility->check() ) {
103 - return;
104 -}
105 -
106 -global $wbcr_inp_safe_mode;
107 -
108 -$wbcr_inp_safe_mode = false;
109 -
110 -// Set the constant that the plugin is activated
111 -define( 'WINP_PLUGIN_ACTIVE', true );
112 -
113 -define( 'WINP_PLUGIN_VERSION', $wbcr_compatibility->get_plugin_version() );
114 -
115 -// Root directory of the plugin
116 -define( 'WINP_PLUGIN_DIR', dirname( __FILE__ ) );
117 -
118 -// Absolute url of the root directory of the plugin
119 -define( 'WINP_PLUGIN_URL', plugins_url( null, __FILE__ ) );
120 -
121 -// Relative url of the plugin
122 -define( 'WINP_PLUGIN_BASE', plugin_basename( __FILE__ ) );
123 -
124 -// The type of posts used for snippets types
125 -define( 'WINP_SNIPPETS_POST_TYPE', 'wbcr-snippets' );
126 -
127 -// The taxonomy used for snippets types
128 -define( 'WINP_SNIPPETS_TAXONOMY', 'wbcr-snippet-tags' );
129 -
130 -// The snippets types
131 -define( 'WINP_SNIPPET_TYPE_PHP', 'php' );
132 -define( 'WINP_SNIPPET_TYPE_TEXT', 'text' );
133 -define( 'WINP_SNIPPET_TYPE_UNIVERSAL', 'universal' );
134 -define( 'WINP_SNIPPET_TYPE_CSS', 'css' );
135 -define( 'WINP_SNIPPET_TYPE_JS', 'js' );
136 -define( 'WINP_SNIPPET_TYPE_HTML', 'html' );
137 -
138 -// The snippet automatic insertion locations
139 -define( 'WINP_SNIPPET_AUTO_HEADER', 'header' );
140 -define( 'WINP_SNIPPET_AUTO_FOOTER', 'footer' );
141 -define( 'WINP_SNIPPET_AUTO_BEFORE_POST', 'before_post' );
142 -define( 'WINP_SNIPPET_AUTO_BEFORE_CONTENT', 'before_content' );
143 -define( 'WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH', 'before_paragraph' );
144 -define( 'WINP_SNIPPET_AUTO_AFTER_PARAGRAPH', 'after_paragraph' );
145 -define( 'WINP_SNIPPET_AUTO_AFTER_CONTENT', 'after_content' );
146 -define( 'WINP_SNIPPET_AUTO_AFTER_POST', 'after_post' );
147 -define( 'WINP_SNIPPET_AUTO_BEFORE_EXCERPT', 'before_excerpt' );
148 -define( 'WINP_SNIPPET_AUTO_AFTER_EXCERPT', 'after_excerpt' );
149 -define( 'WINP_SNIPPET_AUTO_BETWEEN_POSTS', 'between_posts' );
150 -define( 'WINP_SNIPPET_AUTO_BEFORE_POSTS', 'before_posts' );
151 -define( 'WINP_SNIPPET_AUTO_AFTER_POSTS', 'after_posts' );
152 -
153 -require_once( WINP_PLUGIN_DIR . '/libs/factory/core/boot.php' );
154 -require_once( WINP_PLUGIN_DIR . '/includes/compat.php' );
155 -require_once( WINP_PLUGIN_DIR . '/includes/class.helpers.php' );
156 -require_once( WINP_PLUGIN_DIR . '/includes/class.plugin.php' );
157 -
158 -try {
159 - new WINP_Plugin( __FILE__, array_merge( $plugin_info, array(
160 - 'plugin_version' => WINP_PLUGIN_VERSION,
161 - 'plugin_text_domain' => $wbcr_compatibility->get_text_domain(),
162 - ) ) );
163 -} catch ( Exception $exception ) {
164 - // Plugin wasn't initialized due to an error
165 - define( 'WINP_PLUGIN_THROW_ERROR', true );
166 -
167 - $wbcr_plugin_error_func = function () use ( $exception ) {
168 - $error = sprintf( "The %s plugin has stopped. <b>Error:</b> %s Code: %s", 'Woody Ad Snippets', $exception->getMessage(), $exception->getCode() );
169 - echo '<div class="notice notice-error"><p>' . $error . '</p></div>';
170 - };
171 -
172 - add_action( 'admin_notices', $wbcr_plugin_error_func );
173 - add_action( 'network_admin_notices', $wbcr_plugin_error_func );
174 -}
175 -// @formatter:on
1 +<?php
2 +/**
3 + * Plugin Name: Woody Code Snippets
4 + * Plugin URI: https://woodysnippet.com/
5 + * Description: Executes PHP code, uses conditional logic to insert ads, text, media content and external service's code. Ensures no content duplication.
6 + * Author: Themeisle
7 + * Version: 2.7.9
8 + * WordPress Available: yes
9 + * Requires License: no
10 + * Text Domain: insert-php
11 + * Domain Path: /languages/
12 + * Author URI: https://themeisle.com
13 + *
14 + * @package Woody_Code_Snippets
15 + */
16 +
17 +// Exit if accessed directly.
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit;
20 +}
21 +
22 +if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
23 + add_action(
24 + 'admin_notices',
25 + function () {
26 + ?>
27 + <div class="notice notice-error">
28 + <p><?php esc_html_e( 'Woody Code Snippets requires PHP 7.4 or higher. Please upgrade your PHP version.', 'insert-php' ); ?></p>
29 + </div>
30 + <?php
31 + }
32 + );
33 +
34 + return;
35 +}
36 +
37 +global $wbcr_inp_safe_mode;
38 +
39 +$wbcr_inp_safe_mode = false;
40 +
41 +// Set the constant that the plugin is activated.
42 +define( 'WINP_PLUGIN_ACTIVE', true );
43 +
44 +define( 'WINP_PLUGIN_VERSION', '2.7.9' );
45 +
46 +// Root directory of the plugin.
47 +define( 'WINP_PLUGIN_DIR', __DIR__ );
48 +
49 +define( 'WINP_PLUGIN_FILE', __FILE__ );
50 +
51 +// Absolute url of the root directory of the plugin.
52 +define( 'WINP_PLUGIN_URL', plugins_url( '', __FILE__ ) );
53 +
54 +// Relative url of the plugin.
55 +define( 'WINP_PLUGIN_BASE', plugin_basename( __FILE__ ) );
56 +
57 +// Plugin slug.
58 +define( 'WINP_PLUGIN_SLUG', basename( dirname( WINP_PLUGIN_FILE ) ) );
59 +
60 +define( 'WINP_PLUGIN_NAMESPACE', str_replace( '-', '_', strtolower( trim( WINP_PLUGIN_SLUG ) ) ) );
61 +
62 +// The type of posts used for snippets types.
63 +define( 'WINP_SNIPPETS_POST_TYPE', 'wbcr-snippets' );
64 +
65 +// The taxonomy used for snippets types.
66 +define( 'WINP_SNIPPETS_TAXONOMY', 'wbcr-snippet-tags' );
67 +
68 +// The snippets types.
69 +define( 'WINP_SNIPPET_TYPE_PHP', 'php' );
70 +define( 'WINP_SNIPPET_TYPE_TEXT', 'text' );
71 +define( 'WINP_SNIPPET_TYPE_UNIVERSAL', 'universal' );
72 +define( 'WINP_SNIPPET_TYPE_CSS', 'css' );
73 +define( 'WINP_SNIPPET_TYPE_JS', 'js' );
74 +define( 'WINP_SNIPPET_TYPE_HTML', 'html' );
75 +define( 'WINP_SNIPPET_TYPE_AD', 'advert' );
76 +
77 +// We need to update these.
78 +define( 'WINP_UPGRADE', 'https://woodysnippet.com/upgrade' );
79 +define( 'WINP_DOCS', 'https://docs.themeisle.com/category/2429-woody-installation-and-setup' );
80 +define( 'WINP_ORG_SUPPORT', 'https://wordpress.org/support/plugin/insert-php/' );
81 +define( 'WINP_SUPPORT', 'https://themeisle.com/contact/' );
82 +
83 +// Load text domain for translations.
84 +add_action(
85 + 'plugins_loaded',
86 + function () {
87 + load_plugin_textdomain( 'insert-php', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
88 + }
89 +);
90 +
91 +// START: Related to premium version compatibility check for below 1.3.
92 +/**
93 + * Deactivates Premium versions below 1.3.0, which are not compatible with this version.
94 + */
95 +function winp_deactivate_incompatible_premium(): void {
96 + $premium_plugin_file = 'woody-ad-snippets-premium/woody-ad-snippets-premium.php';
97 + $premium_plugin_path = WP_PLUGIN_DIR . '/' . $premium_plugin_file;
98 +
99 + if ( ! file_exists( $premium_plugin_path ) ) {
100 + return;
101 + }
102 +
103 + if ( ! function_exists( 'is_plugin_active' ) ) {
104 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
105 + }
106 +
107 + if ( ! is_plugin_active( $premium_plugin_file ) ) {
108 + return;
109 + }
110 +
111 + if ( ! function_exists( 'get_plugin_data' ) ) {
112 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
113 + }
114 + $premium_data = get_plugin_data( $premium_plugin_path );
115 +
116 + if ( version_compare( $premium_data['Version'], '1.3.0', '<' ) ) {
117 + deactivate_plugins( $premium_plugin_file );
118 + // Still hooked this request; it calls WINP_Plugin::app() before init.
119 + remove_action( 'plugins_loaded', 'wasp_premium_load', 20 );
120 + set_transient( 'winp_premium_version_incompatible', true, WEEK_IN_SECONDS );
121 + }
122 +}
123 +add_action( 'plugins_loaded', 'winp_deactivate_incompatible_premium', 5 );
124 +
125 +add_action(
126 + 'admin_init',
127 + function () {
128 + if ( isset( $_GET['winp_dismiss_premium_notice'] ) && check_admin_referer( 'winp_dismiss_premium_notice' ) ) {
129 + delete_transient( 'winp_premium_version_incompatible' );
130 + wp_safe_redirect( remove_query_arg( 'winp_dismiss_premium_notice' ) );
131 + exit;
132 + }
133 + }
134 +);
135 +
136 +add_action(
137 + 'admin_notices',
138 + function () {
139 + if ( get_transient( 'winp_premium_version_incompatible' ) ) {
140 + $dismiss_url = wp_nonce_url(
141 + add_query_arg( 'winp_dismiss_premium_notice', '1' ),
142 + 'winp_dismiss_premium_notice'
143 + );
144 + ?>
145 + <div class="notice notice-error">
146 + <p>
147 + <strong><?php esc_html_e( 'Woody Code Snippets Premium has been deactivated.', 'insert-php' ); ?></strong>
148 + </p>
149 + <p>
150 + <?php
151 + printf(
152 + // translators: %s Premium version number.
153 + esc_html__( 'The installed premium version is not compatible with the current version of Woody Code Snippets. Please update the premium plugin to version %s or higher.', 'insert-php' ),
154 + '<strong>1.3.0</strong>'
155 + );
156 + ?>
157 + </p>
158 + <p>
159 + <a href="<?php echo esc_url( $dismiss_url ); ?>" class="button button-secondary">
160 + <?php esc_html_e( 'Dismiss this notice', 'insert-php' ); ?>
161 + </a>
162 + </p>
163 + </div>
164 + <?php
165 + }
166 + }
167 +);
168 +// END: Related to premium version compatibility check for below 1.3.
169 +
170 +require_once WINP_PLUGIN_DIR . '/includes/class.insertion.locations.php';
171 +require_once WINP_PLUGIN_DIR . '/includes/class.http.php';
172 +require_once WINP_PLUGIN_DIR . '/includes/class.helpers.php';
173 +require_once WINP_PLUGIN_DIR . '/includes/class.code-validator.php';
174 +require_once WINP_PLUGIN_DIR . '/includes/class.error-handler.php';
175 +require_once WINP_PLUGIN_DIR . '/includes/class.plugin.php';
176 +
177 +if ( file_exists( WINP_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
178 + require_once WINP_PLUGIN_DIR . '/vendor/autoload.php';
179 +}
180 +
181 +/**
182 + * Adds a hint and button to the fatal error message.
183 + *
184 + * Since WordPress 5.2, we have access to a special mode for catching PHP errors.
185 + * If a user makes a syntax error while editing a snippet, instead of a white screen
186 + * (if PHP errors are disabled on the server), they will see a message from WordPress
187 + * generated by the WP_Fatal_Error_Handler class.
188 + *
189 + * We decided to add a button to this message to switch to safe mode.
190 + */
191 +add_filter(
192 + 'wp_php_error_message',
193 + function ( $message ) {
194 + $safe_mode_url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&wbcr-php-snippets-safe-mode' );
195 + $safe_mode_button = '<div style="margin:20px 0;padding:20px; background:#ffe8e8;">' . __( 'If you see this message after saving the snippet to the Woody Code Snippets plugin, please enable safe mode in the Woody plugin. Safe mode will allow you to continue working in the admin panel of your site and change the snippet in which you made a php error.', 'insert-php' ) . '</div>';
196 + $safe_mode_button .= '<a href="' . $safe_mode_url . '" class="button">' . __( 'Enable Safe Mode', 'insert-php' ) . '</a>';
197 +
198 + return $message . $safe_mode_button;
199 + }
200 +);
201 +
202 +/**
203 + * Enables/Disable safe mode, in which the php code will not be executed.
204 + */
205 +add_action(
206 + 'plugins_loaded',
207 + function () {
208 + if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) {
209 + WINP_Helper::enable_safe_mode();
210 + wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) ) );
211 + die();
212 + }
213 +
214 + if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) {
215 + WINP_Helper::disable_safe_mode();
216 + wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) ) );
217 + die();
218 + }
219 + },
220 + - 1
221 +);
222 +
223 +/**
224 + * Register product to SDK
225 + *
226 + * @param array<string> $products Registered products.
227 + * @return array<string>
228 + */
229 +function winp_sdk_register_products( $products ) {
230 + $products[] = WINP_PLUGIN_FILE;
231 +
232 + return $products;
233 +}
234 +
235 +/**
236 + * About page metadata
237 + *
238 + * @return array<string, mixed>
239 + */
240 +function winp_sdk_about_page() {
241 + return [
242 + 'location' => 'edit.php?post_type=wbcr-snippets',
243 + 'logo' => WINP_PLUGIN_URL . '/admin/assets/img/icon-256x256.png',
244 + 'review_link' => false,
245 + 'has_upgrade_menu' => false,
246 + ];
247 +}
248 +
249 +/**
250 + * AI Connect metadata.
251 + *
252 + * Only the read abilities are listed: the abilities that save or activate
253 + * snippets run code, so the site owner switches those on deliberately.
254 + *
255 + * @return array<string, mixed>
256 + */
257 +function winp_sdk_ai_connect() {
258 + return [
259 + 'name' => 'Woody Code Snippets',
260 + 'notice_cases' => [
261 + __( 'find where a script is inserted', 'insert-php' ),
262 + __( 'review the code of a snippet', 'insert-php' ),
263 + __( 'audit your active snippets', 'insert-php' ),
264 + ],
265 + 'prompts' => [
266 + __( 'Find which Woody Code Snippets load gtag and where they are inserted.', 'insert-php' ),
267 + __( 'Show me the code of my header scripts snippet and explain what it does.', 'insert-php' ),
268 + __( 'Which of my snippets run PHP on every page?', 'insert-php' ),
269 + ],
270 + 'ability_prefix' => 'woody',
271 + ];
272 +}
273 +
274 +/**
275 + * Register compatibility using SDK.
276 + *
277 + * @param array<string, array<string, string>> $compatibilities All compatibilities.
278 + *
279 + * @return array<string, array<string, string>> Registered compatibility.
280 + */
281 +function winp_sdk_register_compatibility( $compatibilities ) {
282 + $compatibilities['WoodyPro'] = [
283 + 'basefile' => defined( 'WASP_PLUGIN_FILE' ) ? WASP_PLUGIN_FILE : '',
284 + 'required' => '1.3.0',
285 + ];
286 +
287 + return $compatibilities;
288 +}
289 +
290 +add_filter( 'themeisle_sdk_products', 'winp_sdk_register_products' );
291 +add_filter( WINP_PLUGIN_NAMESPACE . '_about_us_metadata', 'winp_sdk_about_page' );
292 +add_filter( WINP_PLUGIN_NAMESPACE . '_ai_connect_metadata', 'winp_sdk_ai_connect' );
293 +add_filter( 'themeisle_sdk_compatibilities/' . basename( WINP_PLUGIN_DIR ), 'winp_sdk_register_compatibility' );
294 +
295 +// Register activation/deactivation hooks.
296 +register_activation_hook(
297 + WINP_PLUGIN_FILE,
298 + function () {
299 + global $winp_snippets_locations;
300 + if ( ! isset( $winp_snippets_locations ) ) {
301 + $winp_snippets_locations = new WINP_Insertion_Locations();
302 + }
303 +
304 + // Instantiate plugin for activation.
305 + $plugin = new WINP_Plugin();
306 + $plugin->activation_hook();
307 + }
308 +);
309 +
310 +register_deactivation_hook(
311 + WINP_PLUGIN_FILE,
312 + function () {
313 + global $winp_snippets_locations;
314 + if ( ! isset( $winp_snippets_locations ) ) {
315 + $winp_snippets_locations = new WINP_Insertion_Locations();
316 + }
317 +
318 + // Instantiate plugin for deactivation.
319 + $plugin = new WINP_Plugin();
320 + $plugin->deactivation_hook();
321 + }
322 +);
323 +
324 +// Initialize on 'init' hook with priority 0 to avoid early translation loading (WP 6.7+)
325 +add_action(
326 + 'init',
327 + function () {
328 + global $winp_snippets_locations;
329 + $winp_snippets_locations = new WINP_Insertion_Locations();
330 +
331 + try {
332 + new WINP_Plugin();
333 + } catch ( Exception $exception ) {
334 + // Plugin wasn't initialized due to an error
335 + define( 'WINP_PLUGIN_THROW_ERROR', true );
336 +
337 + $wbcr_plugin_error_func = function () use ( $exception ) {
338 + $error = sprintf( 'The %s plugin has stopped. <b>Error:</b> %s Code: %s', 'Woody Ad Snippets', $exception->getMessage(), $exception->getCode() );
339 + echo '<div class="notice notice-error"><p>' . $error . '</p></div>';
340 + };
341 +
342 + add_action( 'admin_notices', $wbcr_plugin_error_func );
343 + add_action( 'network_admin_notices', $wbcr_plugin_error_func );
344 + }
345 + },
346 + 0
347 +);