PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.0
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.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 / insert_php.php

insert_php.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.7.0, at insert_php.php

238 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.0
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.6.1' );
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 require_once WINP_PLUGIN_DIR . '/includes/class.insertion.locations.php';
92 require_once WINP_PLUGIN_DIR . '/includes/class.http.php';
93 require_once WINP_PLUGIN_DIR . '/includes/class.helpers.php';
94 require_once WINP_PLUGIN_DIR . '/includes/class.plugin.php';
95
96 /**
97 * Adds a hint and button to the fatal error message.
98 *
99 * Since WordPress 5.2, we have access to a special mode for catching PHP errors.
100 * If a user makes a syntax error while editing a snippet, instead of a white screen
101 * (if PHP errors are disabled on the server), they will see a message from WordPress
102 * generated by the WP_Fatal_Error_Handler class.
103 *
104 * We decided to add a button to this message to switch to safe mode.
105 */
106 add_filter(
107 'wp_php_error_message',
108 function ( $message ) {
109 $safe_mode_url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&wbcr-php-snippets-safe-mode' );
110 $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>';
111 $safe_mode_button .= '<a href="' . $safe_mode_url . '" class="button">' . __( 'Enable Safe Mode', 'insert-php' ) . '</a>';
112
113 return $message . $safe_mode_button;
114 }
115 );
116
117 /**
118 * Enables/Disable safe mode, in which the php code will not be executed.
119 */
120 add_action(
121 'plugins_loaded',
122 function () {
123 if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) {
124 WINP_Helper::enable_safe_mode();
125 wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) ) );
126 die();
127 }
128
129 if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) {
130 WINP_Helper::disable_safe_mode();
131 wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) ) );
132 die();
133 }
134 },
135 - 1
136 );
137
138 /**
139 * Register product to SDK
140 *
141 * @param array<string> $products Registered products.
142 * @return array<string>
143 */
144 function winp_sdk_register_products( $products ) {
145 $products[] = WINP_PLUGIN_FILE;
146
147 return $products;
148 }
149
150 /**
151 * About page metadata
152 *
153 * @return array<string, mixed>
154 */
155 function winp_sdk_about_page() {
156 return [
157 'location' => 'edit.php?post_type=wbcr-snippets',
158 'logo' => WINP_PLUGIN_URL . '/admin/assets/img/icon-256x256.png',
159 'review_link' => false,
160 'has_upgrade_menu' => false,
161 ];
162 }
163
164 /**
165 * Register compatibility using SDK.
166 *
167 * @param array<string, array<string, string>> $compatibilities All compatibilities.
168 *
169 * @return array<string, array<string, string>> Registered compatibility.
170 */
171 function winp_sdk_register_compatibility( $compatibilities ) {
172 $compatibilities['WoodyPro'] = [
173 'basefile' => defined( 'WASP_PLUGIN_FILE' ) ? WASP_PLUGIN_FILE : '',
174 'required' => '1.3.0',
175 ];
176
177 return $compatibilities;
178 }
179
180 add_filter( 'themeisle_sdk_products', 'winp_sdk_register_products' );
181 add_filter( WINP_PLUGIN_NAMESPACE . '_about_us_metadata', 'winp_sdk_about_page' );
182 add_filter( 'themeisle_sdk_compatibilities/' . basename( WINP_PLUGIN_DIR ), 'winp_sdk_register_compatibility' );
183
184 // Register activation/deactivation hooks.
185 register_activation_hook(
186 WINP_PLUGIN_FILE,
187 function () {
188 global $winp_snippets_locations;
189 if ( ! isset( $winp_snippets_locations ) ) {
190 $winp_snippets_locations = new WINP_Insertion_Locations();
191 }
192
193 // Instantiate plugin for activation.
194 $plugin = new WINP_Plugin();
195 $plugin->activation_hook();
196 }
197 );
198
199 register_deactivation_hook(
200 WINP_PLUGIN_FILE,
201 function () {
202 global $winp_snippets_locations;
203 if ( ! isset( $winp_snippets_locations ) ) {
204 $winp_snippets_locations = new WINP_Insertion_Locations();
205 }
206
207 // Instantiate plugin for deactivation.
208 $plugin = new WINP_Plugin();
209 $plugin->deactivation_hook();
210 }
211 );
212
213 // Initialize on 'init' hook with priority 0 to avoid early translation loading (WP 6.7+)
214 add_action(
215 'init',
216 function () {
217 global $winp_snippets_locations;
218 $winp_snippets_locations = new WINP_Insertion_Locations();
219
220 try {
221 require_once WINP_PLUGIN_DIR . '/vendor/autoload.php';
222 new WINP_Plugin();
223 } catch ( Exception $exception ) {
224 // Plugin wasn't initialized due to an error
225 define( 'WINP_PLUGIN_THROW_ERROR', true );
226
227 $wbcr_plugin_error_func = function () use ( $exception ) {
228 $error = sprintf( 'The %s plugin has stopped. <b>Error:</b> %s Code: %s', 'Woody Ad Snippets', $exception->getMessage(), $exception->getCode() );
229 echo '<div class="notice notice-error"><p>' . $error . '</p></div>';
230 };
231
232 add_action( 'admin_notices', $wbcr_plugin_error_func );
233 add_action( 'network_admin_notices', $wbcr_plugin_error_func );
234 }
235 },
236 0
237 );
238