1

So now I have finally found plugins for social network login that works on my web hotel. (The Nextend plugins.) :-)

I have set "users must be registered and logged in to comment" on the main site (this is a multisite). Works nicely on the main site.

Unfortunately this is not carried over to the subsites. How do I force this on the subsites too? (Without having to do it manually.)

One more little problem (which I think is easier to solve): I want only the social plugin login on the login pages. Is there a really easy way to do that?

UPDATE: Solved. Can be done by adding a filter for the "comment_registration" option. See

https://codex.wordpress.org/Plugin_API/Filter_Reference/pre_option_(option_name)

Sorry for the noise.

  • 1
    can you please add your solutions as an answer and accept it. – Pieter Goosen Mar 27 '14 at 6:54
  • Ah, yes, it seems possible now. Will do later. ;-) – Leo Mar 27 '14 at 11:49
  • Great, and enjoy the new badge. – Pieter Goosen Mar 27 '14 at 11:54
  • Those badgets come and go. Anyway I did have enough points to answer. ;-) – Leo Mar 27 '14 at 18:46
2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.