Am using a third party plugin(eg. ABC Plugin). And their code doesn't have any hooks or filters. And they don't provide customization based on our requirements.
So if I modify the plugin code, I would have to duplicate the changes each time when an update is available for that plugin.
Hence I decided to create a plugin, that will work along with the other plugin, and make the necessary modifications.
Right now, I want to limit the access to a specific url of the plugin page (in admin panel), only to a specific user type.
And the url is like .php?page=abcplugin&route_name=customers__index
Am thinking to use the admin_init
hook to check whether the current requested url is the above, by simply doing if( $_GET['page']=='abcplugin') && $_GET['route_name']=='customers__index')
But am not sure how to show the You do not have permission to access this page
error message. Any inputs?
Am using a third party plugin(eg. ABC Plugin). And their code doesn't have any hooks or filters. And they don't provide customization based on our requirements.
So if I modify the plugin code, I would have to duplicate the changes each time when an update is available for that plugin.
Hence I decided to create a plugin, that will work along with the other plugin, and make the necessary modifications.
Right now, I want to limit the access to a specific url of the plugin page (in admin panel), only to a specific user type.
And the url is like https://mywebsite/wp-admin/admin.php?page=abcplugin&route_name=customers__index
Am thinking to use the admin_init
hook to check whether the current requested url is the above, by simply doing if( $_GET['page']=='abcplugin') && $_GET['route_name']=='customers__index')
But am not sure how to show the You do not have permission to access this page
error message. Any inputs?
1 Answer
Reset to default 0It's done with wp_die()
.
Something along these lines:
if ( $no_user_access ) {
wp_die( 'You do not have permission to access this page' );
}
See: https://developer.wordpress/reference/functions/wp_die/