admin_init
runs on admin pages, not the front end. The equivalent front end action, init
, is too early to check is_page
. A safe action for redirection is template_redirect
:
function xyz() {
if( is_page( 172 )
&& ! current_user_can('update_core') ) {
wp_redirect( home_url() );
exit;
}
}
add_action( 'template_redirect', 'xyz' );
Related Posts:
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- Restrict dashboard access for specific user roles to specific actions
- Redirect admin 403 “Cheatin uh?” admin pages
- Redirect non-admin after login, and in url – /admin
- How do I remove dashboard access from specific user roles?
- Can an admin check passwords of registered users?
- Prevent author from changing their posts if admin has modified
- How to remove administrator role in settings -> general -> New User Default Role?
- Redirect Admin User in Dashboard
- Create un-removeable user
- Custom CSS In Admin Only For Certain Roles
- Remove ability to access certain admin menus
- Remove admin AND editor from the “change role to” menu in user listing
- Customize the upload screen
- Blocking Administrative Access to Authors and Subcribers?
- Customize Admin Users Screen based on Role
- Make certain pages uneditable by editors?
- How to display only logged in user’s post comments in comments area
- how to redirect to url.com/wp-admin if url.com/admin is typed in?
- Change the Default Pages Menu View in wp-admin
- How can I restore admin capabilities?
- Protect custom php file with login
- Admin page redirect to another admin page
- What determines whether admin toolbar is shown to a logged-in user?
- front end editing using iFrames, best approach?
- How do you set up a WordPress blog with multiple authors to allow something like StackExchange’s “community wiki” feature?
- Displaying different in-page content to cliente/admin
- WordPress Admin Login Redirect Problem
- How to hide a specific part of dashboard for non-admin roles?
- WordPress administrator area access disabled temporarily due to widespread brute force attacks
- WordPress Remove Submenus
- Redirect in an Admin page
- Redirect from the dashboard to edit.php if wp_is_mobile() is true
- Create a WordPress administrator without access to back-end
- Only Admin can Edit, Delete or Update
- add_cap for editor but no admin role
- Shared account / dual blogging in WordPress
- Bind custom role to admin page
- Access for adding subpages but not for pages
- remove menus for a specific role?
- Can’t login to my admin area
- Allow admins to login as other users
- current_user_can(‘administrator’) not working in custom login
- Show global Message in User Profiles with admin only Input field in WordPress Backend
- How to make sure your admin doesn’t hi-jack you site?
- Redirect public site to another one but allow administrators to access the old site
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- How should I setup the “Users” area to hand over to a client?
- solution to prevent specific admins from altering site contents
- Admin user roles/permissions
- Posts in sidebar only by admin
- How To Remove Import/Export Option From Tools?
- Doesn’t call user information to include “wp-load.php” in an external php file
- Hide top admin panel for non admin and non editors
- How can I create multiple different admin roles with their own capabilities
- ‘Conflict’ with action deleted_post and is_admin()
- Signed-in as admin on just part of the site
- Different role for free and pro users in wordpress without using bbpress
- Capability to read/edit page in wp-admin only for administrators
- WP Logs me out after updating anything on dashboard
- You do not have permission to access this document on form submit
- Different customer login form than administrator login form?
- How to save dismissable notice state in WP 4.2?
- Notification that the admin is online
- Disable all https in WordPress
- Limit access to posts/pages by user roles
- Is there a hook to put stylesheet and/or JS inside iframes (thickbox or tinyMCE) in admin area
- Thickbox hacking – removing fields
- WordPress last login foreach user
- custom tabs in media uploader
- How to customize this automatic slug shortener with an overrwrite function
- Hide content-box on specific pages (in admin)?
- Is there a way to set the user Role based on email domain
- How to customize wp_signon()
- Admin Notices coding standard issue
- user-new.php less detailed after WP3.1; how to revert?
- How can I remove the “updates” menu in the WordPress Admin panel?
- How do I change Administrator to Super Administrator
- Remove Admin sidebar link
- One button on admin page works but not two
- wordpress user roles are not working
- Display popup or admin-notice after add new categories
- How can I POST or GET to the same admin page from which I am POST-ing or GET-ing
- WordPress admin toolbar not loading styles after migration
- I’m a super admin and I want to give an admin the ability to add new users…?
- Return User Meta text as links to post edit inside the user columns
- How to pass a specific post id from “all posts” list in Admin panel
- Default scripts added to each admin page
- Settings API – Last two tabs not rendered separate
- Infinite redirects at front end if logged in user is not an Admin (Toolset Access)
- Is it possible to push admin notices to one specific user instead of all users?
- How to show only specific category post by user role without plugin and restrict all other cats
- Custom redirection when managing users in admin
- How to retain HTML5 Attributes on Markup
- Why doesn’t the Media Browser use thumbnail sized images?
- Improving this link color picker code
- Change the Author name to a custom field?
- Buddypress send admin notification email when new subscriber registers
- Background image in login showing in admin area
- How to change user role setting in members plugin so that user can only edit his own post?