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

WordPress Trac noreply at wordpress.org
Tue Aug 29 06:26:42 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 has-patch  |     Focuses:
-----------------------------------+------------------------------

Comment (by okat):

 >Calling $wp_theme->get_stylesheet() is unaffected by the proposed
 PR/patch. Any plugin or theme or core code that does this before wp-
 includes/pluggable.php is loaded is "doing it wrong".

 > In any case, having a "loose" functional code that runs in global scope
 in a plugin's file is a big "bad practice" usually. Triggering "doing it
 wrong" in such cases seems warranted.

 Thank you for the insightful feedback, @azaozz. It helped clarify several
 key points for me!
 I agree that best practices should be followed to avoid "loose" functional
 code running globally, and triggering "doing it wrong" makes sense.

 >There seem to be couple alternatives to fix the particular case with
 theme-previews.php. Perhaps instead of moving the file it would be better
 to move the code that is adding the actions and filters to a function, and
 then load that function on plugins_loaded (add the hook for it in
 default_filters.php)? Then the file would not need moving and there will
 be no "loose code" in the global scope there.

 For the issue this time, I took this approach by encapsulating hooks into
 a function and initializing it in `default_filters.php`. I submitted
 another PR, so I would greatly appreciate it if you retake a look at the
 PR. Thank you in advance! https://github.com/WordPress/wordpress-
 develop/pull/5107

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


More information about the wp-trac mailing list