Version Description
(11 Sep 2017) = * Fixed: Prevent snippets from being executed twice when saving due to invalid ID being passed to allow_execute_snippet filter * Fixed: Re-enabled output suppression when executing snippets
Download this release
Release Info
Developer | bungeshea |
Plugin | Code Snippets |
Version | 2.9.3 |
Comparing to | |
See all releases |
Code changes from version 2.9.2 to 2.9.3
- code-snippets.php +3 -3
- languages/code-snippets.pot +13 -13
- php/admin-menus/class-edit-menu.php +1 -1
- php/class-admin.php +7 -3
- php/snippet-ops.php +21 -9
- readme.txt +5 -1
code-snippets.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
* @author Shea Bunge <shea@bungeshea.com>
|
11 |
* @copyright 2012-2017 Shea Bunge
|
12 |
* @license MIT http://opensource.org/licenses/MIT
|
13 |
-
* @version 2.9.
|
14 |
* @link https://github.com/sheabunge/code-snippets
|
15 |
*/
|
16 |
|
@@ -20,7 +20,7 @@ Plugin URI: https://github.com/sheabunge/code-snippets
|
|
20 |
Description: An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!
|
21 |
Author: Shea Bunge
|
22 |
Author URI: https://bungeshea.com
|
23 |
-
Version: 2.9.
|
24 |
License: MIT
|
25 |
License URI: license.txt
|
26 |
Text Domain: code-snippets
|
@@ -42,7 +42,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
42 |
* @since 2.0
|
43 |
* @var string A PHP-standardized version number string
|
44 |
*/
|
45 |
-
define( 'CODE_SNIPPETS_VERSION', '2.9.
|
46 |
|
47 |
/**
|
48 |
* The full path to the main file of this plugin
|
10 |
* @author Shea Bunge <shea@bungeshea.com>
|
11 |
* @copyright 2012-2017 Shea Bunge
|
12 |
* @license MIT http://opensource.org/licenses/MIT
|
13 |
+
* @version 2.9.3
|
14 |
* @link https://github.com/sheabunge/code-snippets
|
15 |
*/
|
16 |
|
20 |
Description: An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!
|
21 |
Author: Shea Bunge
|
22 |
Author URI: https://bungeshea.com
|
23 |
+
Version: 2.9.3
|
24 |
License: MIT
|
25 |
License URI: license.txt
|
26 |
Text Domain: code-snippets
|
42 |
* @since 2.0
|
43 |
* @var string A PHP-standardized version number string
|
44 |
*/
|
45 |
+
define( 'CODE_SNIPPETS_VERSION', '2.9.3' );
|
46 |
|
47 |
/**
|
48 |
* The full path to the main file of this plugin
|
languages/code-snippets.pot
CHANGED
@@ -6,9 +6,9 @@
|
|
6 |
#, fuzzy
|
7 |
msgid ""
|
8 |
msgstr ""
|
9 |
-
"Project-Id-Version: code-snippets 2.9.
|
10 |
"Report-Msgid-Bugs-To: \n"
|
11 |
-
"POT-Creation-Date: 2017-09-
|
12 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
13 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
@@ -172,7 +172,7 @@ msgstr ""
|
|
172 |
|
173 |
#: php/admin-menus/class-manage-menu.php:23
|
174 |
#: php/admin-menus/class-manage-menu.php:45 php/class-admin.php:61
|
175 |
-
#: php/class-admin.php:
|
176 |
msgid "Snippets"
|
177 |
msgstr ""
|
178 |
|
@@ -226,46 +226,46 @@ msgstr ""
|
|
226 |
msgid "Settings"
|
227 |
msgstr ""
|
228 |
|
229 |
-
#: php/class-admin.php:
|
230 |
msgid "Manage your existing snippets"
|
231 |
msgstr ""
|
232 |
|
233 |
-
#: php/class-admin.php:
|
234 |
msgid "Visit the WordPress.org plugin page"
|
235 |
msgstr ""
|
236 |
|
237 |
-
#: php/class-admin.php:
|
238 |
msgid "About"
|
239 |
msgstr ""
|
240 |
|
241 |
-
#: php/class-admin.php:
|
242 |
msgid "Visit the support forums"
|
243 |
msgstr ""
|
244 |
|
245 |
-
#: php/class-admin.php:
|
246 |
msgid "Support"
|
247 |
msgstr ""
|
248 |
|
249 |
-
#: php/class-admin.php:
|
250 |
msgid "Support this plugin's development"
|
251 |
msgstr ""
|
252 |
|
253 |
-
#: php/class-admin.php:
|
254 |
msgid "Donate"
|
255 |
msgstr ""
|
256 |
|
257 |
-
#: php/class-admin.php:
|
258 |
msgid ""
|
259 |
"<strong>Have feedback on Code Snippets?</strong> Please take the time to "
|
260 |
"answer a short survey on how you use this plugin and what you'd like to see "
|
261 |
"changed or added in the future."
|
262 |
msgstr ""
|
263 |
|
264 |
-
#: php/class-admin.php:
|
265 |
msgid "Take the survey now"
|
266 |
msgstr ""
|
267 |
|
268 |
-
#: php/class-admin.php:
|
269 |
msgid "Dismiss"
|
270 |
msgstr ""
|
271 |
|
6 |
#, fuzzy
|
7 |
msgid ""
|
8 |
msgstr ""
|
9 |
+
"Project-Id-Version: code-snippets 2.9.3\n"
|
10 |
"Report-Msgid-Bugs-To: \n"
|
11 |
+
"POT-Creation-Date: 2017-09-11 23:43+1000\n"
|
12 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
13 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
172 |
|
173 |
#: php/admin-menus/class-manage-menu.php:23
|
174 |
#: php/admin-menus/class-manage-menu.php:45 php/class-admin.php:61
|
175 |
+
#: php/class-admin.php:148 php/views/manage.php:19
|
176 |
msgid "Snippets"
|
177 |
msgstr ""
|
178 |
|
226 |
msgid "Settings"
|
227 |
msgstr ""
|
228 |
|
229 |
+
#: php/class-admin.php:147
|
230 |
msgid "Manage your existing snippets"
|
231 |
msgstr ""
|
232 |
|
233 |
+
#: php/class-admin.php:178
|
234 |
msgid "Visit the WordPress.org plugin page"
|
235 |
msgstr ""
|
236 |
|
237 |
+
#: php/class-admin.php:179
|
238 |
msgid "About"
|
239 |
msgstr ""
|
240 |
|
241 |
+
#: php/class-admin.php:183
|
242 |
msgid "Visit the support forums"
|
243 |
msgstr ""
|
244 |
|
245 |
+
#: php/class-admin.php:184
|
246 |
msgid "Support"
|
247 |
msgstr ""
|
248 |
|
249 |
+
#: php/class-admin.php:188
|
250 |
msgid "Support this plugin's development"
|
251 |
msgstr ""
|
252 |
|
253 |
+
#: php/class-admin.php:189
|
254 |
msgid "Donate"
|
255 |
msgstr ""
|
256 |
|
257 |
+
#: php/class-admin.php:220
|
258 |
msgid ""
|
259 |
"<strong>Have feedback on Code Snippets?</strong> Please take the time to "
|
260 |
"answer a short survey on how you use this plugin and what you'd like to see "
|
261 |
"changed or added in the future."
|
262 |
msgstr ""
|
263 |
|
264 |
+
#: php/class-admin.php:224
|
265 |
msgid "Take the survey now"
|
266 |
msgstr ""
|
267 |
|
268 |
+
#: php/class-admin.php:227
|
269 |
msgid "Dismiss"
|
270 |
msgstr ""
|
271 |
|
php/admin-menus/class-edit-menu.php
CHANGED
@@ -178,7 +178,7 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
|
|
178 |
|
179 |
ob_start( array( $this, 'code_error_callback' ) );
|
180 |
|
181 |
-
$result = execute_snippet( $snippet->code, $snippet->id );
|
182 |
|
183 |
ob_end_clean();
|
184 |
|
178 |
|
179 |
ob_start( array( $this, 'code_error_callback' ) );
|
180 |
|
181 |
+
$result = execute_snippet( $snippet->code, $snippet->id, false );
|
182 |
|
183 |
ob_end_clean();
|
184 |
|
php/class-admin.php
CHANGED
@@ -40,7 +40,7 @@ class Code_Snippets_Admin {
|
|
40 |
add_action( 'code_snippets/admin/manage', array( $this, 'survey_message' ) );
|
41 |
|
42 |
if ( isset( $_POST['save_snippet'] ) && $_POST['save_snippet'] ) {
|
43 |
-
add_action( 'code_snippets/allow_execute_snippet', array( $this, 'prevent_exec_on_save' ), 10,
|
44 |
}
|
45 |
}
|
46 |
|
@@ -112,15 +112,19 @@ class Code_Snippets_Admin {
|
|
112 |
*
|
113 |
* @return bool Whether the snippet will be executed
|
114 |
*/
|
115 |
-
function prevent_exec_on_save( $exec, $exec_id ) {
|
116 |
|
117 |
if ( ! isset( $_POST['save_snippet'], $_POST['snippet_id'] ) ) {
|
118 |
return $exec;
|
119 |
}
|
120 |
|
|
|
|
|
|
|
|
|
121 |
$id = intval( $_POST['snippet_id'] );
|
122 |
|
123 |
-
if ( $id
|
124 |
return false;
|
125 |
}
|
126 |
|
40 |
add_action( 'code_snippets/admin/manage', array( $this, 'survey_message' ) );
|
41 |
|
42 |
if ( isset( $_POST['save_snippet'] ) && $_POST['save_snippet'] ) {
|
43 |
+
add_action( 'code_snippets/allow_execute_snippet', array( $this, 'prevent_exec_on_save' ), 10, 3 );
|
44 |
}
|
45 |
}
|
46 |
|
112 |
*
|
113 |
* @return bool Whether the snippet will be executed
|
114 |
*/
|
115 |
+
function prevent_exec_on_save( $exec, $exec_id, $table_name ) {
|
116 |
|
117 |
if ( ! isset( $_POST['save_snippet'], $_POST['snippet_id'] ) ) {
|
118 |
return $exec;
|
119 |
}
|
120 |
|
121 |
+
if ( code_snippets()->db->get_table_name() !== $table_name ) {
|
122 |
+
return $exec;
|
123 |
+
}
|
124 |
+
|
125 |
$id = intval( $_POST['snippet_id'] );
|
126 |
|
127 |
+
if ( $id === $exec_id ) {
|
128 |
return false;
|
129 |
}
|
130 |
|
php/snippet-ops.php
CHANGED
@@ -414,18 +414,28 @@ function export_snippets( $ids, $multisite = null, $format = 'xml' ) {
|
|
414 |
*
|
415 |
* @since 2.0
|
416 |
*
|
417 |
-
* @param
|
418 |
-
* @param
|
|
|
|
|
419 |
* @return mixed The result of the code execution
|
420 |
*/
|
421 |
-
function execute_snippet( $code, $id = 0 ) {
|
422 |
|
423 |
if ( empty( $code ) ) {
|
424 |
return false;
|
425 |
}
|
426 |
|
|
|
|
|
|
|
|
|
427 |
$result = eval( $code );
|
428 |
|
|
|
|
|
|
|
|
|
429 |
do_action( 'code_snippets/after_execute_snippet', $id, $code, $result );
|
430 |
|
431 |
return $result;
|
@@ -452,7 +462,7 @@ function execute_active_snippets() {
|
|
452 |
|
453 |
/* Fetch snippets from site table */
|
454 |
if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
|
455 |
-
$queries[] = $wpdb->prepare( "SELECT id, code FROM {$wpdb->snippets} WHERE (scope=0 OR scope=%d) AND active=1", $current_scope );
|
456 |
}
|
457 |
|
458 |
/* Fetch snippets from the network table */
|
@@ -470,21 +480,23 @@ function execute_active_snippets() {
|
|
470 |
|
471 |
/* Add the scope number to the IDs array, so that it is the first variable in the query */
|
472 |
array_unshift( $active_shared_ids, $current_scope );
|
473 |
-
$queries[] = $wpdb->prepare( $sql, $active_shared_ids );
|
474 |
|
475 |
} else {
|
476 |
-
$
|
|
|
477 |
}
|
478 |
}
|
479 |
|
480 |
-
foreach ( $queries as $query ) {
|
481 |
$active_snippets = $wpdb->get_results( $query, ARRAY_A );
|
482 |
|
483 |
/* Loop through the returned snippets and execute the PHP code */
|
484 |
-
foreach ( $active_snippets as $
|
|
|
485 |
$code = $snippet['code'];
|
486 |
|
487 |
-
if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id ) ) {
|
488 |
execute_snippet( $code, $snippet_id );
|
489 |
}
|
490 |
}
|
414 |
*
|
415 |
* @since 2.0
|
416 |
*
|
417 |
+
* @param string $code The snippet code to execute
|
418 |
+
* @param int $id The snippet ID
|
419 |
+
* @param bool $catch_output Whether to attempt to suppress the output of execution using buffers
|
420 |
+
*
|
421 |
* @return mixed The result of the code execution
|
422 |
*/
|
423 |
+
function execute_snippet( $code, $id = 0, $catch_output = true ) {
|
424 |
|
425 |
if ( empty( $code ) ) {
|
426 |
return false;
|
427 |
}
|
428 |
|
429 |
+
if ( $catch_output ) {
|
430 |
+
ob_start();
|
431 |
+
}
|
432 |
+
|
433 |
$result = eval( $code );
|
434 |
|
435 |
+
if ( $catch_output ) {
|
436 |
+
ob_end_clean();
|
437 |
+
}
|
438 |
+
|
439 |
do_action( 'code_snippets/after_execute_snippet', $id, $code, $result );
|
440 |
|
441 |
return $result;
|
462 |
|
463 |
/* Fetch snippets from site table */
|
464 |
if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
|
465 |
+
$queries[ $wpdb->snippets ] = $wpdb->prepare( "SELECT id, code FROM {$wpdb->snippets} WHERE (scope=0 OR scope=%d) AND active=1", $current_scope );
|
466 |
}
|
467 |
|
468 |
/* Fetch snippets from the network table */
|
480 |
|
481 |
/* Add the scope number to the IDs array, so that it is the first variable in the query */
|
482 |
array_unshift( $active_shared_ids, $current_scope );
|
483 |
+
$queries[ $wpdb->ms_snippets ] = $wpdb->prepare( $sql, $active_shared_ids );
|
484 |
|
485 |
} else {
|
486 |
+
$sql = "SELECT id, code FROM {$wpdb->ms_snippets} WHERE (scope=0 OR scope=%d) AND active=1";
|
487 |
+
$queries[ $wpdb->ms_snippets ] = $wpdb->prepare( $sql, $current_scope );
|
488 |
}
|
489 |
}
|
490 |
|
491 |
+
foreach ( $queries as $table_name => $query ) {
|
492 |
$active_snippets = $wpdb->get_results( $query, ARRAY_A );
|
493 |
|
494 |
/* Loop through the returned snippets and execute the PHP code */
|
495 |
+
foreach ( $active_snippets as $snippet ) {
|
496 |
+
$snippet_id = intval( $snippet['id'] );
|
497 |
$code = $snippet['code'];
|
498 |
|
499 |
+
if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id, $table_name ) ) {
|
500 |
execute_snippet( $code, $snippet_id );
|
501 |
}
|
502 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://bungeshea.com/donate/
|
|
4 |
Tags: code-snippets, snippets, code, php, network, multisite
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 4.8.1
|
7 |
-
Stable tag: 2.9.
|
8 |
License: MIT
|
9 |
License URI: license.txt
|
10 |
|
@@ -110,6 +110,10 @@ That's fantastic! Fork the [repository on GitHub](http://github.com/sheabunge/co
|
|
110 |
|
111 |
== Changelog ==
|
112 |
|
|
|
|
|
|
|
|
|
113 |
= 2.9.2 (8 Sep 2017) =
|
114 |
* Fixed: Do not attempt to combine queries for fetching local and multisite snippets
|
115 |
|
4 |
Tags: code-snippets, snippets, code, php, network, multisite
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 4.8.1
|
7 |
+
Stable tag: 2.9.3
|
8 |
License: MIT
|
9 |
License URI: license.txt
|
10 |
|
110 |
|
111 |
== Changelog ==
|
112 |
|
113 |
+
= 2.9.3 (11 Sep 2017) =
|
114 |
+
* Fixed: Prevent snippets from being executed twice when saving due to invalid ID being passed to allow_execute_snippet filter
|
115 |
+
* Fixed: Re-enabled output suppression when executing snippets
|
116 |
+
|
117 |
= 2.9.2 (8 Sep 2017) =
|
118 |
* Fixed: Do not attempt to combine queries for fetching local and multisite snippets
|
119 |
|