admin管理员组

文章数量:1431726

In addition to the normal single post view on my website, I added a full screen version of the post with entirely new set of styles. In this full screen option, everything is removed except the_content() of the post.

I did a functional non standard php template for this purpose called prompter.php and I put it in the root of my site.

In each single post, there is a button called "prompter view" that will trigger the view of the current post in "prompter mode" (full screen mode)

Everything is working OK, until I apply role based permission on my post.

It turns out my full screen mode is not being protected by the role permission set by wordpress.

My question is how can I make my custom post template inherit the permission set on the normal post template?

Here are the example of what I am trying to say.

Single post using normal template (unprotected)

/?p=123

Single post using full screen mode (unprotected)

.php?p=123

Single post using normal template (Protected)

/?p=2193

Single post using full screen mode (still unprotected)

.php?p=2193

It turns out that even there is a restriction imposed on post 2193, if the user will go straight to the fullscreen template and supply the post ID, the post will still be viewable without permission check.

How Can I make my full screen template protected also by WordPress permission settings?

Thanks

In addition to the normal single post view on my website, I added a full screen version of the post with entirely new set of styles. In this full screen option, everything is removed except the_content() of the post.

I did a functional non standard php template for this purpose called prompter.php and I put it in the root of my site.

In each single post, there is a button called "prompter view" that will trigger the view of the current post in "prompter mode" (full screen mode)

Everything is working OK, until I apply role based permission on my post.

It turns out my full screen mode is not being protected by the role permission set by wordpress.

My question is how can I make my custom post template inherit the permission set on the normal post template?

Here are the example of what I am trying to say.

Single post using normal template (unprotected)

http://prompter.rareapps/?p=123

Single post using full screen mode (unprotected)

http://prompter.rareapps/prompter.php?p=123

Single post using normal template (Protected)

http://prompter.rareapps/?p=2193

Single post using full screen mode (still unprotected)

http://prompter.rareapps/prompter.php?p=2193

It turns out that even there is a restriction imposed on post 2193, if the user will go straight to the fullscreen template and supply the post ID, the post will still be viewable without permission check.

How Can I make my full screen template protected also by WordPress permission settings?

Thanks

Share Improve this question edited Apr 24, 2019 at 9:08 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jan 27, 2015 at 0:34 Charles WayneCharles Wayne 2852 gold badges4 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The following bypasses wordpress by not going through index.php:

http://prompter.rareapps/prompter.php?p=2193

I'd recommend that instead of doing that, you place prompter.php in your theme directory and then hijack the page to display when someone clicks the link to view full screen using the template_redirect filter:

function my_special_display_view( $template ) {
    if ( is_page() && isset($_REQUEST['special_view']) ) {
        global $post;
        $post_id = $post->ID;
        $new_template = locate_template( array('prompter.php') );
        if ( !empty( $new_template ) ) {
            $template = $new_template;
        }
    }
    return $template;
}
add_filter( 'template_include', 'my_special_display_view', 99 );

This assumes a couple of things:

  1. Your links to your special view look like http://.../?p=2193&special_view=1
  2. Your prompter.php file uses wordpress internals to do things
  3. prompter.php is in the theme root directory

You might need to unenqueue your normal style sheet and queue up another in the same place that you do $template = $new_template;

add_action('wp_enqueue_scripts', 'do_change_styles_significantly', 11);

and a function to go with it:

function do_change_styles_significantly() {
    wp_dequeue_style( HOOK_FOR_YOUR_THEMES_STYLESHEET );
    wp_register_style( 'special_shiny', full_url_to_alternate_styles, array(), '1.0.0', 'all');
}

A bit more complicated, but it would be done within wordpress and give you what you are looking for.

本文标签: Single post full screen template not inheriting WordPress role permission