Skip to content

Instantly share code, notes, and snippets.

@messica
Created August 27, 2015 20:18
Show Gist options
  • Select an option

  • Save messica/a431d3c5fde3e7b1fa45 to your computer and use it in GitHub Desktop.

Select an option

Save messica/a431d3c5fde3e7b1fa45 to your computer and use it in GitHub Desktop.
Redirect to last post viewed instead of confirmation page
<?php
/*
* Remember last post ID
*/
function my_wp() {
global $post, $pmpro_pages;
//don't track pmpro pages
if( ! in_array($post->ID, $pmpro_pages))
setcookie('last_post_viewed', $post->ID, null, '/');
}
add_action('wp', 'my_wp');
/*
* Change login link in confirmation email to append last viewed post
*/
/*
* Redirect to last post instead of Confirmation page
*/
function my_pmpro_confirmation_url($url, $user_id, $level) {
if(!empty($_COOKIE['last_post_viewed']))
$url = get_the_permalink($_COOKIE['last_post_viewed']);
return $url;
}
add_filter('pmpro_confirmation_url', 'my_pmpro_confirmation_url', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment