Custom function is interrupting cornerstone preview - any help?

Hello there,

I have a small problem. While creating a custom template, I needed to create a function that checked if the user is logged in and of a certain role. If they aren’t, they will be booted to the registration page.

So All I am doing is checking for login and say… the role of subscriber. If they do not meet this criteria, they are shunted off to another page via a header reference.

However, when adding content in cornerstone, the preview will not load. I don’t have a problem using the wireframe builder they have, but my client will likely not like it.

Does anyone know of a better way so I can have my cake and eat it too?

The below link should help you with this.

Rather than a redirect you force the user to login to view the content on that template.

One of the examples can be shown below:

<?php
	/**
	 * Template Name: Login
	 * The template for Employee Login form
	 **/
	if(have_posts()) :
		get_header();
		// If the user is logged in, show them the content
		if( is_user_logged_in() ) :
			while(have_posts()) :
				the_post();
				the_content();
			endwhile;
		// If the user is not logged in, force them to log in
		else :
			wp_login_form();
			echo '<p id="loginnav">';
			wp_register( '', ' | ' );
			echo '<a href="';
			bloginfo( 'wpurl' );
			echo '/wp-login.php?action=lostpassword" title="Password Lost and Found">Lost your password?</a></p>';
		endif;
		get_footer();
	else :
		header( 'Location: ' . esc_url( home_url( '/' ) ) . '/404' );
	endif;
?>

@flaming - Thanks for your help! I like how you really take the time and effort!

The issue I was having (and have given up on it since) was to do with roles. I didn’t want admin level to see a page, but a member level (say subscriber to see it). While I was able to preview the page using ‘preview’, I could not work out a way to preview within Cornerstone, as being logged in as admin and not subscriber would redirect me.

Anyway, no biggie, I have since given up on that weird function (weird in hind sight!).

Regards,

Felix

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.