update_blog_option()

I was dealing with network DB option filtering few weeks back and I was unable to find a proper way to use update_option, update_site_option or any relevant function to update the main site’s option value.

I just found update_blog_option which is pretty cool and it does the following inside:

…
switch_to_blog( $id );
$return = update_option( $option, $value );
restore_current_blog();
…

Since the option filtering is triggered per update option, I had to hack it with recursively switching the blog and resetting it after the second callback:

public function get_network_trzapi_key( $option ) {
$site_id = get_current_blog_id();

if ( $site_id !== 1 ) {
switch_to_blog( 1 );
$option = get_option( ‘trzapi_key’ );

}
switch_to_blog( $site_id );

return $option;
}

Feeling much better now and I can cross out that problem off the list.


Mario Peshev is a 5x CEO and operator, founder of DevriX and Growth Shuttle, global value creation advisor, angel investor, and author of “MBA Disrupted.”

His original background in engineering rode the wave of IT entrepreneurship in the last 25 years, from product and service entrepreneurship through acquiring and selling businesses, to investing in global startups like beehiiv, doola, the Stacked Marketer, Alcatraz, SeedBlink.

Peshev spent over 10,000 hours in consulting and training contracts for mid-market and enterprise organizations like VMware, SAP, Software AG, CERN, Saudi Aramco since 2006. His books and guides are referenced in over 50 universities in North America, Europe, and Asia.


Follow Mario on social:

Latest Editions:

Latest Answers: