Leave a Reply

1 comment

  1. 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.