PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / trunk
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts vtrunk
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 | insert_php.php +319 -137 2.1.91trunk View file →
@@ -1,137 +1,319 @@
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 <will@willmaster.com>, Webcraftic <wordpress.webraftic@gmail.com>
7 - * Version: 2.1.91
8 - * Text Domain: insert-php
9 - * Domain Path: /languages/
10 - * Author URI: http://woody-ad-snippets.webcraftic.com/
11 - */
12 -
13 -// Exit if accessed directly
14 -if ( ! defined( 'ABSPATH' ) ) {
15 - exit;
16 -}
17 -
18 -
19 -
20 -require_once( dirname( __FILE__ ) . '/libs/factory/core/includes/class.requirements.php' );
21 -
22 -$wbcr_inp_plugin_info = array(
23 - 'prefix' => 'wbcr_inp_',
24 - 'plugin_name' => 'wbcr_insert_php',
25 - 'plugin_title' => __( 'Woody ad snippets', 'insert-php' ),
26 - 'plugin_build' => 'free',
27 - 'updates' => dirname( __FILE__ ) . '/migrations/'
28 -);
29 -
30 -/**
31 - * Checks compatibility with Wordpress, php and other plugins.
32 - */
33 -$wbcr_inp_plugin_requirements = new Wbcr_Factory410_Requirements( __FILE__, array_merge( $wbcr_inp_plugin_info, array(
34 - 'plugin_last_version' => '2.0.6',
35 - 'plugin_already_activate' => defined( 'WINP_PLUGIN_ACTIVE' ),
36 - 'required_php_version' => '5.2',
37 - 'required_wp_version' => '4.2.0'
38 -) ) );
39 -
40 -/**
41 - * If the plugin is compatible, it will continue its work, otherwise it will be stopped and the user will receive a warning.
42 - */
43 -if ( $wbcr_inp_plugin_requirements->check() ) {
44 - global $wbcr_inp_safe_mode;
45 -
46 - $wbcr_inp_safe_mode = false;
47 -
48 - // Set the constant that the plugin is activated
49 - define( 'WINP_PLUGIN_ACTIVE', true );
50 -
51 - define( 'WINP_PLUGIN_VERSION', $wbcr_inp_plugin_requirements->getPluginVersion() );
52 -
53 - // Root directory of the plugin
54 - define( 'WINP_PLUGIN_DIR', dirname( __FILE__ ) );
55 -
56 - // Absolute url of the root directory of the plugin
57 - define( 'WINP_PLUGIN_URL', plugins_url( null, __FILE__ ) );
58 -
59 - // Relative url of the plugin
60 - define( 'WINP_PLUGIN_BASE', plugin_basename( __FILE__ ) );
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 -
73 - // The snippet automatic insertion locations
74 - define( 'WINP_SNIPPET_AUTO_HEADER', 'header' );
75 - define( 'WINP_SNIPPET_AUTO_FOOTER', 'footer' );
76 - define( 'WINP_SNIPPET_AUTO_BEFORE_POST', 'before_post' );
77 - define( 'WINP_SNIPPET_AUTO_BEFORE_CONTENT', 'before_content' );
78 - define( 'WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH', 'before_paragraph' );
79 - define( 'WINP_SNIPPET_AUTO_AFTER_PARAGRAPH', 'after_paragraph' );
80 - define( 'WINP_SNIPPET_AUTO_AFTER_CONTENT', 'after_content' );
81 - define( 'WINP_SNIPPET_AUTO_AFTER_POST', 'after_post' );
82 - define( 'WINP_SNIPPET_AUTO_BEFORE_EXCERPT', 'before_excerpt' );
83 - define( 'WINP_SNIPPET_AUTO_AFTER_EXCERPT', 'after_excerpt' );
84 - define( 'WINP_SNIPPET_AUTO_BETWEEN_POSTS', 'between_posts' );
85 - define( 'WINP_SNIPPET_AUTO_BEFORE_POSTS', 'before_posts' );
86 - define( 'WINP_SNIPPET_AUTO_AFTER_POSTS', 'after_posts' );
87 -
88 - require_once( WINP_PLUGIN_DIR . '/libs/factory/core/boot.php' );
89 - require_once( WINP_PLUGIN_DIR . '/includes/class.helpers.php' );
90 - require_once( WINP_PLUGIN_DIR . '/includes/class.plugin.php' );
91 -
92 - try {
93 - new WINP_Plugin( __FILE__, array_merge( $wbcr_inp_plugin_info, array(
94 - 'plugin_version' => WINP_PLUGIN_VERSION
95 - ) ) );
96 - } catch( Exception $exception ) {
97 - throw new Exception( $exception->getMessage() );
98 - }
99 -}
100 -
101 -/*
102 -Note: This plugin requires WordPress version 3.3.1 or higher.
103 -
104 -Information about the Insert PHP plugin can be found here:
105 -http://www.willmaster.com/software/WPplugins/go/iphphome_iphplugin
106 -
107 -Instructions and examples can be found here:
108 -http://www.willmaster.com/software/WPplugins/go/iphpinstructions_iphplugin
109 -*/
110 -
111 -// todo: This is the code of the old version of the plugin, left unchanged for compatibility. Delete in the new major version of the plugin
112 -if ( ! function_exists( 'will_bontrager_insert_php' ) ) {
113 -
114 - function will_bontrager_insert_php( $content ) {
115 -
116 - if ( WINP_Helper::is_safe_mode() ) {
117 - return $content;
118 - }
119 -
120 - $will_bontrager_content = $content;
121 - preg_match_all( '!\[insert_php[^\]]*\](.*?)\[/insert_php[^\]]*\]!is', $will_bontrager_content, $will_bontrager_matches );
122 - $will_bontrager_nummatches = count( $will_bontrager_matches[0] );
123 - for ( $will_bontrager_i = 0; $will_bontrager_i < $will_bontrager_nummatches; $will_bontrager_i ++ ) {
124 - ob_start();
125 - eval( $will_bontrager_matches[1][ $will_bontrager_i ] );
126 - $will_bontrager_replacement = ob_get_contents();
127 - ob_clean();
128 - ob_end_flush();
129 - $will_bontrager_content = preg_replace( '/' . preg_quote( $will_bontrager_matches[0][ $will_bontrager_i ], '/' ) . '/', $will_bontrager_replacement, $will_bontrager_content, 1 );
130 - }
131 -
132 - return $will_bontrager_content;
133 - } # function will_bontrager_insert_php()
134 -
135 - add_filter( 'the_content', 'will_bontrager_insert_php', 9 );
136 -} # if( ! function_exists('will_bontrager_insert_php') )
137 -
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.7
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.7' );
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 +add_action(
93 + 'plugins_loaded',
94 + function () {
95 + $premium_plugin_file = 'woody-ad-snippets-premium/woody-ad-snippets-premium.php';
96 + $premium_plugin_path = WP_PLUGIN_DIR . '/' . $premium_plugin_file;
97 +
98 + if ( ! file_exists( $premium_plugin_path ) ) {
99 + return;
100 + }
101 +
102 + if ( ! function_exists( 'is_plugin_active' ) ) {
103 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
104 + }
105 +
106 + if ( ! is_plugin_active( $premium_plugin_file ) ) {
107 + return;
108 + }
109 +
110 + if ( ! function_exists( 'get_plugin_data' ) ) {
111 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
112 + }
113 + $premium_data = get_plugin_data( $premium_plugin_path );
114 +
115 + if ( version_compare( $premium_data['Version'], '1.3.0', '<' ) ) {
116 + deactivate_plugins( $premium_plugin_file );
117 + set_transient( 'winp_premium_version_incompatible', true, WEEK_IN_SECONDS );
118 + }
119 + },
120 + 5
121 +);
122 +
123 +add_action(
124 + 'admin_init',
125 + function () {
126 + if ( isset( $_GET['winp_dismiss_premium_notice'] ) && check_admin_referer( 'winp_dismiss_premium_notice' ) ) {
127 + delete_transient( 'winp_premium_version_incompatible' );
128 + wp_safe_redirect( remove_query_arg( 'winp_dismiss_premium_notice' ) );
129 + exit;
130 + }
131 + }
132 +);
133 +
134 +add_action(
135 + 'admin_notices',
136 + function () {
137 + if ( get_transient( 'winp_premium_version_incompatible' ) ) {
138 + $dismiss_url = wp_nonce_url(
139 + add_query_arg( 'winp_dismiss_premium_notice', '1' ),
140 + 'winp_dismiss_premium_notice'
141 + );
142 + ?>
143 + <div class="notice notice-error">
144 + <p>
145 + <strong><?php esc_html_e( 'Woody Code Snippets Premium has been deactivated.', 'insert-php' ); ?></strong>
146 + </p>
147 + <p>
148 + <?php
149 + printf(
150 + // translators: %s Premium version number.
151 + 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' ),
152 + '<strong>1.3.0</strong>'
153 + );
154 + ?>
155 + </p>
156 + <p>
157 + <a href="<?php echo esc_url( $dismiss_url ); ?>" class="button button-secondary">
158 + <?php esc_html_e( 'Dismiss this notice', 'insert-php' ); ?>
159 + </a>
160 + </p>
161 + </div>
162 + <?php
163 + }
164 + }
165 +);
166 +// END: Related to premium version compatibility check for below 1.3.
167 +
168 +require_once WINP_PLUGIN_DIR . '/includes/class.insertion.locations.php';
169 +require_once WINP_PLUGIN_DIR . '/includes/class.http.php';
170 +require_once WINP_PLUGIN_DIR . '/includes/class.helpers.php';
171 +require_once WINP_PLUGIN_DIR . '/includes/class.code-validator.php';
172 +require_once WINP_PLUGIN_DIR . '/includes/class.error-handler.php';
173 +require_once WINP_PLUGIN_DIR . '/includes/class.plugin.php';
174 +
175 +if ( file_exists( WINP_PLUGIN_DIR . '/vendor/autoload.php' ) ) {
176 + require_once WINP_PLUGIN_DIR . '/vendor/autoload.php';
177 +}
178 +
179 +/**
180 + * Adds a hint and button to the fatal error message.
181 + *
182 + * Since WordPress 5.2, we have access to a special mode for catching PHP errors.
183 + * If a user makes a syntax error while editing a snippet, instead of a white screen
184 + * (if PHP errors are disabled on the server), they will see a message from WordPress
185 + * generated by the WP_Fatal_Error_Handler class.
186 + *
187 + * We decided to add a button to this message to switch to safe mode.
188 + */
189 +add_filter(
190 + 'wp_php_error_message',
191 + function ( $message ) {
192 + $safe_mode_url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&wbcr-php-snippets-safe-mode' );
193 + $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>';
194 + $safe_mode_button .= '<a href="' . $safe_mode_url . '" class="button">' . __( 'Enable Safe Mode', 'insert-php' ) . '</a>';
195 +
196 + return $message . $safe_mode_button;
197 + }
198 +);
199 +
200 +/**
201 + * Enables/Disable safe mode, in which the php code will not be executed.
202 + */
203 +add_action(
204 + 'plugins_loaded',
205 + function () {
206 + if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) {
207 + WINP_Helper::enable_safe_mode();
208 + wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) ) );
209 + die();
210 + }
211 +
212 + if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) {
213 + WINP_Helper::disable_safe_mode();
214 + wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) ) );
215 + die();
216 + }
217 + },
218 + - 1
219 +);
220 +
221 +/**
222 + * Register product to SDK
223 + *
224 + * @param array<string> $products Registered products.
225 + * @return array<string>
226 + */
227 +function winp_sdk_register_products( $products ) {
228 + $products[] = WINP_PLUGIN_FILE;
229 +
230 + return $products;
231 +}
232 +
233 +/**
234 + * About page metadata
235 + *
236 + * @return array<string, mixed>
237 + */
238 +function winp_sdk_about_page() {
239 + return [
240 + 'location' => 'edit.php?post_type=wbcr-snippets',
241 + 'logo' => WINP_PLUGIN_URL . '/admin/assets/img/icon-256x256.png',
242 + 'review_link' => false,
243 + 'has_upgrade_menu' => false,
244 + ];
245 +}
246 +
247 +/**
248 + * Register compatibility using SDK.
249 + *
250 + * @param array<string, array<string, string>> $compatibilities All compatibilities.
251 + *
252 + * @return array<string, array<string, string>> Registered compatibility.
253 + */
254 +function winp_sdk_register_compatibility( $compatibilities ) {
255 + $compatibilities['WoodyPro'] = [
256 + 'basefile' => defined( 'WASP_PLUGIN_FILE' ) ? WASP_PLUGIN_FILE : '',
257 + 'required' => '1.3.0',
258 + ];
259 +
260 + return $compatibilities;
261 +}
262 +
263 +add_filter( 'themeisle_sdk_products', 'winp_sdk_register_products' );
264 +add_filter( WINP_PLUGIN_NAMESPACE . '_about_us_metadata', 'winp_sdk_about_page' );
265 +add_filter( 'themeisle_sdk_compatibilities/' . basename( WINP_PLUGIN_DIR ), 'winp_sdk_register_compatibility' );
266 +
267 +// Register activation/deactivation hooks.
268 +register_activation_hook(
269 + WINP_PLUGIN_FILE,
270 + function () {
271 + global $winp_snippets_locations;
272 + if ( ! isset( $winp_snippets_locations ) ) {
273 + $winp_snippets_locations = new WINP_Insertion_Locations();
274 + }
275 +
276 + // Instantiate plugin for activation.
277 + $plugin = new WINP_Plugin();
278 + $plugin->activation_hook();
279 + }
280 +);
281 +
282 +register_deactivation_hook(
283 + WINP_PLUGIN_FILE,
284 + function () {
285 + global $winp_snippets_locations;
286 + if ( ! isset( $winp_snippets_locations ) ) {
287 + $winp_snippets_locations = new WINP_Insertion_Locations();
288 + }
289 +
290 + // Instantiate plugin for deactivation.
291 + $plugin = new WINP_Plugin();
292 + $plugin->deactivation_hook();
293 + }
294 +);
295 +
296 +// Initialize on 'init' hook with priority 0 to avoid early translation loading (WP 6.7+)
297 +add_action(
298 + 'init',
299 + function () {
300 + global $winp_snippets_locations;
301 + $winp_snippets_locations = new WINP_Insertion_Locations();
302 +
303 + try {
304 + new WINP_Plugin();
305 + } catch ( Exception $exception ) {
306 + // Plugin wasn't initialized due to an error
307 + define( 'WINP_PLUGIN_THROW_ERROR', true );
308 +
309 + $wbcr_plugin_error_func = function () use ( $exception ) {
310 + $error = sprintf( 'The %s plugin has stopped. <b>Error:</b> %s Code: %s', 'Woody Ad Snippets', $exception->getMessage(), $exception->getCode() );
311 + echo '<div class="notice notice-error"><p>' . $error . '</p></div>';
312 + };
313 +
314 + add_action( 'admin_notices', $wbcr_plugin_error_func );
315 + add_action( 'network_admin_notices', $wbcr_plugin_error_func );
316 + }
317 + },
318 + 0
319 +);