wpf_redirect_url

#Overview

This filter is run when a user is redirected from a restricted post or page. It can be used to override the redirect configured in the WP Fusion meta box. To use the code examples below, add them to your active theme’s functions.php file.

#Parameters

  • $redirect: Represents the URL the user will be redirected to.
  • $post_id: Post ID for the post being requested.

#Examples

#Send logged out users to a login page, and send logged-in users to upsell pages based on their applied tags

Say you have a page, “Level 2 Membership Content”. This page has “Restrict Access” checked and requires the “Level 2 Member” tag to view the page. Configure the redirect in the meta box settings on the “Level 2 Membership Content” page to point your login page.

This will redirect all users who either don’t have the “Level 2 Member” tag, or any logged out users, to the login page. However if a user is already logged in, we may want to modify the redirect depending on their membership level.

The code below redirects users who don’t have the tag “Level 1 Member” to the sales page for Level 1 Membership. It redirects users who don’t have the tag “Level 2 Member” to the sales page for Level 2 Membership.

function wpf_redirect_users( $redirect, $post_id ) {

	// Go to the default redirect (the login page) for non-logged in users
	if ( ! wpf_is_user_logged_in() ) {
		return $redirect;
	}

	// If they don't have the tag Level 2 Member, go to the Buy Level 2 Membership page
	if ( ! wpf_has_tag( 'Level 2 Member' ) ) {
		return 'http://mysite.com/buy-level-2-membership';
	}

	// If they don't have the tag Level 1 Member, go to the Buy Level 1 Membership page
	if ( ! wpf_has_tag( 'Level 1 Member' ) ) {
		return 'http://mysite.com/buy-level-1-membership';
	}

}

add_filter( 'wpf_redirect_url', 'wpf_redirect_users', 10, 2 );

Was this helpful?