[wp-trac] [WordPress Trac] #53801: Block-based Widgets Screen does action wp_footer after each Widget

WordPress Trac noreply at wordpress.org
Tue Sep 21 06:55:32 UTC 2021


#53801: Block-based Widgets Screen does action wp_footer after each Widget
-------------------------------------+---------------------
 Reporter:  MadtownLems              |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  5.8.2
Component:  Widgets                  |     Version:  5.8
 Severity:  major                    |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+---------------------

Comment (by EkoJr):

 @peterwilsoncc I would be more in favor with the `is_admin()` option (2nd
 option). Also, there's `admin_enqueue_scripts` and `wp_enqueue_scripts`,
 and plugins can check the WP_Screen object if enqueue scripts hook or
 `wp_enqueue_script()` needs to be used (either to avoid or include on
 `widgets` id).

 It will drop performance much like adding `admin_enqueue_scripts` on every
 admin screen w/o checking the screen id, as well as not checking
 `is_admin()` on/for `wp_enqueue_scripts`. Technically, this situation
 already occurs with some plugins, but Option 2 would increase the
 potential & severity of it occurring. However, it would be the least
 amount of risk to breaking, and would leave optimizations up to the plugin
 authors.

 If option 2 ends up being the decision, and currently is the option to use
 to avoid the issue, it would be a good idea to make plugin authors aware
 of the performance risks. At least until a solution is added, because it
 can cause a significant loss in performance.

 Meanwhile, anyone having the same issue can implement this concept for
 enqueuing scripts & styles.



 {{{
 function proof_of_concept() {
         if ( is_admin() ) {
                 $screen = get_current_screen();

                 if ( 'widgets' === $screen->id ) {
                         wp_enqueue_script( 'dev-admin-widgets' );
                         // OR.
                         add_action( 'admin_enqueue_scripts',
 'dev_admin_widgets_enqueue' );
                 } else {
                         wp_enqueue_script( 'dev-admin-other' );
                         // OR.
                         add_action( 'admin_enqueue_scripts',
 'dev_admin_other_enqueue' );
                 }
         } else {
                 wp_enqueue_script( 'dev-frontend' );
                 // OR.
                 add_action( 'wp_enqueue_scripts', 'dev_frontend_enqueue'
 );
         }
 }
 add_action( 'current_screen', 'proof_of_concept' );
 }}}

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


More information about the wp-trac mailing list