Skip to content

Instantly share code, notes, and snippets.

@chriscarr
Last active December 13, 2019 18:35
Show Gist options
  • Save chriscarr/85650a318445319946606ae6460fa002 to your computer and use it in GitHub Desktop.
Save chriscarr/85650a318445319946606ae6460fa002 to your computer and use it in GitHub Desktop.
Save some WordPress site options as site meta to make site queries easy
<?php
// 🥕 Carrot
// To make the transition easy from site options to
// site meta for specific options we want to easily
// query, this idea will automatically duplicate
// specific site options to site meta and keep in sync.
// NOTE: this is an idea expressed in sudocode
add_filter('update_option', function($option, $old, $new) {
$options_whitelist = ['theme', 'classic-editor', 'site-template'];
if (in_array($option, $options_whitelist)) {
update_site_meta(get_current_blog_id(), 'carrotstuff-' . $option, $new);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment