[wp-trac] [WordPress Trac] #54994: Action Hook admin_enqueue_scripts and wp_enqueue_scripts

WordPress Trac noreply at wordpress.org
Mon Jan 31 01:12:29 UTC 2022


#54994: Action Hook admin_enqueue_scripts and wp_enqueue_scripts
-------------------------------+------------------------------
 Reporter:  smusman98          |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Plugins            |     Version:  5.9
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:  multisite
-------------------------------+------------------------------

Comment (by dd32):

 > `add_action( 'wp_enqueue_scripts', 'self::wp_enqueue_scripts' );`

 add_action() accepts callables, but they must be a global callable
 acceptable by `call_user_func()` which is run within WP_Hook, `self::`
 would refer to WP_Hook in that instance, not your custom class. To use
 that static-call syntax, you'd need to pass `MyClassName::myClassMethod`
 or `[ 'MyClassName', 'myClassMethod' ]`.

 > `add_action( 'admin_enqueue_scripts', [ ( new self() ),
 'admin_enqueue_scripts' ] );`

 That should work, as would `$obj = new self(); add_action( ..., [ $obj,
 'method' ] );` which is syntactically the same.

 If you can provide the error messages, it should point closer to the error
 in calling it.

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


More information about the wp-trac mailing list