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?
- Admin Ajax is returning 0
- Allow member to have access to custom post type only. Permission to only edit their own posts
- Add a Separator to the Admin Menu?
- Custom admin email for new user registration
- WordPress Admin back-end – advanced options page?
- front end logo upload like happytables
- Where is the User’s Admin Bar Preference stored? I want it to default to off for new users
- Default, locked sorting of posting fields
- How to add a link to the tax term in the admin Edit page?
- How can I access profile Admin Colour Scheme
- Different Admin Theme – Based on Role?
- Set default page for user account in admin
- Is it safe to post form data via Ajax to the settings api? Am I missing something?
- Only allow administrators and editors to access wp-admin
- How would I add a link to the profile editing page of the dashboard?
- creating custom rewrite rules for admin pages
- Restrict Author role to only 3 wp-admin pages
- Get post attached image to display in admin dashboard
- Admin option sidebar count
- Admin Top Bar Not Showing On Front End
- WordPress administration Over SSL – To Force SSL Logins and SSL Admin Access
- How to verify nonces in bulk?
- avoiding the display of certain categories to certain user roles at content entry time
- Building Forums with Custom Post Types
- WordPress Hacked 5.5 admin-ajax.php [closed]
- Need to block user role from accessing bbPress all together
- Control Users listed in Users List on dashboard
- How to hide plugin options for editors via functions.php
- Weird jquery problem when upgrade to WordPress 3.1
- Admin Bar Acting Up
- How to show private pages based on a user’s role?
- Get content of publish box
- Add button in admin columns
- How to switch between two forms for visitor once admin logged in?
- How to block direct access to files upload in edd folder
- How to create input page in WordPress admin panel?
- Admin blank but Admin menu showing
- Reference external file as a function