multisite hook for Add Existing User

There’s one called added_existing_user that fires immediately after adding an existing user. Digging a little deeper, I find the function add_user_to_blog() is used by both add_new_user_to_blog() and add_existing_user_to_blog(), and has an action hook named add_user_to_blog. I’d look into using that last hook, if I wanted to ensure something happened when a user was added to … Read more

How to set “Site Address (URL)” programmatically on WP multisite?

If you just want to update that one value, then you can use wp_update_site(): wp_update_site( 123, [ ‘domain’ => ‘new-slug.domain.com’, ] ); But to really update the site URL/address, you’d need to update both the siteurl and home options for the site: switch_to_blog( 123 ); update_option( ‘siteurl’, ‘new URL here’ ); update_option( ‘home’, ‘new URL … Read more

current_user_can() always returns true if user is super admin

The documentation unfortunately not very clear on what “explicitly deny” actually entails. While setting a capability to false will normally explicitly deny the capability, that check is performed after super admins have been waved through. So even though the documentation says “unless explicitly denied”, denying it this way doesn’t work for super admins. Only the … Read more

Custom php page outside the scope of my theme

is this not something that you could put into your functions.php file as a new function, adding the action to init to fire off on the page load? You could then put in an if statement so it only runs when specific criteria is met, such as a page ID or slug or template is … Read more

Cannot access WordPress Multisite Main Dashboard

You can gain super admin access to the site by adding this function in the functions.php file if ( !function_exists( ‘grant_super_admin’ ) ) { require_once ABSPATH . WPINC . ‘/capabilities.php’; } // ID of the user to be granted Super Admin privileges. $user_id = 1; $result = grant_super_admin($user_id); You can remove the code once you … Read more