@@ -448,12 +448,11 @@ function execute_active_snippets() {
448
448
global $ wpdb ;
449
449
450
450
$ current_scope = is_admin () ? 1 : 2 ;
451
-
452
- $ collate = "COLLATE {$ wpdb ->collate }" ;
451
+ $ queries = array ();
453
452
454
453
/* Fetch snippets from site table */
455
454
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 );
455
+ $ queries [] = $ wpdb ->prepare ( "SELECT id, code FROM {$ wpdb ->snippets } WHERE (scope=0 OR scope=%d) AND active=1 " , $ current_scope );
457
456
}
458
457
459
458
/* Fetch snippets from the network table */
@@ -467,34 +466,27 @@ function execute_active_snippets() {
467
466
$ active_shared_ids_format = implode ( ', ' , array_fill ( 0 , count ( $ active_shared_ids ), '%d ' ) );
468
467
469
468
/* 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)) " ;
469
+ $ sql = "SELECT id, code FROM {$ wpdb ->snippets } WHERE (scope=0 OR scope=%d) AND (active=1 OR id IN ( $ active_shared_ids_format)) " ;
471
470
472
471
/* Add the scope number to the IDs array, so that it is the first variable in the query */
473
472
array_unshift ( $ active_shared_ids , $ current_scope );
474
- $ mu_sql = $ wpdb ->prepare ( $ mu_sql , $ active_shared_ids );
473
+ $ queries [] = $ wpdb ->prepare ( $ sql , $ active_shared_ids );
475
474
476
475
} 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 );
476
+ $ queries [] = $ wpdb ->prepare ( "SELECT id, code FROM {$ wpdb ->ms_snippets } WHERE (scope=0 OR scope=%d) AND active=1 " , $ current_scope );
478
477
}
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
478
}
488
479
489
- /* Grab the snippets from the database */
490
- $ active_snippets = $ wpdb ->get_results ( $ sql , ARRAY_A );
480
+ foreach ( $ queries as $ query ) {
481
+ $ active_snippets = $ wpdb ->get_results ( $ query , ARRAY_A );
491
482
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 ' ];
483
+ /* Loop through the returned snippets and execute the PHP code */
484
+ foreach ( $ active_snippets as $ snippet_id => $ snippet ) {
485
+ $ code = $ snippet ['code ' ];
495
486
496
- if ( apply_filters ( 'code_snippets/allow_execute_snippet ' , true , $ snippet_id ) ) {
497
- execute_snippet ( $ code , $ snippet_id );
487
+ if ( apply_filters ( 'code_snippets/allow_execute_snippet ' , true , $ snippet_id ) ) {
488
+ execute_snippet ( $ code , $ snippet_id );
489
+ }
498
490
}
499
491
}
500
492
0 commit comments