The wpmu_new_blog Hook in WPFTS

The wpmu_new_blog hook is a WordPress Multisite-specific hook that fires when a new blog (site) is created in the network. WPFTS uses this hook to activate the plugin and initialize its settings and database tables for the new blog.

What WPFTS Does When wpmu_new_blog is Called:

  1. Network-Wide Activation Check: The plugin checks if it’s activated for the entire Multisite network using the is_plugin_active_for_network() function.

  2. Plugin Activation for the New Blog: If the plugin is activated network-wide, WPFTS calls its _activate_plugin() method for the new blog. This method creates the necessary database tables and sets default option values. It’s important to note that switching to the new blog is done using switch_to_blog() and back using restore_current_blog() to avoid conflicts.

Important Functions Involved in Handling wpmu_new_blog:

  • is_plugin_active_for_network()

  • switch_to_blog()

  • WPFTS_Core:: _activate_plugin()

  • restore_current_blog() (implicitly, after the handler completes)

How to Use This in Addon Development:

Developers of Multisite-compatible addons should be aware that WPFTS automatically activates for new blogs in the network. If your addon also requires separate activation for each blog, you can use the wpmu_new_blog hook to perform the necessary actions.

Additional Notes:

  • The wpmu_new_blog hook handler only executes in a WordPress Multisite environment.

  • WPFTS is only activated for a new blog if it’s activated network-wide.