Earlier this week, I received an email from someone who was asking about the Settings API. Specifically, he was curious as to how the WordPress defaults array works.
For those of who may have worked with theme development, plugin development, or the Settings API in general, then you may be familiar with functions that look like this:
/** * Provides a default value for the theme layout setting. * * @since 1.0.0 */ function get_theme_default_layout_options() { $defaults = array( 'layout' => 'right_sidebar_layout', 'display_featured_images' => 'always' ); return apply_filters ( 'theme_default_layout_options', $defaults ); }
But if you’re not familiar with the Settings API or with how to `apply_filters` call works, then this particular function can be confusing especially when it comes to understanding the serialization lifecycle of saving options to the database.