Experience the powerful AI writing right inside WordPress
Show stunning before-and-after transformations with image sliders.
Improve user engagement by showing estimated reading time.
Written by saedul
Showcase Designs Using Before After Slider.
When managing a WordPress multi-site network, efficiently handling settings and configuration data across multiple sites becomes critical. The WordPress Options API for multi-site offers developers a streamlined, secure, and standardized way to store, retrieve, and update site options that affect either individual sites or the entire network. Understanding how the Options API works in a multi-site context, including its different types, empowers you to create robust multi-site plugins and themes with consistent settings management.
This article will explore the WordPress Options API for multi-site, its types, and best practices for working with it to manage options effectively across networks and sites.
The WordPress Options API is a set of functions designed to store and retrieve settings or configuration options in the WordPress database. Options are stored in the wp_options table for a single site and can be used to save various data, from simple flags and text values to complex serialized arrays.
wp_options
In a multi-site environment, WordPress introduces additional considerations because each site has its own options table, and there is a network-wide options table called wp_sitemeta. This requires developers to be mindful of where and how options are stored.
wp_sitemeta
The Options API for multi-site extends the basic options system by providing functions that work with both individual site options and network (site-wide) options. This distinction allows you to store options specific to a single site or shared across all sites within the multi-site network.
wp_2_options
This separation is essential for managing settings at the right scope.
When working with the WordPress Options API for multi-site, there are primarily two types of options you need to understand:
These options are saved and retrieved for a single site within the multi-site network. Each site has its own options table, and the standard Options API functions work on these site-specific options.
get_option( $option, $default = false )
update_option( $option, $value )
add_option( $option, $value )
delete_option( $option )
These functions operate on the current site’s options table. When called within the context of a specific site, they affect only that site’s data.
Network-wide options apply to the entire multi-site network. These options are stored in the wp_sitemeta table and are shared across all sites.
get_site_option( $option, $default = false )
update_site_option( $option, $value )
add_site_option( $option, $value )
delete_site_option( $option )
These functions allow you to manage options that affect the whole network, such as network settings for a plugin or theme.
When building plugins or themes that support multi-site, it’s crucial to decide whether your options should be site-specific or network-wide. Here are some practical tips:
get_option()
update_option()
get_site_option()
update_site_option()
// Update a site-specific option for the current site update_option( 'my_plugin_setting', 'value_for_this_site' ); // Get a site-specific option $site_setting = get_option( 'my_plugin_setting', 'default_value' ); // Update a network-wide option update_site_option( 'my_plugin_network_setting', 'value_for_all_sites' ); // Get a network-wide option $network_setting = get_site_option( 'my_plugin_network_setting', 'default_value' );
Q1: Can I use get_option() to retrieve network-wide options in a multi-site setup?No, get_option() retrieves options from the current site’s options table. To get network-wide options, you should use get_site_option().
Q2: How do I delete a network-wide option?Use the delete_site_option( $option ) function to remove an option from the network-wide options stored in the wp_sitemeta table.
Q3: Are network options accessible to all sites in the multi-site network?Yes, network options are stored centrally and accessible by all sites, making them perfect for settings shared across the entire network.
Q4: Can plugins store both site and network options?Yes, many plugins use site options for per-site settings and network options for global configurations, allowing flexible and scalable plugin settings management.
Q5: How does WordPress handle option caching in multi-site?WordPress caches options per site, and network options are cached separately. This caching improves performance by minimizing database queries.
The WordPress Options API for multi-site provides a powerful, flexible way to manage settings and configurations across both individual sites and entire networks. By understanding the types of options site-specific and network-wide and using the appropriate API functions, developers can build scalable, maintainable multi-site plugins and themes. Following best practices such as prefixing, sanitizing data, and caching ensures a secure and efficient multi-site environment.
This page was last edited on 29 May 2025, at 9:33 am
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
How many people work in your company?Less than 1010-5050-250250+
By proceeding, you agree to our Privacy Policy