The populate_site_meta() WordPress PHP function creates WordPress site meta and sets the default values.
Usage
populate_site_meta($site_id, $meta);
Example: populate_site_meta(1, array('color_scheme' => 'blue', 'logo' => 'https://example.com/logo.png'));
Parameters
$site_id (int)
- Required. Site ID to populate meta for.$meta (array)
- Optional. Custom meta$key => $value
pairs to use. Default:array()
.
More information
See WordPress Developer Resources: populate_site_meta()
Examples
Set default meta values for a new site
This example sets default meta values for a new site with a given ID.
$site_id = 2; $default_meta = array( 'color_scheme' => 'blue', 'logo' => 'https://example.com/logo.png', 'footer_text' => 'Thanks for visiting!' ); populate_site_meta($site_id, $default_meta);
Add new meta value to an existing site
This example adds a new meta value to an existing site.
$site_id = 3; $new_meta = array('newsletter_enabled' => true); populate_site_meta($site_id, $new_meta);
Update an existing meta value for a site
This example updates an existing meta value for a site.
$site_id = 4; $update_meta = array('color_scheme' => 'green'); populate_site_meta($site_id, $update_meta);
Remove a meta value from a site
This example removes a meta value from a site by setting it to an empty string.
$site_id = 5; $remove_meta = array('footer_text' => ''); populate_site_meta($site_id, $remove_meta);
Set multiple meta values for a site
This example sets multiple meta values for a site at once.
$site_id = 6; $multiple_meta = array( 'color_scheme' => 'red', 'logo' => 'https://example.com/new-logo.png', 'footer_text' => 'Copyright © 2023' ); populate_site_meta($site_id, $multiple_meta);