Code Snippets - Version 2.9.2

Version Description

(8 Sep 2017) = * Fixed: Do not attempt to combine queries for fetching local and multisite snippets

Download this release

Release Info

Developer bungeshea
Plugin Icon Code Snippets
Version 2.9.2
Comparing to
See all releases

Code changes from version 2.9.1 to 2.9.2

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.1
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.1
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.1' );
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.2
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.2
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.2' );
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.1\n"
10
  "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2017-09-07 11:40+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"
6
  #, fuzzy
7
  msgid ""
8
  msgstr ""
9
+ "Project-Id-Version: code-snippets 2.9.2\n"
10
  "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2017-09-08 00:24+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"
php/snippet-ops.php CHANGED
@@ -448,12 +448,11 @@ function execute_active_snippets() {
448
  global $wpdb;
449
 
450
  $current_scope = is_admin() ? 1 : 2;
451
-
452
- $collate = "COLLATE {$wpdb->collate}";
453
 
454
  /* Fetch snippets from site table */
455
  if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
456
- $sql = $wpdb->prepare( "SELECT id, code {$collate} FROM {$wpdb->snippets} WHERE (scope=0 OR scope=%d) AND active=1", $current_scope );
457
  }
458
 
459
  /* Fetch snippets from the network table */
@@ -467,34 +466,27 @@ function execute_active_snippets() {
467
  $active_shared_ids_format = implode( ',', array_fill( 0, count( $active_shared_ids ), '%d' ) );
468
 
469
  /* Include them in the query */
470
- $mu_sql = "SELECT id, code {$collate} FROM {$wpdb->snippets} WHERE (scope=0 OR scope=%d) AND (active=1 OR id IN ($active_shared_ids_format))";
471
 
472
  /* Add the scope number to the IDs array, so that it is the first variable in the query */
473
  array_unshift( $active_shared_ids, $current_scope );
474
- $mu_sql = $wpdb->prepare( $mu_sql, $active_shared_ids );
475
 
476
  } else {
477
- $mu_sql = $wpdb->prepare( "SELECT id, code {$collate} FROM {$wpdb->ms_snippets} WHERE (scope=0 OR scope=%d) AND active=1", $current_scope );
478
  }
479
-
480
- /* Join the two SQL queries together */
481
- $sql = ( empty( $sql ) ? '' : $sql . ' UNION ALL ' ) . $mu_sql;
482
- }
483
-
484
- /* Return false if there is no query */
485
- if ( empty( $sql ) ) {
486
- return false;
487
  }
488
 
489
- /* Grab the snippets from the database */
490
- $active_snippets = $wpdb->get_results( $sql, ARRAY_A );
491
 
492
- /* Loop through the returned snippets and execute the PHP code */
493
- foreach ( $active_snippets as $snippet_id => $snippet ) {
494
- $code = $collate ? $snippet["code $collate"] : $snippet['code'];
495
 
496
- if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id ) ) {
497
- execute_snippet( $code, $snippet_id );
 
498
  }
499
  }
500
 
448
  global $wpdb;
449
 
450
  $current_scope = is_admin() ? 1 : 2;
451
+ $queries = array();
 
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 */
466
  $active_shared_ids_format = implode( ',', array_fill( 0, count( $active_shared_ids ), '%d' ) );
467
 
468
  /* Include them in the query */
469
+ $sql = "SELECT id, code FROM {$wpdb->snippets} WHERE (scope=0 OR scope=%d) AND (active=1 OR id IN ($active_shared_ids_format))";
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
+ $queries[] = $wpdb->prepare( "SELECT id, code FROM {$wpdb->ms_snippets} WHERE (scope=0 OR scope=%d) AND active=1", $current_scope );
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 $snippet_id => $snippet ) {
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
  }
491
  }
492
 
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.1
8
  License: MIT
9
  License URI: license.txt
10
 
@@ -110,6 +110,9 @@ That's fantastic! Fork the [repository on GitHub](http://github.com/sheabunge/co
110
 
111
  == Changelog ==
112
 
 
 
 
113
  = 2.9.1 (7 Sep 2017) =
114
  * Fixed: Prevent illegal mix of collations errors when fetching snippets from database tables with different collations [[#](https://wordpress.org/support/topic/issue-on-multisite-with-wpml/)]
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.2
8
  License: MIT
9
  License URI: license.txt
10
 
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
+
116
  = 2.9.1 (7 Sep 2017) =
117
  * Fixed: Prevent illegal mix of collations errors when fetching snippets from database tables with different collations [[#](https://wordpress.org/support/topic/issue-on-multisite-with-wpml/)]
118