Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How do I force “users must be registered and logged in” on subsites?

Here is what you do to force registration on sub sites:

/**
 * Require registration for comments on subsites too.
 */
function ourcomments_pre_option_comment_registration( $value )
{
        return 1;
}
add_filter( 'pre_option_comment_registration', 'ourcomments_pre_option_comment_registration', 10, 1 );

To only show social buttons for login something like this can be used:

/**
 * Hide login fields. Only social logins.
 */
function ourcomments_only_social_logins_login_form() {
?>
  <script type="text/javascript">
(function() {
    // Some things seems to be added later, hide them. And display site name.
    var cssHide = "";
    cssHide += "div#login h1 a { background:none; text-indent: 0; font-size: 30px; font-weight: bold; width: auto; height: auto; color: black; }";
    function checkAndRemove(el) {
        if (el) {
            var elP = el.parentElement;
            if (elP && "P" !== elP.nodeName) elP = elP.parentElement;
            if (elP && "P" === elP.nodeName) {
                elP.parentElement.removeChild(elP);
            }
        }
    }
    checkAndRemove(document.getElementById("user_login"));
    checkAndRemove(document.getElementById("user_pass"));
    // checkAndRemove(document.getElementById("rememberme"));
    cssHide += " div#login form#loginform p.forgetmenot { display:none }";
    // checkAndRemove(document.getElementById("wp-submit"));
    cssHide += " div#login form#loginform p.submit { display:none }";

    // Remove lost password (looks easily breakable...):
    var navLostPassword = document.querySelector("div#login p#nav")
    if (navLostPassword)
        navLostPassword.parentElement.removeChild(navLostPassword);
    else {
        console.log("p#nav not found");
        cssHide += " div#login p#nav { display:none }";
    }

    // For Nextend:
    var nextendOr = document.querySelector("div#login form#login-form h3");
    if (nextendOr)
        nextendOr.replaceChild(document.createTextNode("Please login!"), nextendOr.firstChild);
    else {
        console.log("h3 not found");
        cssHide += " h3 { display: none; }";
    }
    var s = document.createElement("style");
    s.appendChild(document.createTextNode(cssHide));
    document.body.appendChild(s);
})();
  </script>
<?php
}
add_action('login_form', 'ourcomments_only_social_logins_login_form', 1000);
add_action('register_form', 'ourcomments_only_social_logins_login_form', 1000);
add_action('bp_sidebar_login_form', 'ourcomments_only_social_logins_login_form', 1000);

Since the plugins for social buttons do not place those on sub sites you probably want to login through the main site:

/**
 * Login through main site.
 * Mostly a copy of the wp_login_url in general-template.php.
 * Fix-me: move to plugin.
 */
function ourcomments_network_login_url($login_url, $redirect) {
    $net_login_url = network_site_url('wp-login.php', 'login');

    $my_redirect = $redirect;
if ( empty($my_redirect) )
            $my_redirect = $_SERVER['REQUEST_URI'];
if ( !empty($my_redirect) )
    $net_login_url = add_query_arg('redirect_to', urlencode($my_redirect), $net_login_url);

    // We do not have the $force_reauth arg but we know how it looks in the url.
    $values = parse_url($login_url);
    $query = $values['query'];
    parse_str($query, $output);
    if ( $output['reauth'] )
    $net_login_url = add_query_arg('reauth', '1', $net_login_url);

return $net_login_url;
}
add_filter('login_url', 'ourcomments_network_login_url', -100, 2);

This can be added to a themes functions.php. Or put in a plugin (which I did not have time to do yet).

Maybe I should add that a malicious user could still try to get in another way. This is just to make normal users more comfortable.

Related Posts:

  1. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  2. How to customise wp-login.php only for users who are setting a password for the first time?
  3. Disabling standard registration login with username/email and password?
  4. Problem in auto login after registration
  5. Login user after registration programmatically
  6. How can I redirect user after entering wrong password?
  7. Separate registration and login for different roles
  8. SSO / authentication integration with external ‘directory service’
  9. How to prefill WordPress registration with social details
  10. Custom login form
  11. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  12. How do I change the language of only the login page?
  13. Disable WordPress 3.6 idle logout / login modal window / session expiration
  14. Woocommerce registration page [closed]
  15. Avoid to load default WP styles in login screen
  16. WordPress registration message
  17. How to fake a WordPress login?
  18. How build a custom login/register form with error handling?
  19. Can not login with correct username and password
  20. How to remove the WordPress logo from login and register page?
  21. How can I add a custom script to footer of login page?
  22. Login email after registration never sent or received
  23. How to keep always logged in development environment
  24. custom login page redirect to logged in user profile page
  25. How do I check if a post is private?
  26. Receiving “This content cannot be displayed in a frame” error on login page
  27. Action wp_login_failed not working if only one field is filled out
  28. How can I do customizations on login, registration and password recovery forms?
  29. What hooks should I use for pre-login and pre-registration actions?
  30. WordPress Login Footer URL
  31. Remove built in wordpress login and use only google auth
  32. Change Login Page for a Multisite Subsite
  33. Redirect user after login/registration globally
  34. Positioning the “Lost your password?” and “← Back to Site”
  35. send users logging in from wp-login.php directly to home page of site, rather than dashboard
  36. How to get login data (session) outside WordPress?
  37. Change register form action url
  38. Problem with logging in WP users automatically
  39. Is it possible a one click user registration with Facebook or Twitter (or other Social Networks)?
  40. Register/Login using only phone number?
  41. Add class to input form in login form
  42. Allow access to a page for admins only
  43. Customizing login error messages
  44. Customizing the WordPress login form
  45. Restricting frontend acess based on user role otherwise redirect to login form
  46. Force users to register in order to view website [duplicate]
  47. how to restrict user login whenever if a user puts on hold by editing wp-login action?
  48. deny IPs from wp-login using .htaccess
  49. auto login after registeration for wp-members plugin
  50. Passing username to login screen
  51. Login error redirecting to wp-login page
  52. How To Change Wp Register/Login URL Permanently To My Custom Page
  53. How can I prevent my custom form from redirecting to wp-login?
  54. reset password link redirect to login page
  55. How do I replace “Username” in the WordPress login form?
  56. Custom Login iframe doesn’t work
  57. Password reset – Disabled for LDAP accounts
  58. How to Get Logged-in to “Remote WP Site” from my local script (in Same Browser)?
  59. Replace dash with space in username on login
  60. Autologin only working the second time
  61. replace wp-login.php login forms via a hook & use custom forms with wp-login form validation
  62. How to modify the action attribute of the wp-login.php?action=register form?
  63. Correct passwords keep appearing as incorrect
  64. Auto login between word press subdomain and a .net website
  65. Login form doesn’t log in
  66. Get the url of custom login page in the registration page
  67. How to change wordpress Log In text
  68. WordPress error on log out ‘Not Permitted’ and can’t log out
  69. Redirect wp-login
  70. By registering always make uppercase the first letter of the login
  71. Show reCaptcha on Custom Frontend Login & Register Form [closed]
  72. Best option to implement external register/login to WP from self-made API
  73. Auto Login After Registration
  74. Disable all other page except index,register,login till user login
  75. Is wp_login_form secure on a non secure page?
  76. Is the login encrypted before it is sent? If so how to do I encrypt it the same way?
  77. What speaks against using a custom login.php / register.php to wordpress?
  78. Form Action submit over https
  79. Is there anyway to get the inputted password string from the login form?
  80. Login and Forgot password in Lightbox
  81. Forcing frontend login with UI switch
  82. How do I add Login fields and registration link to the header?
  83. How to make a user be able to register if such a login already exists?
  84. Prevent display password on wp-login.php
  85. Change default login auth
  86. wordpress login without password just email address (NO 2 factor authentication with email)
  87. Sending new registration meta values to admin by email
  88. WordPress SSL not working [closed]
  89. Where is the php file, that does the checks for login information?
  90. Are login functions considered part of the WP backend?
  91. WordPress registration page template
  92. Removing “public” user registration without completely turning it off?
  93. Cannot Get User id after login success in file wp_login.php
  94. Disable registration on certain condition
  95. Alert Message through email or phone(Message)
  96. what is the best and safest way to allow users to register to site
  97. Moving from one host to another – cannot access the dashboard
  98. Temporally disable password to login with empty password?
  99. How are all users now set to inactive?
  100. woocommerce store login not working at first time
Categories login Tags login, user-registration, wp-login-form
Our shortcode dropdown box in Tinymce is not working in WordPress 3.9?
How to unset comment_notes_before field in WordPress comment_form

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress