Skip to content

Instantly share code, notes, and snippets.

@aliciaduffy
Last active October 8, 2015 17:08
Show Gist options
  • Save aliciaduffy/3362651 to your computer and use it in GitHub Desktop.
Save aliciaduffy/3362651 to your computer and use it in GitHub Desktop.
WordPress / Preview Link - add login link
<?php
// Show login link if a user visits a preview link and is logged out
remove_action( 'init', '_show_post_preview' );
add_action( 'init', 'NAME_show_post_preview' );
function NAME_show_post_preview($result='', $id = false) {
// if ?preview=true is set
if ( isset($_GET['preview'])) {
$id = (int) $_GET['preview_id'];
if ( false == wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) {
if ( is_user_logged_in() ) {
wp_die( __('You do not have permission to preview drafts.') );
} else {
wp_die('<a href="'. wp_login_url() .'">Log in</a> to see this preview.');
}
}
add_filter('the_preview', '_set_preview');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment