d widgets can have null values for some reason if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) ) continue; $id = "text-$o"; // Never never never translate an id wp_register_sidebar_widget($id, $name, 'wp_widget_text', $widget_ops, array( 'number' => $o )); wp_register_widget_control($id, $name, 'wp_widget_text_control', $control_ops, array( 'number' => $o )); } // If there are none, we register the widget's existance with a generic template if ( !$id ) { wp_register_sidebar_widget( 'text-1', $name, 'wp_widget_text', $widget_ops, array( 'number' => -1 ) ); wp_register_widget_control( 'text-1', $name, 'wp_widget_text_control', $control_ops, array( 'number' => -1 ) ); } } /** * Display categories widget. * * Allows multiple category widgets. * * @since 2.2.0 * * @param array $args Widget arguments. * @param int $number Widget number. */ function wp_widget_categories($args, $widget_args = 1) { extract($args, EXTR_SKIP); if ( is_numeric($widget_args) ) $widget_args = array( 'number' => $widget_args ); $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); extract($widget_args, EXTR_SKIP); $options = get_option('widget_categories'); if ( !isset($options[$number]) ) return; $c = $options[$number]['count'] ? '1' : '0'; $h = $options[$number]['hierarchical'] ? '1' : '0'; $d = $options[$number]['dropdown'] ? '1' : '0'; $title = empty($options[$number]['title']) ? __('Categories') : apply_filters('widget_title', $options[$number]['title']); echo $before_widget; echo $before_title . $title . $after_title; $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h); if ( $d ) { $cat_args['show_option_none'] = __('Select Category'); wp_dropdown_categories($cat_args); ?> $widget_args ); $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); extract($widget_args, EXTR_SKIP); $options = get_option('widget_categories'); if ( !is_array( $options ) ) $options = array(); if ( !$updated && !empty($_POST['sidebar']) ) { $sidebar = (string) $_POST['sidebar']; $sidebars_widgets = wp_get_sidebars_widgets(); if ( isset($sidebars_widgets[$sidebar]) ) $this_sidebar =& $sidebars_widgets[$sidebar]; else $this_sidebar = array(); foreach ( (array) $this_sidebar as $_widget_id ) { if ( 'wp_widget_categories' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) { $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; if ( !in_array( "categories-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed. unset($options[$widget_number]); } } foreach ( (array) $_POST['widget-categories'] as $widget_number => $widget_cat ) { if ( !isset($widget_cat['title']) && isset($options[$widget_number]) ) // user clicked cancel continue; $title = trim(strip_tags(stripslashes($widget_cat['title']))); $count = isset($widget_cat['count']); $hierarchical = isset($widget_cat['hierarchical']); $dropdown = isset($widget_cat['dropdown']); $options[$widget_number] = compact( 'title', 'count', 'hierarchical', 'dropdown' ); } update_option('widget_categories', $options); $updated = true; } if ( -1 == $number ) { $title = ''; $count = false; $hierarchical = false; $dropdown = false; $number = '%i%'; } else { $title = attribute_escape( $options[$number]['title'] ); $count = (bool) $options[$number]['count']; $hierarchical = (bool) $options[$number]['hierarchical']; $dropdown = (bool) $options[$number]['dropdown']; } ?>



'widget_categories', 'description' => __( "A list or dropdown of categories" ) ); $name = __( 'Categories' ); $id = false; foreach ( (array) array_keys($options) as $o ) { // Old widgets can have null values for some reason if ( !isset($options[$o]['title']) ) continue; $id = "categories-$o"; wp_register_sidebar_widget( $id, $name, 'wp_widget_categories', $widget_ops, array( 'number' => $o ) ); wp_register_widget_control( $id, $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => $o ) ); } // If there are none, we register the widget's existance with a generic template if ( !$id ) { wp_register_sidebar_widget( 'categories-1', $name, 'wp_widget_categories', $widget_ops, array( 'number' => -1 ) ); wp_register_widget_control( 'categories-1', $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => -1 ) ); } } /** * Upgrade previous category widget to current version. * * @since 2.3.0 * * @return array */ function wp_widget_categories_upgrade() { $options = get_option( 'widget_categories' ); if ( !isset( $options['title'] ) ) return $options; $newoptions = array( 1 => $options ); update_option( 'widget_categories', $newoptions ); $sidebars_widgets = get_option( 'sidebars_widgets' ); if ( is_array( $sidebars_widgets ) ) { foreach ( $sidebars_widgets as $sidebar => $widgets ) { if ( is_array( $widgets ) ) { foreach ( $widgets as $widget ) $new_widgets[$sidebar][] = ( $widget == 'categories' ) ? 'categories-1' : $widget; } else { $new_widgets[$sidebar] = $widgets; } } if ( $new_widgets != $sidebars_widgets ) update_option( 'sidebars_widgets', $new_widgets ); } return $newoptions; } /** * Display recent entries widget. * * @since 2.2.0 * * @param array $args Widget arguments. * @return int Displayed cache. */ function wp_widget_recent_entries($args) { if ( '%BEG_OF_TITLE%' != $args['before_title'] ) { if ( $output = wp_cache_get('widget_recent_entries', 'widget') ) return print($output); ob_start(); } extract($args); $options = get_option('widget_recent_entries'); $title = empty($options['title']) ? __('Recent Posts') : apply_filters('widget_title', $options['title']); if ( !$number = (int) $options['number'] ) $number = 10; else if ( $number < 1 ) $number = 1; else if ( $number > 15 ) $number = 15; $r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1)); if ($r->have_posts()) : ?>