mirror of
https://github.com/WordPress/WordPress.git
synced 2024-10-03 10:07:53 +02:00
Improve widgets hooks, props Denis-de-Bernardy, fixes #10013
git-svn-id: http://svn.automattic.com/wordpress/trunk@11510 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
206db6eddb
commit
e0a2b8eebe
@ -64,7 +64,7 @@ class WP_Widget {
|
|||||||
* @param array $instance Current settings
|
* @param array $instance Current settings
|
||||||
*/
|
*/
|
||||||
function form($instance) {
|
function form($instance) {
|
||||||
echo '<p>' . __('There are no options for this widget.') . '</p>';
|
echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
|
||||||
return 'noform';
|
return 'noform';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,15 +168,15 @@ class WP_Widget {
|
|||||||
|
|
||||||
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
|
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
|
||||||
$this->_set( $widget_args['number'] );
|
$this->_set( $widget_args['number'] );
|
||||||
$settings = $this->get_settings();
|
$instance = $this->get_settings();
|
||||||
|
|
||||||
if ( array_key_exists( $this->number, $settings ) ) {
|
if ( array_key_exists( $this->number, $instance ) ) {
|
||||||
$settings = $settings[$this->number];
|
$instance = $instance[$this->number];
|
||||||
// filters the widget's settings, return false to stop displaying the widget
|
// filters the widget's settings, return false to stop displaying the widget
|
||||||
$settings = apply_filters('widget_display_callback', $settings, $this, $args);
|
$instance = apply_filters('widget_display_callback', $instance, $this, $args);
|
||||||
if ( false !== $settings )
|
if ( false !== $instance )
|
||||||
$this->widget($args, $settings);
|
$this->widget($args, $instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Deal with changed settings.
|
/** Deal with changed settings.
|
||||||
@ -223,13 +223,12 @@ class WP_Widget {
|
|||||||
$new_instance = stripslashes_deep($new_instance);
|
$new_instance = stripslashes_deep($new_instance);
|
||||||
$this->_set($number);
|
$this->_set($number);
|
||||||
|
|
||||||
if ( isset($all_instances[$number]) )
|
$old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
|
||||||
$instance = $this->update($new_instance, $all_instances[$number]);
|
|
||||||
else
|
$instance = $this->update($new_instance, $old_instance);
|
||||||
$instance = $this->update($new_instance, array());
|
|
||||||
|
|
||||||
// filters the widget's settings before saving, return false to cancel saving (keep the old settings if updating)
|
// filters the widget's settings before saving, return false to cancel saving (keep the old settings if updating)
|
||||||
$instance = apply_filters('widget_update_callback', $instance, $new_instance, $this);
|
$instance = apply_filters('widget_update_callback', $instance, $new_instance, $old_instance, $this);
|
||||||
if ( false !== $instance )
|
if ( false !== $instance )
|
||||||
$all_instances[$number] = $instance;
|
$all_instances[$number] = $instance;
|
||||||
|
|
||||||
@ -265,8 +264,9 @@ class WP_Widget {
|
|||||||
$return = null;
|
$return = null;
|
||||||
if ( false !== $instance ) {
|
if ( false !== $instance ) {
|
||||||
$return = $this->form($instance);
|
$return = $this->form($instance);
|
||||||
if ( 'noform' !== $return )
|
// add extra fields in the widget form - be sure to set $return to null if you add any
|
||||||
do_action_ref_array( 'in_widget_form', array(&$this) ); // add extra fields in the widget form
|
// if the widget has no form the text echoed from the default form method can be hidden using css
|
||||||
|
do_action_ref_array( 'in_widget_form', array(&$this, &$return, $instance) );
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user