Closed carlomanf closed 2 years ago
be3ef1f attempts to solve this by re-generating the roles at the point of after_setup_theme
and re-defining wp_get_current_user
. Unfortunately, this means the plugin can't be used in conjunction with other plugins that re-define wp_get_current_user
. This seems to be the most reasonable solution for now, without drastically changing the structure of the plugin.
This issue can be closed for now, and re-opened in the case any unintended effects are discovered.
While using version 1.3.1, I noticed some strange behaviours with user capabilities in a number of different places. I determined that the cause is this plugin, particularly that the user roles are being registered too late to be recognised by core.
For some background, here is the order of some relevant events as part of each execution cycle:
plugins_loaded
action is firedWP_Roles
instance is constructedfunctions.php
is loadedafter_setup_theme
action is firedinit
action is firedFrom version 1.3.0 to version 1.3.1, the funnel type registration was moved from
plugins_loaded
toafter_setup_theme
. As shown above, this is too late for the user roles to be registered.However, the problem was not introduced by version 1.3.1 either. When performing a
WP_Query
, there is an unconditional call toget_current_user_id()
which will ultimately cause theWP_Roles
instance to be constructed if it was not constructed already.Accordingly, to correctly register the user roles, two things must be ensured:
plugins_loaded
action or earlierWP_Roles
instance needs to be prevented until the post types (or at least the user roles) are registered