最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Prevent third party plugin's admin page access based on user type

programmeradmin3浏览0评论

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?

Share Improve this question asked Dec 16, 2019 at 17:33 Vpp ManVpp Man 1234 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It'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/

发布评论

评论列表(0)

  1. 暂无评论