Create rewriterules for different domains in htaccess file with WP multisite

If you wanted to target a specific domain then you need a condition (RewriteCond directive), preceding the RewriteRule that checks for the specific domain (Host: header). For example: RewriteCond %{HTTP_HOST} ^domainb\.com [NC] RewriteRule ^i-like-([a-zA-Z0-9-]+)/$ wp-content/themes/customtheme/custom-pages/ilike.php?like=$1 [L] The HTTP_HOST server variable contains just the Host: header sent in the request. Reference: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

Assign role to user on first login, if they are first (after admin)

To set is the connected user belongs to the blog, you need to do that on hook wp_login that means the user is connected : const ROLE_ADMINISTRATOR = “administrator”; const ROLE_CONTRIBUTOR = “contributor”; add_action(“wp_login”, function ($user_login, \WP_User $user) { if ( !is_multisite() || is_user_member_of_blog() ) { return; } $usersAdministrator = get_users([ “role” => ROLE_ADMINISTRATOR, ]); … Read more

Rest API Multisite Site List?

There is no built-in endpoint for sites on a multisite network. As can be seen in the documentation, the built-in endpoints are: +—————-+——————-+ | Posts | /wp/v2/posts | +—————-+——————-+ | Post Revisions | /wp/v2/revisions | +—————-+——————-+ | Categories | /wp/v2/categories | +—————-+——————-+ | Tags | /wp/v2/tags | +—————-+——————-+ | Pages | /wp/v2/pages | +—————-+——————-+ | … Read more

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

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)