Link to registration page in Wordpress - wordpress

There is
wp_login_url, wp_logout_url, but what what about registration url?
Is there standard way to get link to registration? I need to display a link to registration page with further redirect to previous page.
PS I am using my theme login.

The following will return the registration url:
<?php
echo site_url('/wp-login.php?action=register');
?>
UPDATE:
To get the registration url with a redirect to the current page use:
<?php
echo site_url('/wp-login.php?action=register&redirect_to=' . get_permalink());
?>

Since 3.6, there is now a func:
http://codex.wordpress.org/Function_Reference/wp_registration_url
<?php echo wp_registration_url(); ?>
You can override it with the register_url filter.
add_filter( 'register_url', 'custom_register_url' );
function custom_register_url( $register_url )
{
$register_url = get_permalink( $register_page_id );
return $register_url;
}

I know this is an old question, but for anyone picking it up use wp_register().
It automatically determines if you're logged in and supplies either a link to the admin section of the site, or a link to the register form.
It also respects the settings in Settings -> General -> Membership (Anyone Can Register?)

If I understand correctly you are asking for default Word Press registration page. That would be www.domainname.com/wp-signup.php

<?php echo wp_registration_url(); ?>
https://codex.wordpress.org/Function_Reference/wp_registration_url

2 points here
Make sure you have turn on the "Anyone can register" in the setting page
if you host in a subfolder, make sure you include
Without subfolder:
Register
OR
Register
With subfolder
Register

In case of hosting your wordpress site in a subfolder (e.g.: mysite.com/myblog) you also need to include your site's url as follows:
<?php echo get_site_url() . "/wp-login.php?action=register" ?>
--> http://mysite.com/myblog/wp-login.php?action=register
Otherwise you will be redirected to a non-existing page
--> http://mysite.com/wp-login.php?action=register

1st of all I'm a WP newbe.
wp_registration_url can redirect the new user back to the page he came from, buy without enforcing login on the way (I dont use auto login because i want the user to authenticate the mail).
i use instead (sample with Allow PHP in posts plugin):
Register
hope it helps...

You can use wp_registration_url() any where you want to add link to wordpress registration
to add the redirection url use apply_filters()
<a href="<?php wp_registration_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ); ?>" >click to register</a>

Related

How to Disable Woocommerce My Account Autodirect

I'd like to customize the Woocommerce login/register page using an editor plugin which requires you to be logged into the Wordpress Dashboard. The problem is Woocommerce directs to the My Account page if the user is logged in. Is there a snippet I could temporarily run that will tell Woocommerce to load the login/register page instead of the My Account page if the user is logged in?
I found a solution thanks to a reply Oliver Vogel made to someone else asking the same question here. Thanks Oliver! This is Oliver's Post
For non-technical people like me who are trying to edit the Woocommerce Login / Register page while being logged into the Wordpress dashboard, insert this snippet into the functions.php file preferably with a nice plugin like Code Snippets. It will create a shortcode called [woo-login]. Create a new web page and add the [woo-login] shortcode to it and the Woo login page will open even when you are logged in.
add_shortcode('woo-login', 'my_login');
function my_login() {
if (is_user_logged_in()) {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
} else {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
}
}

Wordpress & Gravity Forms - Why Is My For Only Display Form Admin & Not Post Author On FrontEnd?

I'm building a directory listings website where local businesses can add and edit their listings from the front-end of the website. I'm running into an issue where only administrators are able to view the form on the front end, but the listing author can't. Here is my conditional code:
<?php if(current_user_can( 'edit_others_posts', $post->ID ) || ($post->post_author == $current_user->ID)) { ?>
<?php
echo do_shortcode('[gravityform id="17" update=" '. $post->ID . '" title="false" ajax="true" description="false"]');
?>
<?php } ?>
I was able to find a fix yesterday. Apparently, to allow front-end edits to listings - you have to hook into a gravity forms settings and tell it to do so. Otherwise, non-admins won't be able to view the form.
// Allow gravity form editing on the front end
add_filter('gform_update_post/public_edit', '__return_true');

Wordpress Redirect page

I search several times but I couldn't find nothing that really helps me.
Basically I have a very VERY simple Theme which is working very well.
I also have a database with some IP's and depending by this IP I need to redirect the guest to different pages.
So on my template index.php file I added:
if ($country == "br") {
echo "case1";
} else {
$location = bloginfo('template_url')."/index-nbr.php";
echo $location;
?>
<script type="text/javascript">
window.location= <?php echo "'" . $location . "'"; ?>;
</script>
<?php
}
I tried many different ways to redirect but none of them work. Could someone help me with this stuff?
Ok let me make your life easier.
Just install this plugin you will find a text box on the bottom of every page in PAGES section in Admin panel where you can put your desired link/URL of the page and that will redirect you to your inserted URL.
Page Link to Plugin

How do I make my links in Wordpress not add itself to the existing URL?

I'm guessing there is a simple solution to this, but I can't seem to get my phrasing right when searching for it, so I'll post it here.
I have some links that look like this in Wordpress:
<a target="_blank" href="<?php echo get_post_meta($post->ID, $prefix.'hjemmeside', true); ?>"><?php echo get_post_meta($post->ID, $prefix.'hjemmeside', true); ?></a>
Just regular links that I echo in my single template to create user homepage/facebook etc. The problem is when you click it, the link will just adds itself to the end of the URL:
Example:
wordpress.com/single
when clicking the link:
wordpress.com/single/www.homepagelink.com
Thanks for any help :)
My guess is that wordpress isn't adding anything. If you have the URL without preceding http:// in the custom field it is shown that way by the browser. If you check the generated source code with your browser you will find the code like this:
<a target="_blank" href="www.homepagelink.com">www.homepagelink.com</a>
Without http:// or other valid URL schema this is interpreted by the browser as a relative link and handled as such.
You can either add the http:// in the field value or you place a wrapper function in the functions.php of your theme to make sure it is always interpreted as URL regardless what was put in the field.
function my_field_link($id, $field) {
$value = get_post_meta($id, $field, true);
if (substr($value, 0, 7) == "http://") return $value;
return "http://" . $value;
}
Then you can call this function like this:
<a target="_blank" href="<?php echo my_field_link($post->ID, prefix.'hjemmeside'); ?>"><?php echo my_field_link($post->ID, prefix.'hjemmeside'); ?></a>
Now the link will always start with http://.
Note: If you expect to have other URL schemas in use (https, ftp, scp, etc.) you should adapt the function accordingly.

Woocommerce/Wordpress - Redirect User Login to Homepage

I have searched for the answer to this, used plugins and still nothing works.
I would like users of my site to be redirected to the home page after they login/register.
Currently, the user logs in and is redirected to the my account page.
Woocommerce provides this code, but it failed to work for me:
/*
* goes in theme functions.php or a custom plugin
*
* By default login goes to my account
**/
add_filter('woocommerce_login_widget_redirect', 'custom_login_redirect');
function custom_login_redirect( $redirect_to ) {
$redirect_to = 'http://anypage.com';
}
I have also attempted to use the Peter's Redirect plugin but it does not work since woocommerce bypasses wp-login.php.
Thoughts?
You can download http://wordpress.org/extend/plugins/peters-login-redirect/ and replace this in the widget-login.php
<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo $redirect_to; ?>
with
<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo site_url('/wp-content/plugins/peters-login-redirect/wplogin_redirect_control.php/'); ?>" />
That way you can use peters login redirect to redirect globally and specific users using the woocommerce login widget.
Make sure you change "Use external redirect file. Set this to "Yes" if you are using a plugin such as Gigya that bypasses the regular WordPress redirect process (and allows only one fixed redirect URL). Then, set the redirect URL to %s" in the settings to "YES".
Hope this helps.
Use this code on functions.php
add_filter('woocommerce_login_redirect', 'wc_login_redirect');
function wc_login_redirect( $redirect_to ) {
$redirect_to = 'https://www.google.co.in/';
return $redirect_to;
}
That fix they provide only works if you are utilizing the login widget. All you need to do it redirect the user after logging in to your home page is to add this to your login form:
<input type="hidden" name="redirect" value="<?php echo get_home_url(); ?>" />
There has been a filter recently added to allow you to redirect after registration. Doing a redirect on login is as simple as Tomanow mentions above (putting it in form-login.php). Here is a link to the filter and some instructions for handling this on the registration form.
https://github.com/woothemes/woocommerce/commit/014e31952828377bf7a1ebf4e812a43d0bcefa67#commitcomment-3351995
Use this code on functions.php
add_action('wp_logout','go_home');
function go_home(){
wp_redirect( home_url() );
exit();
}
Do this:
Go to admin > Woocommerce > Settings > General
Find "Customer Accounts" under "Cart, Checkout and Accounts"
Uncheck "Prevent customers from accessing WordPress admin"
Save Changes and test!
You can set redirect according to user role. Given bellow the code for that redirection and I have developed a WooCommerce Login or Register Redirect plugin for entry level user or nor technical or no-programmer.
//Redirect users to custom URL based on their role after login
function wp_woo_custom_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$dashboard = admin_url();
$myaccount = get_permalink( wc_get_page_id( 'my-account' ) );
if( $role == 'administrator' ) {
//Redirect administrators to the dashboard
$admin_redirect = get_option('admin_redirect');
$redirect = $admin_redirect;
} elseif ( $role == 'shop-manager' ) {
//Redirect shop managers to the dashboard
$shop_manager_redirect = get_option('shop_manager_redirect');
$redirect = $shop_manager_redirect;
} elseif ( $role == 'customer' || $role == 'subscriber' ) {
//Redirect customers and subscribers to the "My Account" page
$customer_redirect = get_option('customer_redirect');
$redirect = $customer_redirect;
} else {
//Redirect any other role to the previous visited page or, if not available, to the home
$redirect = wp_get_referer() ? wp_get_referer() : home_url();
}
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'wp_woo_custom_redirect', 10, 2 );
Also include this for standard WordPress login form logins that use wp-login.php:
add_filter('login_redirect', 'custom_login_redirect');
I use this filter and the one you have given, against the same filter function, and it catches the two places where a user may log in (WP and WC).
Also just noticed the obvious problem. You have this in your filter function:
$redirect_to = 'http://anypage.com';
but you need this:
return 'http://anypage.com';
$return_url is passed in from previous filters, so you can inspect it and decide whether to change it.
Edit:
Actually, I need to correct some of this. It looks like the woocommerce_login_widget_redirect filter is used to set the redirect parameter in the widget login form. This means it only fires when the user is not logged in and the widget login form is presented. It cannot be used to decide where to send the user after they have logged in.
The WP login_redirect filter fires after the user has logged in, and can modify any redirect_to URL sent with the login form to enable you to redirect the user to some other page.
In addition, the WooCommerce login widget does not handle the logins that you would assume it does. The login process is handled via AJAX in woocommerce-ajax.php You will see in there that the redirect URL is not passed through the woocommerce_login_widget_redirect filter and so cannot be modified. I'm going to raised this as a pull request with WooCommerce, because I believe it should be filtered.
https://github.com/woothemes/woocommerce/pull/2508

Resources