[wp-trac] [WordPress Trac] #59000: Add a check for wp_get_current_user to current_user_can

WordPress Trac noreply at wordpress.org
Mon Aug 28 05:58:16 UTC 2023


#59000: Add a check for wp_get_current_user to current_user_can
-------------------------------------+------------------------------
 Reporter:  scruffian                |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Users                    |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  2nd-opinion needs-patch  |     Focuses:
-------------------------------------+------------------------------

Comment (by okat):

 @azaozz Thank you for taking a look at this!

 >Looking at the original issue, it seems better to warn plugin authors
 that methods like $wp_theme->get_stylesheet() cannot be used before the
 plugins_loaded action (which runs immediately after all plugins and
 pluggable.php are loaded). Then add a "doing it wrong" in these methods
 similarly to the way in script-loader.php (i.e. check if the
 plugins_loaded action has run and call doing_it_wrong if not). This will
 ensure that the stylesheet, template, etc. filters do not run too early
 and similar errors do not happen in the future.

 If we proceed with this approach, the user will just have to wait for the
 error currently occurring in Block Theme Previews to be fixed over time by
 the plugin author, which may take an unpredictable amount of time.
 Also, for plugin authors, not being able to use
 `$wp_theme->get_stylesheet()` before the `plugins_loaded` action could be
 perceived as a breaking change. Not a few plugins (such as CoBlocks,
 Elementor, WooCommerce) will be affected. That's the reason I changed the
 order of loading in https://github.com/WordPress/wordpress-
 develop/pull/5028 while keeping the current behavior.

 Could we confirm if taking this direction is acceptable? Do you have any
 thoughts?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59000#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list