*/
class WP_Widget {
- var $id_base; // Root id for all widgets of this type.
- var $name; // Name for this widget type.
- var $widget_options; // Option array passed to wp_register_sidebar_widget()
- var $control_options; // Option array passed to wp_register_widget_control()
+ public $id_base; // Root id for all widgets of this type.
+ public $name; // Name for this widget type.
+ public $widget_options; // Option array passed to wp_register_sidebar_widget()
+ public $control_options; // Option array passed to wp_register_widget_control()
- var $number = false; // Unique ID number of the current instance.
- var $id = false; // Unique ID string of the current instance (id_base-number)
- var $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
+ public $number = false; // Unique ID number of the current instance.
+ public $id = false; // Unique ID string of the current instance (id_base-number)
+ public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
// Member functions that you must over-ride.
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget
*/
- function widget($args, $instance) {
+ public function widget($args, $instance) {
die('function WP_Widget::widget() must be over-ridden in a sub-class.');
}
* @param array $old_instance Old settings for this instance
* @return array Settings to save or bool false to cancel saving
*/
- function update($new_instance, $old_instance) {
+ public function update($new_instance, $old_instance) {
return $new_instance;
}
*
* @param array $instance Current settings
*/
- function form($instance) {
+ public function form($instance) {
echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
return 'noform';
}
* - width: required if more than 250px
* - height: currently not used but may be needed in the future
*/
- function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
+ public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
$this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base);
$this->name = $name;
$this->option_name = 'widget_' . $this->id_base;
/**
* PHP4 constructor
*/
- function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) {
+ public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) {
WP_Widget::__construct( $id_base, $name, $widget_options, $control_options );
}
* @param string $field_name Field name
* @return string Name attribute for $field_name
*/
- function get_field_name($field_name) {
+ public function get_field_name($field_name) {
return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
}
* @param string $field_name Field name
* @return string ID attribute for $field_name
*/
- function get_field_id($field_name) {
+ public function get_field_id($field_name) {
return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
}
// Private Functions. Don't worry about these.
- function _register() {
+ public function _register() {
$settings = $this->get_settings();
$empty = true;
}
}
- function _set($number) {
+ public function _set($number) {
$this->number = $number;
$this->id = $this->id_base . '-' . $number;
}
- function _get_display_callback() {
+ public function _get_display_callback() {
return array($this, 'display_callback');
}
- function _get_update_callback() {
+ public function _get_update_callback() {
return array($this, 'update_callback');
}
- function _get_form_callback() {
+ public function _get_form_callback() {
return array($this, 'form_callback');
}
*
* @return bool True if Customizer is on, false if not.
*/
- function is_preview() {
+ public function is_preview() {
global $wp_customize;
return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ;
}
/** Generate the actual widget content.
* Just finds the instance and calls widget().
* Do NOT over-ride this function. */
- function display_callback( $args, $widget_args = 1 ) {
+ public function display_callback( $args, $widget_args = 1 ) {
if ( is_numeric($widget_args) )
$widget_args = array( 'number' => $widget_args );
*
* @param mixed $deprecated Not used.
*/
- function update_callback( $deprecated = 1 ) {
+ public function update_callback( $deprecated = 1 ) {
global $wp_registered_widgets;
$all_instances = $this->get_settings();
if ( $this->updated )
return;
- $sidebars_widgets = wp_get_sidebars_widgets();
-
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
// Delete the settings for this instance of the widget
if ( isset($_POST['the-widget-id']) )
*
* Do NOT over-ride this function.
*/
- function form_callback( $widget_args = 1 ) {
+ public function form_callback( $widget_args = 1 ) {
if ( is_numeric($widget_args) )
$widget_args = array( 'number' => $widget_args );
}
/** Helper function: Registers a single instance. */
- function _register_one($number = -1) {
+ public function _register_one($number = -1) {
wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
_register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) );
_register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
}
- function save_settings($settings) {
+ public function save_settings($settings) {
$settings['_multiwidget'] = 1;
update_option( $this->option_name, $settings );
}
- function get_settings() {
+ public function get_settings() {
$settings = get_option($this->option_name);
if ( false === $settings && isset($this->alt_option_name) )
* @since 2.8.0
*/
class WP_Widget_Factory {
- var $widgets = array();
+ public $widgets = array();
- function WP_Widget_Factory() {
+ public function WP_Widget_Factory() {
add_action( 'widgets_init', array( $this, '_register_widgets' ), 100 );
}
- function register($widget_class) {
+ public function register($widget_class) {
$this->widgets[$widget_class] = new $widget_class();
}
- function unregister($widget_class) {
+ public function unregister($widget_class) {
if ( isset($this->widgets[$widget_class]) )
unset($this->widgets[$widget_class]);
}
- function _register_widgets() {
+ public function _register_widgets() {
global $wp_registered_widgets;
$keys = array_keys($this->widgets);
$registered = array_keys($wp_registered_widgets);
/**
* Register widget for use in sidebars.
*
- * The default widget option is 'classname' that can be override.
+ * The default widget option is 'classname' that can be overridden.
*
- * The function can also be used to unregister widgets when $output_callback
+ * The function can also be used to un-register widgets when $output_callback
* parameter is an empty string.
*
* @since 2.2.0
if ( is_array($sidebars_widgets) ) {
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
- if ( $skip_inactive && 'wp_inactive_widgets' == $sidebar )
+ if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
continue;
+ }
if ( is_array($widgets) ) {
foreach ( $widgets as $widget ) {
}
foreach ( $_sidebars_widgets as $sidebar => $widgets ) {
- if ( 'wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) )
+ if ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
continue;
+ }
if ( !in_array( $sidebar, $registered_sidebar_keys ) ) {
$_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $widgets;