admin管理员组

文章数量:1201032

I have below code.

add_action( 'admin_init', [$this, 'settings_page_registration'] );

I would like to use enqueue_assets function name inside add_action().

Should I use like below ?

add_action( 'admin_init', [$this, 'settings_page_registration', 'enqueue_assets'] );

I have below code.

add_action( 'admin_init', [$this, 'settings_page_registration'] );

I would like to use enqueue_assets function name inside add_action().

Should I use like below ?

add_action( 'admin_init', [$this, 'settings_page_registration', 'enqueue_assets'] );
Share Improve this question asked May 10, 2022 at 3:37 FoysalFoysal 4451 gold badge5 silver badges16 bronze badges 2
  • 1 No, that's not how it works. What are you trying to do? Why do you need to pass the function name like that? – Jacob Peattie Commented May 10, 2022 at 3:39
  • Thanks @JacobPeattie. I would like to call the function at admin_init. Thanks. – Foysal Commented May 10, 2022 at 3:53
Add a comment  | 

1 Answer 1

Reset to default 2

If you need to call enqueue_assets at admin_init, then add a new add_action():

add_action( 'admin_init', [$this, 'settings_page_registration'] );
add_action( 'admin_init', [$this, 'enqueue_assets'] );
  • https://developer.wordpress.org/reference/functions/add_action/

That said, if your assets are JS scripts or CSS, you should consider wp_enqueue_script() & wp_enqueue_scripts

  • https://developer.wordpress.org/reference/functions/wp_enqueue_script
  • https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/

本文标签: adminHow to pass multiple parameter in addaction()