Redirect to the referrer URL with CRED

Let’s assume you have a CRED Form on a Post or Page, which is appearing on several different Posts or pages (via content template as for example), and you want to be redirected to the Page/post where the CRED form is present, after submitting it.

One possibility is to “Keep display this form”, but that will also keep display the success messages and so on

Therefore you need a dynamic redirect to the Referrer URL.

This can be done with the WordPress function wp_get_referer()

Example:

add_filter('cred_success_redirect', 'custom_redirect',10,3);

function custom_redirect($url, $post_id, $form_data) {
  //Only if the Form is ID 54
  if ($form_data['id']==54) {

   //Populate a variable $redirect with the referrer URL
    //see https://codex.wordpress.org/Function_Reference/wp_get_referer
    $redirect = wp_get_referer();
    if ($redirect) {
      return $redirect;
    }
    else {
      die;
    }
  }
}

 

Ticket:
https://wp-types.com/forums/topic/cred-form-back-1-page-on-submition/

Enable Persistent Browser Language Redirection

From https://wordpress.org/support/topic/plugin-wpml-multilingual-cms-remember-browser-language-cookie-not-working

Go to plugins/sitepress-multilingual-cms/res/js/jquery.cookie.js

From line 34 you ca see that:

var days= options.expires, t = options.expires = new Date();
				t.setDate(t.getDate() + days);

Change to this :

var t = options.expires, t = options.expires = new Date();
var minutes = 60;
t.setTime(t.getTime() + (minutes * 60 * 1000));

Where : var minutes = 60 are the minutes you want until cookie expiration.

Redirect Old Domains

add_action( 'wp_loaded', 'redirect_old_domains' );
function redirect_old_domains() {
	
	// Get the referring URL
	$the_link = esc_url( $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] );
	
	// Strip the link
	$the_link = str_replace( array( 'www.', 'http://', 'https://' ) , '' , $the_link ); 
	
	// Redirect the link
	if( $the_link == 'mydomain.es/faq.aspx' ) {
		wp_redirect("http://www.mydomain.es/faq/");
		exit();
	}

}

This code will hook into wp_loaded, detect the referring domain and redirect the link if it matches similar to how Redirect 301 in .htaccess would work.

Example Scenario:

Client wants to use WPML as “A different domain per language”. Has domains that were once non-WordPress websites and wishes to redirect old URLs to the proper language domains.

The main issue with the Redirect 301 route is it’s sharing the same .htaccess file and all domains point to the same WordPress install.

For instance, if the main domain is mydomain.com then typically we have a line for the .es domain in .htaccess:

Redirect 301 /faq.aspx http://www.mydomain.es/faq

The main English domain mydomain.com/faq.aspx will end up going to http://www.mydomain.es/faq and the same for the other domains.

Hooking through wp_loaded resolves the issue, allowing the client to redirect as many old URLs from multiple domains to the new WordPress website.