Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Replace Register Link with Function WordPress

  • SOLVED

There are a thousand ways to hack the login pages of wordpress. I am looking for the cleanest way anyone knows of to replace the "Register" link to show a modal instead of leading to the wordpress default page.

So this:

<a href="https://mysite.com/wp-login.php?action=register">

needs to become this:

<a href="#myModal7" role="button" data-toggle="modal">



I do not want to edit any core files, nor make copies of core files.

Answers (4)

2013-02-01

Dbranes answers:

you could check out the filter 'register' to edit the register link

I think it could be something like this:

add_filter('register', 'my_register_link');

function my_register_link($link){
// do some stuff with register link
//
return $link;
}


Kyle comments:

Hi Dbranes, thanks for the reply. Something like this is exactly what I am looking for. I tried this but didn't get a result:

add_filter('register', 'my_register_link');
function my_register_link($link){

$link = '<a href="#myModal7" role="button" data-toggle="modal">Register</a>';

return $link;

}

Link is still directing to /wp-login?action=register


Dbranes comments:


ok, have you tried changing the priority:

add_filter('register', 'my_register_link',99);


Kyle comments:

Thanks for following up

I added the 99 but still no result :(


Dbranes comments:

It looks like the register function wp_register() is not used everywhere.

In wp-login.php we have:

<a href="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login' ) ); ?>"><?php _e( 'Register' ); ?></a>


and

<form name="registerform" id="registerform" action="<?php echo esc_url( site_url('wp-login.php?action=register', 'login_post') ); ?>" method="post">


but not the function wp_register().

But in /wp-includes/default-widgets.php and in some theme's sidebars.php can we find

<?php wp_register(); ?>



Kyle comments:

Okay, yes, I was just looking through the codex too and wondered what it mean when it said included in sidebars. Is there someway to cover both bases?


Dbranes comments:

( if you use the Meta widget, then you get wp_register() )

... maybe some jQuery tricks to edit links with action=register ?


Kyle comments:

Hmm, yeah I am only concerned with the link on the login page unfortunately

I'm not too skilled with jQuery either. I wonder if there is a way to filter/replace the entire #nav paragraph?


Kyle comments:

What about removing the #nav completely with jquery than inserting my link (and the lost password link) into the footer where the back to blog link is with the login_footer hook?


Dbranes comments:

ok, here is a toy example (without jQuery) to replace the #nav html code on the wp-login.php page

add_action('login_footer','my_login_footer');
function my_login_footer(){
echo "<script>
var e = document.getElementById('nav');
var myhtml = '<a href=\"#myModal7\" role=\"button\" data-toggle=\"modal\">Register (modified)</a> | <a href=\"http://example.com/wp-login.php?action=lostpassword\" title=\"Password Lost and Found\">Lost your password?</a>';
e.innerHTML= myhtml;
</script>";
}


Kyle comments:

Okay making progress :)

Very odd result, so when viewing the page markup it looks exactly as it should:

<a href="#myModal7" role="button" data-toggle="modal">


However, the actual link is this:

/wp-login.php?redirect_to=https%3A%2F%mysite.com%2F#myModal7

Strange


Kyle comments:

It works!

I had to re-add the bootstrap js with login_enque_script

2013-02-01

Arnav Joy answers:

see this plugin

http://wordpress.org/extend/plugins/login-with-ajax/

http://wordpress.org/extend/plugins/modal-register/


Kyle comments:

Hi arnav, thanks for the reply.

I do not want to change/replace any current functions. My security software does not work with third party plugins.

Needs to be a function

2013-02-01

Francisco Javier Carazo Gil answers:

Kyle,

I would make a new sign up form with jQuery UI you can show the modal dialog.


Kyle comments:

Hi Javier, thanks for the reply

Cannot change the whole form, that link only


Francisco Javier Carazo Gil comments:

Prepare the sign up form directly in HTML into modal dialog with jQuery UI and prepare a script to make the signup:
$user_id = wp_create_user($name, $password, $email);
if(is_wp_error($user_id))
echo "Username already exists. Please try another one.";
else{
update_user_meta($user_id, 'address', $address);
update_user_meta($user_id, 'first_name', $first_name);
update_user_meta($user_id, 'last_name', $last_name);
}

$from = get_option('admin_email');
$headers = 'From: '.$from . "\r\n";
$subject = "Registration successful";
$msg = "Registration successful.\nYour login details\nUsername: $username";
wp_mail($email, $subject, $msg, $headers);


Kyle comments:

Unfortunately this will remove the form from the scope of my security software which will cause malware and intrusion risks


Kyle comments:

I do not want to change any core functions or alter any existing processes. I only want to replace that link


Francisco Javier Carazo Gil comments:

Kyle,

No, you can use nonce to protect your forms, I don't know what software of security are you talking about.

You can use instead then .htaccess:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^action=register$ [NC]
RewriteRule ^wordpress/wp-login.php$ http://www.example.com/wordpress/register? [L,R=301,NC]

This will redirect http://www.example.com/wordpress/wp-login.php?action=register EXACTLY to http://www.example.com/wordpress/register


Kyle comments:

My security has its own protective measures that I do not wish to circumvent, so I want to stay with the current process.

My server doesn't allow for editing htaccess

2013-02-01

John Cotton answers:

Have you looked at the site_url filter?

apply_filters( 'site_url', $url, $path, $scheme, $blog_id );

You could check in a filter that it was the register link (ie strpos( $url, 'action=register' ) ) and then return your own link the circumstances you want to.

JC


John Cotton comments:

<blockquote>add_filter('register', 'my_register_link');</blockquote>
That filter doesn't always have the registration link in it (checkout the core code to see why) so you should check it before returning.

Site url won't either so you would have to check there too, but it's the place where the actual url is being set so feels (to me at least) like the better place to check/change.


Kyle comments:

Hi John, thanks for the reply

I need the extra part of the link with the data-toggle="modal" part to execute the modal I believe. I don't think that will execute with the $url hook


John Cotton comments:

Fair point.

Register filter it is!