$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WordPress Plugin Boilerplate - add actions andor filters based on user's role|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WordPress Plugin Boilerplate - add actions andor filters based on user's role

matteradmin9PV0评论

I am developing a plugin using WordPress Plugin Boilerplate.

Some of its functionality need to be available only when a shortcode gets resolved in a page and furthermore some of it only if a user is logged in and has certain roles.

Inside enqueue_scripts() I am enqueueing my scripts, but I register those in the function fired by the shortcode; I also register some of them only for logged users with specific roles. I do the same with css (using enqueue_styles()).

I am adding actions and filters inside define_public_hooks().

A bunch of those are there to associate ajax calls to their callback function, with all but one only necessary if the user is logged in and has certain roles.

Inside the ajax callbacks I do check for is_user_logged_in() and if so, for its roles.

Since is_user_logged_in() is not available inside define_public_hooks(): is there a way to avoid the overhead(? if any) and risks(? if any) of registering actions that are unnecessary unless user is logged in?

Post a comment

comment list (0)

  1. No comments so far