[wp-trac] [WordPress Trac] #60366: add call_for_blog for easy to switch blog and restore in multisite

WordPress Trac noreply at wordpress.org
Wed Feb 19 07:08:48 UTC 2025


#60366: add call_for_blog  for easy to switch blog and restore in multisite
-------------------------+------------------------------
 Reporter:  denishua     |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by oshodev):

 Your function is well-structured, but the usage examples have a slight
 mismatch in function names (call_for_blog vs. for_blog). Below is the
 corrected version with consistent naming:

 Function (No Changes Needed)

 {{{
 function call_for_blog($blog_id, $callback, ...$args){
     try {
         $switched = (is_multisite() && $blog_id && $blog_id !=
 get_current_blog_id()) ? switch_to_blog($blog_id) : false;
         return call_user_func_array($callback, $args);
     } finally {
         if ($switched) {
             restore_current_blog();
         }
     }
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60366#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list