Code Snippets - Version 2.9.1

Version Description

(7 Sep 2017) = * Fixed: Prevent illegal mix of collations errors when fetching snippets from database tables with different collations [#]

Download this release

Release Info

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

Code changes from version 2.9.0 to 2.9.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.0
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.0
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.0' );
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.1
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.1
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.1' );
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.0\n"
10
  "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2017-09-07 00:19+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.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"
php/snippet-ops.php CHANGED
@@ -449,9 +449,11 @@ function execute_active_snippets() {
449
 
450
  $current_scope = is_admin() ? 1 : 2;
451
 
 
 
452
  /* Fetch snippets from site table */
453
  if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
454
- $sql = $wpdb->prepare( "SELECT id, code FROM {$wpdb->snippets} WHERE (scope=0 OR scope=%d) AND active=1", $current_scope );
455
  }
456
 
457
  /* Fetch snippets from the network table */
@@ -465,14 +467,14 @@ function execute_active_snippets() {
465
  $active_shared_ids_format = implode( ',', array_fill( 0, count( $active_shared_ids ), '%d' ) );
466
 
467
  /* Include them in the query */
468
- $mu_sql = "SELECT id, code FROM {$wpdb->snippets} WHERE (scope=0 OR scope=%d) AND (active=1 OR id IN ($active_shared_ids_format))";
469
 
470
  /* Add the scope number to the IDs array, so that it is the first variable in the query */
471
  array_unshift( $active_shared_ids, $current_scope );
472
  $mu_sql = $wpdb->prepare( $mu_sql, $active_shared_ids );
473
 
474
  } else {
475
- $mu_sql = $wpdb->prepare( "SELECT id, code FROM {$wpdb->ms_snippets} WHERE (scope=0 OR scope=%d) AND active=1", $current_scope );
476
  }
477
 
478
  /* Join the two SQL queries together */
@@ -485,13 +487,14 @@ function execute_active_snippets() {
485
  }
486
 
487
  /* Grab the snippets from the database */
488
- $active_snippets = $wpdb->get_results( $sql, OBJECT_K );
489
 
490
  /* Loop through the returned snippets and execute the PHP code */
491
  foreach ( $active_snippets as $snippet_id => $snippet ) {
 
492
 
493
  if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id ) ) {
494
- execute_snippet( $snippet->code, $snippet_id );
495
  }
496
  }
497
 
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
  $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 */
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
 
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.0
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.0 (6 Sep 2017) =
114
  * Fixed: Prevented invalid properties from being set when saving a snippet
115
  * Fixed: Use the correct protocol when saving a snippet
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
 
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
+
116
  = 2.9.0 (6 Sep 2017) =
117
  * Fixed: Prevented invalid properties from being set when saving a snippet
118
  * Fixed: Use the correct protocol when saving a snippet