不确定你在这里追求什么,可能还有其他选择,但有。this 挂钩:
/**
* Filters a widget\'s settings before saving.
*
* Returning false will effectively short-circuit the widget\'s ability
* to update settings.
*
* @since 2.8.0
*
* @param array $instance The current widget instance\'s settings.
* @param array $new_instance Array of new widget settings.
* @param array $old_instance Array of old widget settings.
* @param WP_Widget $this The current widget instance.
*/
$instance = apply_filters(
\'widget_update_callback\',
$instance,
$new_instance,
$old_instance,
$this
);
下面是一个示例,我们如何以文本小部件为目标并修改
text
更新时的输入字段:
add_filter( \'widget_update_callback\', function( $instance, $new, $old, $obj )
{
if( \'text\' === $obj->id_base && ! empty( $instance[\'text\'] ) )
{
// Warning this overrides the widget instance text input:
// $instance[\'text\'] = \'override text\';
}
return $instance;
}, 10, 4 );