File tree Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -1220,17 +1220,46 @@ public function maybe_delete_transients( $should_delete ) {
12201220 return ;
12211221 }
12221222
1223+ if ( is_multisite () ) {
1224+ $ this ->delete_multisite_transients ();
1225+
1226+ return ;
1227+ }
1228+
12231229 $ wpdb ->query ( $ wpdb ->prepare (
12241230 "DELETE FROM {$ wpdb ->options } WHERE option_name LIKE %s OR option_name LIKE %s " ,
12251231 '_transient_% ' ,
12261232 '_site_transient_% '
12271233 ) );
1234+ }
12281235
1229- if ( is_multisite () ) {
1230- $ wpdb ->query ( $ wpdb ->prepare (
1231- "DELETE FROM {$ wpdb ->sitemeta } WHERE meta_key LIKE %s " , '_site_transient_% '
1232- ) );
1236+ /**
1237+ * Deletes the transients for all blogs on the multisite network.
1238+ *
1239+ * @return void
1240+ */
1241+ protected function delete_multisite_transients () {
1242+ global $ wpdb ;
1243+
1244+ $ wpdb ->query ( $ wpdb ->prepare (
1245+ "DELETE FROM {$ wpdb ->sitemeta } WHERE meta_key LIKE %s " , '_site_transient_% '
1246+ ) );
1247+
1248+ $ sites = get_sites ([ 'fields ' => 'ids ' , 'number ' => 0 ]);
1249+
1250+ foreach ( $ sites as $ id ) {
1251+ try {
1252+ switch_to_blog ( $ id );
1253+
1254+ $ wpdb ->query ( $ wpdb ->prepare (
1255+ "DELETE FROM {$ wpdb ->options } WHERE option_name LIKE %s " , '_transient_% '
1256+ ) );
1257+ } catch ( Exception $ error ) {
1258+ error_log ($ error ->getMessage ());
1259+ }
12331260 }
1261+
1262+ restore_current_blog ();
12341263 }
12351264
12361265 /**
You can’t perform that action at this time.
0 commit comments