Do not set header
in a template file. Those are part of the HTTP request itself.
About your problem:
Add a template (whatever file you need – see “Template Hierarchy”). On top of it you include the default stuff like get_header();
and so on. For the restricted part, you use the following:
if ( current_user_can( 'view_players_area' ) )
{
// Code that you want to show to logged in users
// with a capability of `view_players_area`
}
else
{
# @link http://queryposts.com/function/wp_login_form/
wp_login_form();
}
Related Posts:
- Add, edit specific CPT with custom role
- Explanation of User Roles and Capabilities
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Disable posts, only allow to edit existing pages, not create new ones (create_posts)
- Authentication / login mechanism (non wp-admin)
- Is there a simple way to manage capabilities per user?
- Why is unfiltered html allowed in custom fields for author / contributor roles?
- How to check if a role has a specific capability
- Different Admin Theme – Based on Role?
- How to remove sticky post capability for a specific user role?
- How can I have different groups of editors only allowed to edit certain parent+subpages?
- Remove wordpress author’s capability to moderate comments on their own posts
- Can you set a role as author?
- WordPress Local Install Theme Folder Permission To Edit
- Are User Levels Still Currently Used?
- Roles for Custom Post Types
- Applying roles to an admin sub-menu (eg Appearance -> Menus)
- What are the minimum role/permissions for freelance developer?
- Limit number of users a role can create
- Question regarding WP multisite feature
- How to change footer or for different kinds of users in wordpress?
- Hiding custom theme functionality using capabilities
- User Capabilities are not available in WP REST permission callback?
- If user is logged in and has a role echo statement
- How to hide plugin options for editors via functions.php
- Show only pages you are author of
- Why “Mine” is the default view when adding ‘capability_type’ in register_post_type
- See which user role / capability is needed to use a plugin
- Force “submit for review” on update?
- current_user_can() returning true for capability when the user and role do not have the capability
- How might I enable a user to view Draft pages from a different Author, without the ability to edit?
- How can I enforce user to use Application password to generate JWT token? [closed]
- What is the preferred way to add custom javascript files to the site?
- Should I use set_transient or update_option?
- Custom Taxonomy Tree view
- Add a preview to a WordPress Control Panel
- Change text of twentyseventeen_edit_link()
- wp_insert_post breaks rewrite rules
- Where can I find a good reviewed collection of Twenty Ten child themes?
- How do I remove RSS feeds from themes?
- How to add (css) classes to only one wp_nav_menu()?
- Advantages of using instead of wp_enqueue_style()?
- Style.css redirects to 404 Page not found
- How to get all users with Author role capabilities?
- How to add suggest plugin to theme?
- When developing a distributable Theme, does it HAVE to be “inheritable”?
- Relative Time On Posts
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- Prevent update check for specific theme
- Multiple Authors on Single Post
- How to add font in wordpress
- Implement content-nosidebar.php / content-leftsidebar.php
- How to change i18n/l10n of #reply-title? (Old title: Comment reply link not working)
- Managing Users and Creating Groups [closed]
- How to call WooCommerce update cart function programatically
- How to get an array of user roles with or without a specific capability?
- How to restrict CPT post’s fronted view only for specific user roles?
- Lightweight framework [closed]
- What are the Entry classes for?
- Using an if statement in the theme customizer page
- Custom markup with wp_nav_menu based on pages
- How to edit my theme for full width?
- What VSCode extensions are there for working with block themes? [closed]
- What is the “correct” way to add hooks or similar PHP behavior to a blocktheme?
- Fetch wordpress video attachment with post ID
- Access to CPT but not to ‘post’ post type
- Echo all category names, apart from one
- Is it possible to visually group items on the theme customizer?
- How can I develop multiple widgets for a WordPress theme?
- Is there a way to optionally hide the title bar when logged in?
- How to create first post, fifth post full width, rest in three columns and so on
- How to Create custom xml file for demo content for custom theme?
- post_exists returning 0 if title contain special characters
- Theme not showing up
- How can I compare publish and update dates for a single post?
- Displaying the right content on a page url
- Adding a new setting using Kirki or WP customizer with an if statement
- Custom admin logo not showing after wordpress 4.5 upgrade
- Unable to change the priority with ‘remove_action’ and ‘add_action’ in child theme
- Translate a child theme with pure PHP and gettext
- Pagination: Keep prev and next link even on the first/ last page
- Is there a way to serve different resolution images to different devices?
- How to substitute old wordpress menu by wp 3 menu the right way?
- Why my theme option not working?
- Catch the moment when theme is deleted
- Attribute form NumberControl doesn’t update when I update page before it lose its focus
- Next and previous post link shows error in first and last post
- create loop for the_content()
- Media & Plugin screens stall
- Is wp_mail plugin territory?
- HTML TO WP Theme : Submenu goes down wp_nav_menu
- How do I remove p tag *insertions*? Disabling `wpautop` removes manual tags
- Create a variable with string, array or multiple values
- How can I include the js and css file of my custom theme dynamically in header.php
- What hook to use for loading a custom class extension during Theme initialization?
- Set start page depending on screen width [closed]
- How can I change the title of the Home link in the navigation bar?
- What is the advantage of using home.php over index.php for the front page
- Add option for administrator to submit link
- WordPress search field won’t get wider