patronage / bubs-next

Headless Wordpress + Next.js Project scaffolding
https://bubs-next.vercel.app
MIT License
37 stars 10 forks source link

Run `bubs_update_title_prefix` exactly once #290

Open kylehotchkiss opened 1 year ago

kylehotchkiss commented 1 year ago

Prevents issues where this code runs multiple times and prefixes the site name too much


if ($site_prefix) {
    function bubs_update_title_prefix() {
        global $site_prefix;
        $site_name = get_option('blogname');
        $site_name = str_replace(['LOCAL: ', 'STAGING: '], '', $site_name);

        if (strpos($site_name, $site_prefix) === false) {
          update_option('blogname', $site_prefix . $site_name);
        }

        remove_action('admin_init', 'bubs_update_title_prefix');
    }

    add_action('admin_init', 'bubs_update_title_prefix');
}
?>```