0

Specifically, are the before_widget, after_widget, before_title and before_title array keys always set inside My_Widget::widget()?

I'm wondering if statements such as the following are necessary (inside My_Widget::widget() for example)?

$args['before_widget'] = ! empty( $args['before_widget'] ) ? $args['before_widget'] : '';
$args['after_widget'] = ! empty( $args['after_widget'] ) ? $args['after_widget'] : '';

Note: My My_Widget class extends WP_Widget in case you were wondering.

1 Answer 1

0

This is mostly a case of trusting the arguments. Or not trusting.

  • You can assume that you have received meaningful arguments, ready to be used.
  • You can assume they are arbitrary and possibly grossly invalid.

I would say in this specific case it hangs if the code is public or private. In private site you have the full control over it, from sidebar registration to widget output.

Making widget for public distribution, I reason, would require much more strict checks and making sure it doesn't fall apart on receiving unexpected inputs.

1
  • Thanks @Rarst for your comments, they've given me something to think about (how exactly my code will be used going forward). For example, if someone decides to register a new sidebar with a different set of args. Apr 14, 2015 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.