admin管理员组

文章数量:1332345

When a widget is used, in what order are the members used? Obviously, __construct is first, but what happens next? function widget()? function form()?

Which comes first, the chicken or the egg?

When a widget is used, in what order are the members used? Obviously, __construct is first, but what happens next? function widget()? function form()?

Which comes first, the chicken or the egg?

Share Improve this question edited May 27, 2020 at 8:46 Krzysiek Dróżdż 25.5k9 gold badges53 silver badges74 bronze badges asked May 27, 2020 at 8:40 GreatDayDanGreatDayDan 153 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

It's hard to tell the order in which these functions are called, because they're used in different contexts.

WP_Widget class has 4 methods:

  • __construct - it constructs the widget, so it's always run first
  • widget - it should output the content of given widget, so it's used on front-end in sidebar, when the widget is printed
  • form - it outputs the options of given widget in admin area, so it's used in admin, when you edit the widget
  • update - it processes the options form and saves the options, so it's used in admin, when you save the widget options

By using logging, I found out that if it has not been constructed, then function form is called, then function widget.

本文标签: widgetsfor class wpwidgetin what order are the member functions called