X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/542cf06a610bc430421351ace7a2cc45f393b990..a7cd4c052013b423c6301153f68c7fdbaa2a447b:/wp-includes/default-widgets.php diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index 2c9ec067..1bdadd8e 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -1,5 +1,4 @@ 'widget_pages', 'description' => __( 'Your site’s WordPress Pages') ); - $this->WP_Widget('pages', __('Pages'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'A list of your site’s Pages.') ); + parent::__construct('pages', __('Pages'), $widget_ops); } - function widget( $args, $instance ) { - extract( $args ); + public function widget( $args, $instance ) { + + /** + * Filter the widget title. + * + * @since 2.6.0 + * + * @param string $title The widget title. Default 'Pages'. + * @param array $instance An array of the widget's settings. + * @param mixed $id_base The widget ID. + */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base ); - $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base); $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; if ( $sortby == 'menu_order' ) $sortby = 'menu_order, post_title'; - $out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) ); - - if ( !empty( $out ) ) { - echo $before_widget; - if ( $title) - echo $before_title . $title . $after_title; + /** + * Filter the arguments for the Pages widget. + * + * @since 2.8.0 + * + * @see wp_list_pages() + * + * @param array $args An array of arguments to retrieve the pages list. + */ + $out = wp_list_pages( apply_filters( 'widget_pages_args', array( + 'title_li' => '', + 'echo' => 0, + 'sort_column' => $sortby, + 'exclude' => $exclude + ) ) ); + + if ( ! empty( $out ) ) { + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } ?> 'post_title', 'title' => '', 'exclude' => '') ); $title = esc_attr( $instance['title'] ); @@ -90,66 +113,90 @@ class WP_Widget_Pages extends WP_Widget { */ class WP_Widget_Links extends WP_Widget { - function WP_Widget_Links() { + public function __construct() { $widget_ops = array('description' => __( "Your blogroll" ) ); - $this->WP_Widget('links', __('Links'), $widget_ops); + parent::__construct('links', __('Links'), $widget_ops); } - function widget( $args, $instance ) { - extract($args, EXTR_SKIP); + public function widget( $args, $instance ) { $show_description = isset($instance['description']) ? $instance['description'] : false; $show_name = isset($instance['name']) ? $instance['name'] : false; $show_rating = isset($instance['rating']) ? $instance['rating'] : false; $show_images = isset($instance['images']) ? $instance['images'] : true; $category = isset($instance['category']) ? $instance['category'] : false; - - if ( is_admin() && !$category ) { - // Display All Links widget as such in the widgets screen - echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget; - return; - } - - $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget); - wp_list_bookmarks(apply_filters('widget_links_args', array( - 'title_before' => $before_title, 'title_after' => $after_title, - 'category_before' => $before_widget, 'category_after' => $after_widget, + $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; + $order = $orderby == 'rating' ? 'DESC' : 'ASC'; + $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; + + $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] ); + + /** + * Filter the arguments for the Links widget. + * + * @since 2.6.0 + * + * @see wp_list_bookmarks() + * + * @param array $args An array of arguments to retrieve the links list. + */ + wp_list_bookmarks( apply_filters( 'widget_links_args', array( + 'title_before' => $args['before_title'], 'title_after' => $args['after_title'], + 'category_before' => $before_widget, 'category_after' => $args['after_widget'], 'show_images' => $show_images, 'show_description' => $show_description, 'show_name' => $show_name, 'show_rating' => $show_rating, - 'category' => $category, 'class' => 'linkcat widget' - ))); + 'category' => $category, 'class' => 'linkcat widget', + 'orderby' => $orderby, 'order' => $order, + 'limit' => $limit, + ) ) ); } - function update( $new_instance, $old_instance ) { + public function update( $new_instance, $old_instance ) { $new_instance = (array) $new_instance; - $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0); + $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); foreach ( $instance as $field => $val ) { if ( isset($new_instance[$field]) ) $instance[$field] = 1; } - $instance['category'] = intval($new_instance['category']); + + $instance['orderby'] = 'name'; + if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) + $instance['orderby'] = $new_instance['orderby']; + + $instance['category'] = intval( $new_instance['category'] ); + $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; return $instance; } - function form( $instance ) { + public function form( $instance ) { //Defaults - $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) ); - $link_cats = get_terms( 'link_category'); + $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); + $link_cats = get_terms( 'link_category' ); + if ( ! $limit = intval( $instance['limit'] ) ) + $limit = -1; ?>

- +

+ + + +

id="get_field_id('images'); ?>" name="get_field_name('images'); ?>" />
@@ -160,6 +207,10 @@ class WP_Widget_Links extends WP_Widget { id="get_field_id('rating'); ?>" name="get_field_name('rating'); ?>" />

+

+ + +

'widget_search', 'description' => __( "A search form for your site") ); - $this->WP_Widget('search', __('Search'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") ); + parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops ); } - function widget( $args, $instance ) { - extract($args); - $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); + public function widget( $args, $instance ) { - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } // Use current theme search form if it exists get_search_form(); - echo $after_widget; + echo $args['after_widget']; } - function form( $instance ) { + public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); $title = $instance['title']; ?> @@ -198,7 +251,7 @@ class WP_Widget_Search extends WP_Widget { '')); $instance['title'] = strip_tags($new_instance['title']); @@ -214,37 +267,72 @@ class WP_Widget_Search extends WP_Widget { */ class WP_Widget_Archives extends WP_Widget { - function WP_Widget_Archives() { - $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s posts') ); - $this->WP_Widget('archives', __('Archives'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') ); + parent::__construct('archives', __('Archives'), $widget_ops); } - function widget( $args, $instance ) { - extract($args); - $c = $instance['count'] ? '1' : '0'; - $d = $instance['dropdown'] ? '1' : '0'; - $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base); + public function widget( $args, $instance ) { + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base ); + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } if ( $d ) { ?> - + '', 'count' => 0, 'dropdown' => '') ); $instance['title'] = strip_tags($new_instance['title']); @@ -254,7 +342,7 @@ class WP_Widget_Archives extends WP_Widget { return $instance; } - function form( $instance ) { + public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') ); $title = strip_tags($instance['title']); $count = $instance['count'] ? 'checked="checked"' : ''; @@ -262,9 +350,9 @@ class WP_Widget_Archives extends WP_Widget { ?>

+ id="get_field_id('dropdown'); ?>" name="get_field_name('dropdown'); ?>" /> +
id="get_field_id('count'); ?>" name="get_field_name('count'); ?>" /> -
- id="get_field_id('dropdown'); ?>" name="get_field_name('dropdown'); ?>" />

'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") ); - $this->WP_Widget('meta', __('Meta'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, & WordPress.org links.") ); + parent::__construct('meta', __('Meta'), $widget_ops); } - function widget( $args, $instance ) { - extract($args); - $title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base); + public function widget( $args, $instance ) { - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base ); + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } ?> '' ) ); $title = strip_tags($instance['title']); ?> @@ -327,31 +431,34 @@ class WP_Widget_Meta extends WP_Widget { */ class WP_Widget_Calendar extends WP_Widget { - function WP_Widget_Calendar() { - $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s posts') ); - $this->WP_Widget('calendar', __('Calendar'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s Posts.') ); + parent::__construct('calendar', __('Calendar'), $widget_ops); } - function widget( $args, $instance ) { - extract($args); - $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base); - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + public function widget( $args, $instance ) { + + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } echo '
'; get_calendar(); echo '
'; - echo $after_widget; + echo $args['after_widget']; } - function update( $new_instance, $old_instance ) { + public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); return $instance; } - function form( $instance ) { + public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $title = strip_tags($instance['title']); ?> @@ -368,24 +475,36 @@ class WP_Widget_Calendar extends WP_Widget { */ class WP_Widget_Text extends WP_Widget { - function WP_Widget_Text() { - $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML')); + public function __construct() { + $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML.')); $control_ops = array('width' => 400, 'height' => 350); - $this->WP_Widget('text', __('Text'), $widget_ops, $control_ops); + parent::__construct('text', __('Text'), $widget_ops, $control_ops); } - function widget( $args, $instance ) { - extract($args); - $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); - $text = apply_filters( 'widget_text', $instance['text'], $instance ); - echo $before_widget; - if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> -
+ public function widget( $args, $instance ) { + + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + + /** + * Filter the content of the Text widget. + * + * @since 2.3.0 + * + * @param string $widget_text The widget content. + * @param WP_Widget $instance WP_Widget instance. + */ + $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ); + echo $args['before_widget']; + if ( ! empty( $title ) ) { + echo $args['before_title'] . $title . $args['after_title']; + } ?> +
'', 'text' => '' ) ); $title = strip_tags($instance['title']); - $text = format_to_edit($instance['text']); + $text = esc_textarea($instance['text']); ?>

@@ -418,28 +537,40 @@ class WP_Widget_Text extends WP_Widget { */ class WP_Widget_Categories extends WP_Widget { - function WP_Widget_Categories() { - $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) ); - $this->WP_Widget('categories', __('Categories'), $widget_ops); + public function __construct() { + $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories." ) ); + parent::__construct('categories', __('Categories'), $widget_ops); } - function widget( $args, $instance ) { - extract( $args ); + public function widget( $args, $instance ) { - $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base); - $c = $instance['count'] ? '1' : '0'; - $h = $instance['hierarchical'] ? '1' : '0'; - $d = $instance['dropdown'] ? '1' : '0'; + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base ); - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h); if ( $d ) { $cat_args['show_option_none'] = __('Select Category'); - wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args)); + + /** + * Filter the arguments for the Categories widget drop-down. + * + * @since 2.8.0 + * + * @see wp_dropdown_categories() + * + * @param array $cat_args An array of Categories widget drop-down arguments. + */ + wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) ); ?>