carlomanf / wp-funnel-manager

Organises wordpress content into multi-step funnels.
https://wordpress.org/plugins/wp-funnel-manager/
5 stars 0 forks source link

User roles not working correctly #16

Closed carlomanf closed 2 years ago

carlomanf commented 2 years ago

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:

  1. Plugins are loaded
  2. (Non-plugged) pluggable functions are loaded
  3. The plugins_loaded action is fired
  4. The WP_Roles instance is constructed
  5. The theme's functions.php is loaded
  6. The after_setup_theme action is fired
  7. The current user is constructed
  8. The init action is fired

From version 1.3.0 to version 1.3.1, the funnel type registration was moved from plugins_loaded to after_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 to get_current_user_id() which will ultimately cause the WP_Roles instance to be constructed if it was not constructed already.

Accordingly, to correctly register the user roles, two things must be ensured:

carlomanf commented 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.