mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * API for creating dynamic sidebar without hardcoding functionality into
mp-wp_genesis 4 * themes. Includes both internal WordPress routines and theme use routines.
mp-wp_genesis 5 *
mp-wp_genesis 6 * This functionality was found in a plugin before WordPress 2.2 release which
mp-wp_genesis 7 * included it in the core from that point on.
mp-wp_genesis 8 *
mp-wp_genesis 9 * @link http://codex.wordpress.org/Plugins/WordPress_Widgets WordPress Widgets
mp-wp_genesis 10 * @link http://codex.wordpress.org/Plugins/WordPress_Widgets_Api Widgets API
mp-wp_genesis 11 *
mp-wp_genesis 12 * @package WordPress
mp-wp_genesis 13 * @subpackage Widgets
mp-wp_genesis 14 */
mp-wp_genesis 15
mp-wp_genesis 16 /* Global Variables */
mp-wp_genesis 17
mp-wp_genesis 18 /** @ignore */
mp-wp_genesis 19 global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls;
mp-wp_genesis 20
mp-wp_genesis 21 /**
mp-wp_genesis 22 * Stores the sidebars, since many themes can have more than one.
mp-wp_genesis 23 *
mp-wp_genesis 24 * @global array $wp_registered_sidebars
mp-wp_genesis 25 * @since 2.2.0
mp-wp_genesis 26 */
mp-wp_genesis 27 $wp_registered_sidebars = array();
mp-wp_genesis 28
mp-wp_genesis 29 /**
mp-wp_genesis 30 * Stores the registered widgets.
mp-wp_genesis 31 *
mp-wp_genesis 32 * @global array $wp_registered_widgets
mp-wp_genesis 33 * @since 2.2.0
mp-wp_genesis 34 */
mp-wp_genesis 35 $wp_registered_widgets = array();
mp-wp_genesis 36
mp-wp_genesis 37 /**
mp-wp_genesis 38 * Stores the registered widget control (options).
mp-wp_genesis 39 *
mp-wp_genesis 40 * @global array $wp_registered_widget_controls
mp-wp_genesis 41 * @since 2.2.0
mp-wp_genesis 42 */
mp-wp_genesis 43 $wp_registered_widget_controls = array();
mp-wp_genesis 44
mp-wp_genesis 45 /* Template tags & API functions */
mp-wp_genesis 46
mp-wp_genesis 47 /**
mp-wp_genesis 48 * Creates multiple sidebars.
mp-wp_genesis 49 *
mp-wp_genesis 50 * If you wanted to quickly create multiple sidebars for a theme or internally.
mp-wp_genesis 51 * This function will allow you to do so. If you don't pass the 'name' and/or
mp-wp_genesis 52 * 'id' in $args, then they will be built for you.
mp-wp_genesis 53 *
mp-wp_genesis 54 * The default for the name is "Sidebar #", with '#' being replaced with the
mp-wp_genesis 55 * number the sidebar is currently when greater than one. If first sidebar, the
mp-wp_genesis 56 * name will be just "Sidebar". The default for id is "sidebar-" followed by the
mp-wp_genesis 57 * number the sidebar creation is currently at.
mp-wp_genesis 58 *
mp-wp_genesis 59 * @since 2.2.0
mp-wp_genesis 60 *
mp-wp_genesis 61 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
mp-wp_genesis 62 * @uses parse_str() Converts a string to an array to be used in the rest of the function.
mp-wp_genesis 63 * @uses register_sidebar() Sends single sidebar information [name, id] to this
mp-wp_genesis 64 * function to handle building the sidebar.
mp-wp_genesis 65 *
mp-wp_genesis 66 * @param int $number Number of sidebars to create.
mp-wp_genesis 67 * @param string|array $args Builds Sidebar based off of 'name' and 'id' values.
mp-wp_genesis 68 */
mp-wp_genesis 69 function register_sidebars($number = 1, $args = array()) {
mp-wp_genesis 70 global $wp_registered_sidebars;
mp-wp_genesis 71 $number = (int) $number;
mp-wp_genesis 72
mp-wp_genesis 73 if ( is_string($args) )
mp-wp_genesis 74 parse_str($args, $args);
mp-wp_genesis 75
mp-wp_genesis 76 for ( $i=1; $i <= $number; $i++ ) {
mp-wp_genesis 77 $_args = $args;
mp-wp_genesis 78
mp-wp_genesis 79 if ( $number > 1 ) {
mp-wp_genesis 80 $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
mp-wp_genesis 81 } else {
mp-wp_genesis 82 $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
mp-wp_genesis 83 }
mp-wp_genesis 84
mp-wp_genesis 85 if (isset($args['id'])) {
mp-wp_genesis 86 $_args['id'] = $args['id'];
mp-wp_genesis 87 } else {
mp-wp_genesis 88 $n = count($wp_registered_sidebars);
mp-wp_genesis 89 do {
mp-wp_genesis 90 $n++;
mp-wp_genesis 91 $_args['id'] = "sidebar-$n";
mp-wp_genesis 92 } while (isset($wp_registered_sidebars[$_args['id']]));
mp-wp_genesis 93 }
mp-wp_genesis 94
mp-wp_genesis 95 register_sidebar($_args);
mp-wp_genesis 96 }
mp-wp_genesis 97 }
mp-wp_genesis 98
mp-wp_genesis 99 /**
mp-wp_genesis 100 * Builds the definition for a single sidebar and returns the ID.
mp-wp_genesis 101 *
mp-wp_genesis 102 * The $args parameter takes either a string or an array with 'name' and 'id'
mp-wp_genesis 103 * contained in either usage. It will be noted that the values will be applied
mp-wp_genesis 104 * to all sidebars, so if creating more than one, it will be advised to allow
mp-wp_genesis 105 * for WordPress to create the defaults for you.
mp-wp_genesis 106 *
mp-wp_genesis 107 * Example for string would be <code>'name=whatever;id=whatever1'</code> and for
mp-wp_genesis 108 * the array it would be <code>array(
mp-wp_genesis 109 * 'name' => 'whatever',
mp-wp_genesis 110 * 'id' => 'whatever1')</code>.
mp-wp_genesis 111 *
mp-wp_genesis 112 * name - The name of the sidebar, which presumably the title which will be
mp-wp_genesis 113 * displayed.
mp-wp_genesis 114 * id - The unique identifier by which the sidebar will be called by.
mp-wp_genesis 115 * before_widget - The content that will prepended to the widgets when they are
mp-wp_genesis 116 * displayed.
mp-wp_genesis 117 * after_widget - The content that will be appended to the widgets when they are
mp-wp_genesis 118 * displayed.
mp-wp_genesis 119 * before_title - The content that will be prepended to the title when displayed.
mp-wp_genesis 120 * after_title - the content that will be appended to the title when displayed.
mp-wp_genesis 121 *
mp-wp_genesis 122 * <em>Content</em> is assumed to be HTML and should be formatted as such, but
mp-wp_genesis 123 * doesn't have to be.
mp-wp_genesis 124 *
mp-wp_genesis 125 * @since 2.2.0
mp-wp_genesis 126 * @uses $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID.
mp-wp_genesis 127 * @uses parse_str() Converts a string to an array to be used in the rest of the function.
mp-wp_genesis 128 * @usedby register_sidebars()
mp-wp_genesis 129 *
mp-wp_genesis 130 * @param string|array $args Builds Sidebar based off of 'name' and 'id' values
mp-wp_genesis 131 * @return string The sidebar id that was added.
mp-wp_genesis 132 */
mp-wp_genesis 133 function register_sidebar($args = array()) {
mp-wp_genesis 134 global $wp_registered_sidebars;
mp-wp_genesis 135
mp-wp_genesis 136 if ( is_string($args) )
mp-wp_genesis 137 parse_str($args, $args);
mp-wp_genesis 138
mp-wp_genesis 139 $i = count($wp_registered_sidebars) + 1;
mp-wp_genesis 140
mp-wp_genesis 141 $defaults = array(
mp-wp_genesis 142 'name' => sprintf(__('Sidebar %d'), $i ),
mp-wp_genesis 143 'id' => "sidebar-$i",
mp-wp_genesis 144 'before_widget' => '<li id="%1$s" class="widget %2$s">',
mp-wp_genesis 145 'after_widget' => "</li>\n",
mp-wp_genesis 146 'before_title' => '<h2 class="widgettitle">',
mp-wp_genesis 147 'after_title' => "</h2>\n",
mp-wp_genesis 148 );
mp-wp_genesis 149
mp-wp_genesis 150 $sidebar = array_merge($defaults, (array) $args);
mp-wp_genesis 151
mp-wp_genesis 152 $wp_registered_sidebars[$sidebar['id']] = $sidebar;
mp-wp_genesis 153
mp-wp_genesis 154 return $sidebar['id'];
mp-wp_genesis 155 }
mp-wp_genesis 156
mp-wp_genesis 157 /**
mp-wp_genesis 158 * Removes a sidebar from the list.
mp-wp_genesis 159 *
mp-wp_genesis 160 * @since 2.2.0
mp-wp_genesis 161 *
mp-wp_genesis 162 * @uses $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID.
mp-wp_genesis 163 *
mp-wp_genesis 164 * @param string $name The ID of the sidebar when it was added.
mp-wp_genesis 165 */
mp-wp_genesis 166 function unregister_sidebar( $name ) {
mp-wp_genesis 167 global $wp_registered_sidebars;
mp-wp_genesis 168
mp-wp_genesis 169 if ( isset( $wp_registered_sidebars[$name] ) )
mp-wp_genesis 170 unset( $wp_registered_sidebars[$name] );
mp-wp_genesis 171 }
mp-wp_genesis 172
mp-wp_genesis 173 /**
mp-wp_genesis 174 * Register widget for sidebar with backwards compatibility.
mp-wp_genesis 175 *
mp-wp_genesis 176 * Allows $name to be an array that accepts either three elements to grab the
mp-wp_genesis 177 * first element and the third for the name or just uses the first element of
mp-wp_genesis 178 * the array for the name.
mp-wp_genesis 179 *
mp-wp_genesis 180 * Passes to {@link wp_register_sidebar_widget()} after argument list and
mp-wp_genesis 181 * backwards compatibility is complete.
mp-wp_genesis 182 *
mp-wp_genesis 183 * @since 2.2.0
mp-wp_genesis 184 * @uses wp_register_sidebar_widget() Passes the compiled arguments.
mp-wp_genesis 185 *
mp-wp_genesis 186 * @param string|int $name Widget ID.
mp-wp_genesis 187 * @param callback $output_callback Run when widget is called.
mp-wp_genesis 188 * @param string $classname Classname widget option.
mp-wp_genesis 189 * @param mixed $params,... Widget parameters.
mp-wp_genesis 190 */
mp-wp_genesis 191 function register_sidebar_widget($name, $output_callback, $classname = '') {
mp-wp_genesis 192 // Compat
mp-wp_genesis 193 if ( is_array($name) ) {
mp-wp_genesis 194 if ( count($name) == 3 )
mp-wp_genesis 195 $name = sprintf($name[0], $name[2]);
mp-wp_genesis 196 else
mp-wp_genesis 197 $name = $name[0];
mp-wp_genesis 198 }
mp-wp_genesis 199
mp-wp_genesis 200 $id = sanitize_title($name);
mp-wp_genesis 201 $options = array();
mp-wp_genesis 202 if ( !empty($classname) && is_string($classname) )
mp-wp_genesis 203 $options['classname'] = $classname;
mp-wp_genesis 204 $params = array_slice(func_get_args(), 2);
mp-wp_genesis 205 $args = array($id, $name, $output_callback, $options);
mp-wp_genesis 206 if ( !empty($params) )
mp-wp_genesis 207 $args = array_merge($args, $params);
mp-wp_genesis 208
mp-wp_genesis 209 call_user_func_array('wp_register_sidebar_widget', $args);
mp-wp_genesis 210 }
mp-wp_genesis 211
mp-wp_genesis 212 /**
mp-wp_genesis 213 * Register widget for use in sidebars.
mp-wp_genesis 214 *
mp-wp_genesis 215 * The default widget option is 'classname' that can be override.
mp-wp_genesis 216 *
mp-wp_genesis 217 * The function can also be used to unregister widgets when $output_callback
mp-wp_genesis 218 * parameter is an empty string.
mp-wp_genesis 219 *
mp-wp_genesis 220 * @since 2.2.0
mp-wp_genesis 221 *
mp-wp_genesis 222 * @uses $wp_registered_widgets Uses stored registered widgets.
mp-wp_genesis 223 * @uses $wp_register_widget_defaults Retrieves widget defaults.
mp-wp_genesis 224 *
mp-wp_genesis 225 * @param int|string $id Widget ID.
mp-wp_genesis 226 * @param string $name Widget display title.
mp-wp_genesis 227 * @param callback $output_callback Run when widget is called.
mp-wp_genesis 228 * @param array|string Optional. $options Widget Options.
mp-wp_genesis 229 * @param mixed $params,... Widget parameters to add to widget.
mp-wp_genesis 230 * @return null Will return if $output_callback is empty after removing widget.
mp-wp_genesis 231 */
mp-wp_genesis 232 function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) {
mp-wp_genesis 233 global $wp_registered_widgets;
mp-wp_genesis 234
mp-wp_genesis 235 $id = strtolower($id);
mp-wp_genesis 236
mp-wp_genesis 237 if ( empty($output_callback) ) {
mp-wp_genesis 238 unset($wp_registered_widgets[$id]);
mp-wp_genesis 239 return;
mp-wp_genesis 240 }
mp-wp_genesis 241
mp-wp_genesis 242 $defaults = array('classname' => $output_callback);
mp-wp_genesis 243 $options = wp_parse_args($options, $defaults);
mp-wp_genesis 244 $widget = array(
mp-wp_genesis 245 'name' => $name,
mp-wp_genesis 246 'id' => $id,
mp-wp_genesis 247 'callback' => $output_callback,
mp-wp_genesis 248 'params' => array_slice(func_get_args(), 4)
mp-wp_genesis 249 );
mp-wp_genesis 250 $widget = array_merge($widget, $options);
mp-wp_genesis 251
mp-wp_genesis 252 if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || did_action( 'widgets_init' ) ) )
mp-wp_genesis 253 $wp_registered_widgets[$id] = $widget;
mp-wp_genesis 254 }
mp-wp_genesis 255
mp-wp_genesis 256 /**
mp-wp_genesis 257 * Retrieve description for widget.
mp-wp_genesis 258 *
mp-wp_genesis 259 * When registering widgets, the options can also include 'description' that
mp-wp_genesis 260 * describes the widget for display on the widget administration panel or
mp-wp_genesis 261 * in the theme.
mp-wp_genesis 262 *
mp-wp_genesis 263 * @since 2.5.0
mp-wp_genesis 264 *
mp-wp_genesis 265 * @param int|string $id Widget ID.
mp-wp_genesis 266 * @return string Widget description, if available. Null on failure to retrieve description.
mp-wp_genesis 267 */
mp-wp_genesis 268 function wp_widget_description( $id ) {
mp-wp_genesis 269 if ( !is_scalar($id) )
mp-wp_genesis 270 return;
mp-wp_genesis 271
mp-wp_genesis 272 global $wp_registered_widgets;
mp-wp_genesis 273
mp-wp_genesis 274 if ( isset($wp_registered_widgets[$id]['description']) )
mp-wp_genesis 275 return wp_specialchars( $wp_registered_widgets[$id]['description'] );
mp-wp_genesis 276 }
mp-wp_genesis 277
mp-wp_genesis 278 /**
mp-wp_genesis 279 * Alias of {@link wp_unregister_sidebar_widget()}.
mp-wp_genesis 280 *
mp-wp_genesis 281 * @see wp_unregister_sidebar_widget()
mp-wp_genesis 282 *
mp-wp_genesis 283 * @since 2.2.0
mp-wp_genesis 284 *
mp-wp_genesis 285 * @param int|string $id Widget ID.
mp-wp_genesis 286 */
mp-wp_genesis 287 function unregister_sidebar_widget($id) {
mp-wp_genesis 288 return wp_unregister_sidebar_widget($id);
mp-wp_genesis 289 }
mp-wp_genesis 290
mp-wp_genesis 291 /**
mp-wp_genesis 292 * Remove widget from sidebar.
mp-wp_genesis 293 *
mp-wp_genesis 294 * @since 2.2.0
mp-wp_genesis 295 *
mp-wp_genesis 296 * @param int|string $id Widget ID.
mp-wp_genesis 297 */
mp-wp_genesis 298 function wp_unregister_sidebar_widget($id) {
mp-wp_genesis 299 wp_register_sidebar_widget($id, '', '');
mp-wp_genesis 300 wp_unregister_widget_control($id);
mp-wp_genesis 301 }
mp-wp_genesis 302
mp-wp_genesis 303 /**
mp-wp_genesis 304 * Registers widget control callback for customizing options.
mp-wp_genesis 305 *
mp-wp_genesis 306 * Allows $name to be an array that accepts either three elements to grab the
mp-wp_genesis 307 * first element and the third for the name or just uses the first element of
mp-wp_genesis 308 * the array for the name.
mp-wp_genesis 309 *
mp-wp_genesis 310 * Passes to {@link wp_register_widget_control()} after the argument list has
mp-wp_genesis 311 * been compiled.
mp-wp_genesis 312 *
mp-wp_genesis 313 * @since 2.2.0
mp-wp_genesis 314 *
mp-wp_genesis 315 * @param int|string $name Sidebar ID.
mp-wp_genesis 316 * @param callback $control_callback Widget control callback to display and process form.
mp-wp_genesis 317 * @param int $width Widget width.
mp-wp_genesis 318 * @param int $height Widget height.
mp-wp_genesis 319 */
mp-wp_genesis 320 function register_widget_control($name, $control_callback, $width = '', $height = '') {
mp-wp_genesis 321 // Compat
mp-wp_genesis 322 if ( is_array($name) ) {
mp-wp_genesis 323 if ( count($name) == 3 )
mp-wp_genesis 324 $name = sprintf($name[0], $name[2]);
mp-wp_genesis 325 else
mp-wp_genesis 326 $name = $name[0];
mp-wp_genesis 327 }
mp-wp_genesis 328
mp-wp_genesis 329 $id = sanitize_title($name);
mp-wp_genesis 330 $options = array();
mp-wp_genesis 331 if ( !empty($width) )
mp-wp_genesis 332 $options['width'] = $width;
mp-wp_genesis 333 if ( !empty($height) )
mp-wp_genesis 334 $options['height'] = $height;
mp-wp_genesis 335 $params = array_slice(func_get_args(), 4);
mp-wp_genesis 336 $args = array($id, $name, $control_callback, $options);
mp-wp_genesis 337 if ( !empty($params) )
mp-wp_genesis 338 $args = array_merge($args, $params);
mp-wp_genesis 339
mp-wp_genesis 340 call_user_func_array('wp_register_widget_control', $args);
mp-wp_genesis 341 }
mp-wp_genesis 342
mp-wp_genesis 343 /**
mp-wp_genesis 344 * Registers widget control callback for customizing options.
mp-wp_genesis 345 *
mp-wp_genesis 346 * The options contains the 'height', 'width', and 'id_base' keys. The 'height'
mp-wp_genesis 347 * option is never used. The 'width' option is the width of the fully expanded
mp-wp_genesis 348 * control form, but try hard to use the default width. The 'id_base' is for
mp-wp_genesis 349 * multi-widgets (widgets which allow multiple instances such as the text
mp-wp_genesis 350 * widget), an id_base must be provided. The widget id will end up looking like
mp-wp_genesis 351 * {$id_base}-{$unique_number}.
mp-wp_genesis 352 *
mp-wp_genesis 353 * @since 2.2.0
mp-wp_genesis 354 *
mp-wp_genesis 355 * @param int|string $id Sidebar ID.
mp-wp_genesis 356 * @param string $name Sidebar display name.
mp-wp_genesis 357 * @param callback $control_callback Run when sidebar is displayed.
mp-wp_genesis 358 * @param array|string $options Optional. Widget options. See above long description.
mp-wp_genesis 359 * @param mixed $params,... Optional. Additional parameters to add to widget.
mp-wp_genesis 360 */
mp-wp_genesis 361 function wp_register_widget_control($id, $name, $control_callback, $options = array()) {
mp-wp_genesis 362 global $wp_registered_widget_controls;
mp-wp_genesis 363
mp-wp_genesis 364 $id = strtolower($id);
mp-wp_genesis 365
mp-wp_genesis 366 if ( empty($control_callback) ) {
mp-wp_genesis 367 unset($wp_registered_widget_controls[$id]);
mp-wp_genesis 368 return;
mp-wp_genesis 369 }
mp-wp_genesis 370
mp-wp_genesis 371 if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) )
mp-wp_genesis 372 return;
mp-wp_genesis 373
mp-wp_genesis 374 $defaults = array('width' => 250, 'height' => 200 ); // height is never used
mp-wp_genesis 375 $options = wp_parse_args($options, $defaults);
mp-wp_genesis 376 $options['width'] = (int) $options['width'];
mp-wp_genesis 377 $options['height'] = (int) $options['height'];
mp-wp_genesis 378
mp-wp_genesis 379 $widget = array(
mp-wp_genesis 380 'name' => $name,
mp-wp_genesis 381 'id' => $id,
mp-wp_genesis 382 'callback' => $control_callback,
mp-wp_genesis 383 'params' => array_slice(func_get_args(), 4)
mp-wp_genesis 384 );
mp-wp_genesis 385 $widget = array_merge($widget, $options);
mp-wp_genesis 386
mp-wp_genesis 387 $wp_registered_widget_controls[$id] = $widget;
mp-wp_genesis 388 }
mp-wp_genesis 389
mp-wp_genesis 390 /**
mp-wp_genesis 391 * Alias of {@link wp_unregister_widget_control()}.
mp-wp_genesis 392 *
mp-wp_genesis 393 * @since 2.2.0
mp-wp_genesis 394 * @see wp_unregister_widget_control()
mp-wp_genesis 395 *
mp-wp_genesis 396 * @param int|string $id Widget ID.
mp-wp_genesis 397 */
mp-wp_genesis 398 function unregister_widget_control($id) {
mp-wp_genesis 399 return wp_unregister_widget_control($id);
mp-wp_genesis 400 }
mp-wp_genesis 401
mp-wp_genesis 402 /**
mp-wp_genesis 403 * Remove control callback for widget.
mp-wp_genesis 404 *
mp-wp_genesis 405 * @since 2.2.0
mp-wp_genesis 406 * @uses wp_register_widget_control() Unregisters by using empty callback.
mp-wp_genesis 407 *
mp-wp_genesis 408 * @param int|string $id Widget ID.
mp-wp_genesis 409 */
mp-wp_genesis 410 function wp_unregister_widget_control($id) {
mp-wp_genesis 411 return wp_register_widget_control($id, '', '');
mp-wp_genesis 412 }
mp-wp_genesis 413
mp-wp_genesis 414 /**
mp-wp_genesis 415 * Display dynamic sidebar.
mp-wp_genesis 416 *
mp-wp_genesis 417 * By default it displays the default sidebar or 'sidebar-1'. The 'sidebar-1' is
mp-wp_genesis 418 * not named by the theme, the actual name is '1', but 'sidebar-' is added to
mp-wp_genesis 419 * the registered sidebars for the name. If you named your sidebar 'after-post',
mp-wp_genesis 420 * then the parameter $index will still be 'after-post', but the lookup will be
mp-wp_genesis 421 * for 'sidebar-after-post'.
mp-wp_genesis 422 *
mp-wp_genesis 423 * It is confusing for the $index parameter, but just know that it should just
mp-wp_genesis 424 * work. When you register the sidebar in the theme, you will use the same name
mp-wp_genesis 425 * for this function or "Pay no heed to the man behind the curtain." Just accept
mp-wp_genesis 426 * it as an oddity of WordPress sidebar register and display.
mp-wp_genesis 427 *
mp-wp_genesis 428 * @since 2.2.0
mp-wp_genesis 429 *
mp-wp_genesis 430 * @param int|string $index Optional, default is 1. Name or ID of dynamic sidebar.
mp-wp_genesis 431 * @return bool True, if widget sidebar was found and called. False if not found or not called.
mp-wp_genesis 432 */
mp-wp_genesis 433 function dynamic_sidebar($index = 1) {
mp-wp_genesis 434 global $wp_registered_sidebars, $wp_registered_widgets;
mp-wp_genesis 435
mp-wp_genesis 436 if ( is_int($index) ) {
mp-wp_genesis 437 $index = "sidebar-$index";
mp-wp_genesis 438 } else {
mp-wp_genesis 439 $index = sanitize_title($index);
mp-wp_genesis 440 foreach ( (array) $wp_registered_sidebars as $key => $value ) {
mp-wp_genesis 441 if ( sanitize_title($value['name']) == $index ) {
mp-wp_genesis 442 $index = $key;
mp-wp_genesis 443 break;
mp-wp_genesis 444 }
mp-wp_genesis 445 }
mp-wp_genesis 446 }
mp-wp_genesis 447
mp-wp_genesis 448 $sidebars_widgets = wp_get_sidebars_widgets();
mp-wp_genesis 449
mp-wp_genesis 450 if ( empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) )
mp-wp_genesis 451 return false;
mp-wp_genesis 452
mp-wp_genesis 453 $sidebar = $wp_registered_sidebars[$index];
mp-wp_genesis 454
mp-wp_genesis 455 $did_one = false;
mp-wp_genesis 456 foreach ( (array) $sidebars_widgets[$index] as $id ) {
mp-wp_genesis 457 $params = array_merge(
mp-wp_genesis 458 array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
mp-wp_genesis 459 (array) $wp_registered_widgets[$id]['params']
mp-wp_genesis 460 );
mp-wp_genesis 461
mp-wp_genesis 462 // Substitute HTML id and class attributes into before_widget
mp-wp_genesis 463 $classname_ = '';
mp-wp_genesis 464 foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
mp-wp_genesis 465 if ( is_string($cn) )
mp-wp_genesis 466 $classname_ .= '_' . $cn;
mp-wp_genesis 467 elseif ( is_object($cn) )
mp-wp_genesis 468 $classname_ .= '_' . get_class($cn);
mp-wp_genesis 469 }
mp-wp_genesis 470 $classname_ = ltrim($classname_, '_');
mp-wp_genesis 471 $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
mp-wp_genesis 472
mp-wp_genesis 473 $params = apply_filters( 'dynamic_sidebar_params', $params );
mp-wp_genesis 474
mp-wp_genesis 475 $callback = $wp_registered_widgets[$id]['callback'];
mp-wp_genesis 476
mp-wp_genesis 477 if ( is_callable($callback) ) {
mp-wp_genesis 478 call_user_func_array($callback, $params);
mp-wp_genesis 479 $did_one = true;
mp-wp_genesis 480 }
mp-wp_genesis 481 }
mp-wp_genesis 482
mp-wp_genesis 483 return $did_one;
mp-wp_genesis 484 }
mp-wp_genesis 485
mp-wp_genesis 486 /**
mp-wp_genesis 487 * Whether widget is registered using callback with widget ID.
mp-wp_genesis 488 *
mp-wp_genesis 489 * Will only check if both parameters are used. Used to find which sidebar the
mp-wp_genesis 490 * widget is located in, but requires that both the callback and the widget ID
mp-wp_genesis 491 * be known.
mp-wp_genesis 492 *
mp-wp_genesis 493 * @since 2.2.0
mp-wp_genesis 494 *
mp-wp_genesis 495 * @param callback $callback Widget callback to check.
mp-wp_genesis 496 * @param int $widget_id Optional, but needed for checking. Widget ID.
mp-wp_genesis 497 /* @return mixed false if widget is not active or id of sidebar in which the widget is active.
mp-wp_genesis 498 */
mp-wp_genesis 499 function is_active_widget($callback, $widget_id = false) {
mp-wp_genesis 500 global $wp_registered_widgets;
mp-wp_genesis 501
mp-wp_genesis 502 $sidebars_widgets = wp_get_sidebars_widgets(false);
mp-wp_genesis 503
mp-wp_genesis 504 if ( is_array($sidebars_widgets) ) foreach ( $sidebars_widgets as $sidebar => $widgets )
mp-wp_genesis 505 if ( is_array($widgets) ) foreach ( $widgets as $widget )
mp-wp_genesis 506 if ( isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback )
mp-wp_genesis 507 if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] )
mp-wp_genesis 508 return $sidebar;
mp-wp_genesis 509
mp-wp_genesis 510
mp-wp_genesis 511 return false;
mp-wp_genesis 512 }
mp-wp_genesis 513
mp-wp_genesis 514 /**
mp-wp_genesis 515 * Whether the dynamic sidebar is enabled and used by theme.
mp-wp_genesis 516 *
mp-wp_genesis 517 * @since 2.2.0
mp-wp_genesis 518 *
mp-wp_genesis 519 * @return bool True, if using widgets. False, if not using widgets.
mp-wp_genesis 520 */
mp-wp_genesis 521 function is_dynamic_sidebar() {
mp-wp_genesis 522 global $wp_registered_widgets, $wp_registered_sidebars;
mp-wp_genesis 523 $sidebars_widgets = get_option('sidebars_widgets');
mp-wp_genesis 524 foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
mp-wp_genesis 525 if ( count($sidebars_widgets[$index]) ) {
mp-wp_genesis 526 foreach ( (array) $sidebars_widgets[$index] as $widget )
mp-wp_genesis 527 if ( array_key_exists($widget, $wp_registered_widgets) )
mp-wp_genesis 528 return true;
mp-wp_genesis 529 }
mp-wp_genesis 530 }
mp-wp_genesis 531 return false;
mp-wp_genesis 532 }
mp-wp_genesis 533
mp-wp_genesis 534 /* Internal Functions */
mp-wp_genesis 535
mp-wp_genesis 536 /**
mp-wp_genesis 537 * Retrieve full list of sidebars and their widgets.
mp-wp_genesis 538 *
mp-wp_genesis 539 * Will upgrade sidebar widget list, if needed. Will also save updated list, if
mp-wp_genesis 540 * needed.
mp-wp_genesis 541 *
mp-wp_genesis 542 * @since 2.2.0
mp-wp_genesis 543 * @access private
mp-wp_genesis 544 *
mp-wp_genesis 545 * @param bool $update Optional, default is true. Whether to save upgrade of widget array list.
mp-wp_genesis 546 * @return array Upgraded list of widgets to version 2 array format.
mp-wp_genesis 547 */
mp-wp_genesis 548 function wp_get_sidebars_widgets($update = true) {
mp-wp_genesis 549 global $wp_registered_widgets, $wp_registered_sidebars;
mp-wp_genesis 550
mp-wp_genesis 551 $sidebars_widgets = get_option('sidebars_widgets');
mp-wp_genesis 552 $_sidebars_widgets = array();
mp-wp_genesis 553
mp-wp_genesis 554 if ( !isset($sidebars_widgets['array_version']) )
mp-wp_genesis 555 $sidebars_widgets['array_version'] = 1;
mp-wp_genesis 556
mp-wp_genesis 557 switch ( $sidebars_widgets['array_version'] ) {
mp-wp_genesis 558 case 1 :
mp-wp_genesis 559 foreach ( (array) $sidebars_widgets as $index => $sidebar )
mp-wp_genesis 560 if ( is_array($sidebar) )
mp-wp_genesis 561 foreach ( (array) $sidebar as $i => $name ) {
mp-wp_genesis 562 $id = strtolower($name);
mp-wp_genesis 563 if ( isset($wp_registered_widgets[$id]) ) {
mp-wp_genesis 564 $_sidebars_widgets[$index][$i] = $id;
mp-wp_genesis 565 continue;
mp-wp_genesis 566 }
mp-wp_genesis 567 $id = sanitize_title($name);
mp-wp_genesis 568 if ( isset($wp_registered_widgets[$id]) ) {
mp-wp_genesis 569 $_sidebars_widgets[$index][$i] = $id;
mp-wp_genesis 570 continue;
mp-wp_genesis 571 }
mp-wp_genesis 572
mp-wp_genesis 573 $found = false;
mp-wp_genesis 574
mp-wp_genesis 575 foreach ( $wp_registered_widgets as $widget_id => $widget ) {
mp-wp_genesis 576 if ( strtolower($widget['name']) == strtolower($name) ) {
mp-wp_genesis 577 $_sidebars_widgets[$index][$i] = $widget['id'];
mp-wp_genesis 578 $found = true;
mp-wp_genesis 579 break;
mp-wp_genesis 580 } elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) {
mp-wp_genesis 581 $_sidebars_widgets[$index][$i] = $widget['id'];
mp-wp_genesis 582 $found = true;
mp-wp_genesis 583 break;
mp-wp_genesis 584 }
mp-wp_genesis 585 }
mp-wp_genesis 586
mp-wp_genesis 587 if ( $found )
mp-wp_genesis 588 continue;
mp-wp_genesis 589
mp-wp_genesis 590 unset($_sidebars_widgets[$index][$i]);
mp-wp_genesis 591 }
mp-wp_genesis 592 $_sidebars_widgets['array_version'] = 2;
mp-wp_genesis 593 $sidebars_widgets = $_sidebars_widgets;
mp-wp_genesis 594 unset($_sidebars_widgets);
mp-wp_genesis 595
mp-wp_genesis 596 case 2 :
mp-wp_genesis 597 $sidebars = array_keys( $wp_registered_sidebars );
mp-wp_genesis 598 if ( !empty( $sidebars ) ) {
mp-wp_genesis 599 // Move the known-good ones first
mp-wp_genesis 600 foreach ( (array) $sidebars as $id ) {
mp-wp_genesis 601 if ( array_key_exists( $id, $sidebars_widgets ) ) {
mp-wp_genesis 602 $_sidebars_widgets[$id] = $sidebars_widgets[$id];
mp-wp_genesis 603 unset($sidebars_widgets[$id], $sidebars[$id]);
mp-wp_genesis 604 }
mp-wp_genesis 605 }
mp-wp_genesis 606
mp-wp_genesis 607 // Assign to each unmatched registered sidebar the first available orphan
mp-wp_genesis 608 unset( $sidebars_widgets[ 'array_version' ] );
mp-wp_genesis 609 while ( ( $sidebar = array_shift( $sidebars ) ) && $widgets = array_shift( $sidebars_widgets ) )
mp-wp_genesis 610 $_sidebars_widgets[ $sidebar ] = $widgets;
mp-wp_genesis 611
mp-wp_genesis 612 $_sidebars_widgets['array_version'] = 3;
mp-wp_genesis 613 $sidebars_widgets = $_sidebars_widgets;
mp-wp_genesis 614 unset($_sidebars_widgets);
mp-wp_genesis 615 }
mp-wp_genesis 616
mp-wp_genesis 617 if ( $update )
mp-wp_genesis 618 update_option('sidebars_widgets', $sidebars_widgets);
mp-wp_genesis 619 }
mp-wp_genesis 620
mp-wp_genesis 621 unset($sidebars_widgets['array_version']);
mp-wp_genesis 622
mp-wp_genesis 623 $sidebars_widgets = apply_filters('sidebars_widgets', $sidebars_widgets);
mp-wp_genesis 624 return $sidebars_widgets;
mp-wp_genesis 625 }
mp-wp_genesis 626
mp-wp_genesis 627 /**
mp-wp_genesis 628 * Set the sidebar widget option to update sidebars.
mp-wp_genesis 629 *
mp-wp_genesis 630 * @since 2.2.0
mp-wp_genesis 631 * @access private
mp-wp_genesis 632 *
mp-wp_genesis 633 * @param array $sidebars_widgets Sidebar widgets and their settings.
mp-wp_genesis 634 */
mp-wp_genesis 635 function wp_set_sidebars_widgets( $sidebars_widgets ) {
mp-wp_genesis 636 if ( !isset( $sidebars_widgets['array_version'] ) )
mp-wp_genesis 637 $sidebars_widgets['array_version'] = 3;
mp-wp_genesis 638 update_option( 'sidebars_widgets', $sidebars_widgets );
mp-wp_genesis 639 }
mp-wp_genesis 640
mp-wp_genesis 641 /**
mp-wp_genesis 642 * Retrieve default registered sidebars list.
mp-wp_genesis 643 *
mp-wp_genesis 644 * @since 2.2.0
mp-wp_genesis 645 * @access private
mp-wp_genesis 646 *
mp-wp_genesis 647 * @return array
mp-wp_genesis 648 */
mp-wp_genesis 649 function wp_get_widget_defaults() {
mp-wp_genesis 650 global $wp_registered_sidebars;
mp-wp_genesis 651
mp-wp_genesis 652 $defaults = array();
mp-wp_genesis 653
mp-wp_genesis 654 foreach ( (array) $wp_registered_sidebars as $index => $sidebar )
mp-wp_genesis 655 $defaults[$index] = array();
mp-wp_genesis 656
mp-wp_genesis 657 return $defaults;
mp-wp_genesis 658 }
mp-wp_genesis 659
mp-wp_genesis 660 /* Default Widgets */
mp-wp_genesis 661
mp-wp_genesis 662 /**
mp-wp_genesis 663 * Display pages widget.
mp-wp_genesis 664 *
mp-wp_genesis 665 * @since 2.2.0
mp-wp_genesis 666 *
mp-wp_genesis 667 * @param array $args Widget arguments.
mp-wp_genesis 668 */
mp-wp_genesis 669 function wp_widget_pages( $args ) {
mp-wp_genesis 670 extract( $args );
mp-wp_genesis 671 $options = get_option( 'widget_pages' );
mp-wp_genesis 672
mp-wp_genesis 673 $title = empty( $options['title'] ) ? __( 'Pages' ) : apply_filters('widget_title', $options['title']);
mp-wp_genesis 674 $sortby = empty( $options['sortby'] ) ? 'menu_order' : $options['sortby'];
mp-wp_genesis 675 $exclude = empty( $options['exclude'] ) ? '' : $options['exclude'];
mp-wp_genesis 676
mp-wp_genesis 677 if ( $sortby == 'menu_order' ) {
mp-wp_genesis 678 $sortby = 'menu_order, post_title';
mp-wp_genesis 679 }
mp-wp_genesis 680
mp-wp_genesis 681 $out = wp_list_pages( array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) );
mp-wp_genesis 682
mp-wp_genesis 683 if ( !empty( $out ) ) {
mp-wp_genesis 684 ?>
mp-wp_genesis 685 <?php echo $before_widget; ?>
mp-wp_genesis 686 <?php echo $before_title . $title . $after_title; ?>
mp-wp_genesis 687 <ul>
mp-wp_genesis 688 <?php echo $out; ?>
mp-wp_genesis 689 </ul>
mp-wp_genesis 690 <?php echo $after_widget; ?>
mp-wp_genesis 691 <?php
mp-wp_genesis 692 }
mp-wp_genesis 693 }
mp-wp_genesis 694
mp-wp_genesis 695 /**
mp-wp_genesis 696 * Display and process pages widget options form.
mp-wp_genesis 697 *
mp-wp_genesis 698 * @since 2.2.0
mp-wp_genesis 699 */
mp-wp_genesis 700 function wp_widget_pages_control() {
mp-wp_genesis 701 $options = $newoptions = get_option('widget_pages');
mp-wp_genesis 702 if ( isset($_POST['pages-submit']) ) {
mp-wp_genesis 703 $newoptions['title'] = strip_tags(stripslashes($_POST['pages-title']));
mp-wp_genesis 704
mp-wp_genesis 705 $sortby = stripslashes( $_POST['pages-sortby'] );
mp-wp_genesis 706
mp-wp_genesis 707 if ( in_array( $sortby, array( 'post_title', 'menu_order', 'ID' ) ) ) {
mp-wp_genesis 708 $newoptions['sortby'] = $sortby;
mp-wp_genesis 709 } else {
mp-wp_genesis 710 $newoptions['sortby'] = 'menu_order';
mp-wp_genesis 711 }
mp-wp_genesis 712
mp-wp_genesis 713 $newoptions['exclude'] = strip_tags( stripslashes( $_POST['pages-exclude'] ) );
mp-wp_genesis 714 }
mp-wp_genesis 715 if ( $options != $newoptions ) {
mp-wp_genesis 716 $options = $newoptions;
mp-wp_genesis 717 update_option('widget_pages', $options);
mp-wp_genesis 718 }
mp-wp_genesis 719 $title = attribute_escape($options['title']);
mp-wp_genesis 720 $exclude = attribute_escape( $options['exclude'] );
mp-wp_genesis 721 ?>
mp-wp_genesis 722 <p><label for="pages-title"><?php _e('Title:'); ?> <input class="widefat" id="pages-title" name="pages-title" type="text" value="<?php echo $title; ?>" /></label></p>
mp-wp_genesis 723 <p>
mp-wp_genesis 724 <label for="pages-sortby"><?php _e( 'Sort by:' ); ?>
mp-wp_genesis 725 <select name="pages-sortby" id="pages-sortby" class="widefat">
mp-wp_genesis 726 <option value="post_title"<?php selected( $options['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
mp-wp_genesis 727 <option value="menu_order"<?php selected( $options['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
mp-wp_genesis 728 <option value="ID"<?php selected( $options['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
mp-wp_genesis 729 </select>
mp-wp_genesis 730 </label>
mp-wp_genesis 731 </p>
mp-wp_genesis 732 <p>
mp-wp_genesis 733 <label for="pages-exclude"><?php _e( 'Exclude:' ); ?> <input type="text" value="<?php echo $exclude; ?>" name="pages-exclude" id="pages-exclude" class="widefat" /></label>
mp-wp_genesis 734 <br />
mp-wp_genesis 735 <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
mp-wp_genesis 736 </p>
mp-wp_genesis 737 <input type="hidden" id="pages-submit" name="pages-submit" value="1" />
mp-wp_genesis 738 <?php
mp-wp_genesis 739 }
mp-wp_genesis 740
mp-wp_genesis 741 /**
mp-wp_genesis 742 * Display links widget.
mp-wp_genesis 743 *
mp-wp_genesis 744 * @since 2.2.0
mp-wp_genesis 745 *
mp-wp_genesis 746 * @param array $args Widget arguments.
mp-wp_genesis 747 */
mp-wp_genesis 748 function wp_widget_links($args) {
mp-wp_genesis 749 extract($args, EXTR_SKIP);
mp-wp_genesis 750
mp-wp_genesis 751 $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
mp-wp_genesis 752 wp_list_bookmarks(apply_filters('widget_links_args', array(
mp-wp_genesis 753 'title_before' => $before_title, 'title_after' => $after_title,
mp-wp_genesis 754 'category_before' => $before_widget, 'category_after' => $after_widget,
mp-wp_genesis 755 'show_images' => true, 'class' => 'linkcat widget'
mp-wp_genesis 756 )));
mp-wp_genesis 757 }
mp-wp_genesis 758
mp-wp_genesis 759 /**
mp-wp_genesis 760 * Display search widget.
mp-wp_genesis 761 *
mp-wp_genesis 762 * @since 2.2.0
mp-wp_genesis 763 *
mp-wp_genesis 764 * @param array $args Widget arguments.
mp-wp_genesis 765 */
mp-wp_genesis 766 function wp_widget_search($args) {
mp-wp_genesis 767 extract($args);
mp-wp_genesis 768 echo $before_widget;
mp-wp_genesis 769
mp-wp_genesis 770 // Use current theme search form if it exists
mp-wp_genesis 771 get_search_form();
mp-wp_genesis 772
mp-wp_genesis 773 echo $after_widget;
mp-wp_genesis 774 }
mp-wp_genesis 775
mp-wp_genesis 776 /**
mp-wp_genesis 777 * Display archives widget.
mp-wp_genesis 778 *
mp-wp_genesis 779 * @since 2.2.0
mp-wp_genesis 780 *
mp-wp_genesis 781 * @param array $args Widget arguments.
mp-wp_genesis 782 */
mp-wp_genesis 783 function wp_widget_archives($args) {
mp-wp_genesis 784 extract($args);
mp-wp_genesis 785 $options = get_option('widget_archives');
mp-wp_genesis 786 $c = $options['count'] ? '1' : '0';
mp-wp_genesis 787 $d = $options['dropdown'] ? '1' : '0';
mp-wp_genesis 788 $title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']);
mp-wp_genesis 789
mp-wp_genesis 790 echo $before_widget;
mp-wp_genesis 791 echo $before_title . $title . $after_title;
mp-wp_genesis 792
mp-wp_genesis 793 if($d) {
mp-wp_genesis 794 ?>
mp-wp_genesis 795 <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Month')); ?></option> <?php wp_get_archives("type=monthly&format=option&show_post_count=$c"); ?> </select>
mp-wp_genesis 796 <?php
mp-wp_genesis 797 } else {
mp-wp_genesis 798 ?>
mp-wp_genesis 799 <ul>
mp-wp_genesis 800 <?php wp_get_archives("type=monthly&show_post_count=$c"); ?>
mp-wp_genesis 801 </ul>
mp-wp_genesis 802 <?php
mp-wp_genesis 803 }
mp-wp_genesis 804
mp-wp_genesis 805 echo $after_widget;
mp-wp_genesis 806 }
mp-wp_genesis 807
mp-wp_genesis 808 /**
mp-wp_genesis 809 * Display and process archives widget options form.
mp-wp_genesis 810 *
mp-wp_genesis 811 * @since 2.2.0
mp-wp_genesis 812 */
mp-wp_genesis 813 function wp_widget_archives_control() {
mp-wp_genesis 814 $options = $newoptions = get_option('widget_archives');
mp-wp_genesis 815 if ( isset($_POST["archives-submit"]) ) {
mp-wp_genesis 816 $newoptions['count'] = isset($_POST['archives-count']);
mp-wp_genesis 817 $newoptions['dropdown'] = isset($_POST['archives-dropdown']);
mp-wp_genesis 818 $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"]));
mp-wp_genesis 819 }
mp-wp_genesis 820 if ( $options != $newoptions ) {
mp-wp_genesis 821 $options = $newoptions;
mp-wp_genesis 822 update_option('widget_archives', $options);
mp-wp_genesis 823 }
mp-wp_genesis 824 $count = $options['count'] ? 'checked="checked"' : '';
mp-wp_genesis 825 $dropdown = $options['dropdown'] ? 'checked="checked"' : '';
mp-wp_genesis 826 $title = attribute_escape($options['title']);
mp-wp_genesis 827 ?>
mp-wp_genesis 828 <p><label for="archives-title"><?php _e('Title:'); ?> <input class="widefat" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p>
mp-wp_genesis 829 <p>
mp-wp_genesis 830 <label for="archives-count"><input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /> <?php _e('Show post counts'); ?></label>
mp-wp_genesis 831 <br />
mp-wp_genesis 832 <label for="archives-dropdown"><input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="archives-dropdown" name="archives-dropdown" /> <?php _e('Display as a drop down'); ?></label>
mp-wp_genesis 833 </p>
mp-wp_genesis 834 <input type="hidden" id="archives-submit" name="archives-submit" value="1" />
mp-wp_genesis 835 <?php
mp-wp_genesis 836 }
mp-wp_genesis 837
mp-wp_genesis 838 /**
mp-wp_genesis 839 * Display meta widget.
mp-wp_genesis 840 *
mp-wp_genesis 841 * Displays log in/out, RSS feed links, etc.
mp-wp_genesis 842 *
mp-wp_genesis 843 * @since 2.2.0
mp-wp_genesis 844 *
mp-wp_genesis 845 * @param array $args Widget arguments.
mp-wp_genesis 846 */
mp-wp_genesis 847 function wp_widget_meta($args) {
mp-wp_genesis 848 extract($args);
mp-wp_genesis 849 $options = get_option('widget_meta');
mp-wp_genesis 850 $title = empty($options['title']) ? __('Meta') : apply_filters('widget_title', $options['title']);
mp-wp_genesis 851 ?>
mp-wp_genesis 852 <?php echo $before_widget; ?>
mp-wp_genesis 853 <?php echo $before_title . $title . $after_title; ?>
mp-wp_genesis 854 <ul>
mp-wp_genesis 855 <?php wp_register(); ?>
mp-wp_genesis 856 <li><?php wp_loginout(); ?></li>
mp-wp_genesis 857 <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo attribute_escape(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
mp-wp_genesis 858 <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo attribute_escape(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
mp-wp_genesis 859 <li><a href="http://wordpress.org/" title="<?php echo attribute_escape(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
mp-wp_genesis 860 <?php wp_meta(); ?>
mp-wp_genesis 861 </ul>
mp-wp_genesis 862 <?php echo $after_widget; ?>
mp-wp_genesis 863 <?php
mp-wp_genesis 864 }
mp-wp_genesis 865
mp-wp_genesis 866 /**
mp-wp_genesis 867 * Display and process meta widget options form.
mp-wp_genesis 868 *
mp-wp_genesis 869 * @since 2.2.0
mp-wp_genesis 870 */
mp-wp_genesis 871 function wp_widget_meta_control() {
mp-wp_genesis 872 $options = $newoptions = get_option('widget_meta');
mp-wp_genesis 873 if ( isset($_POST["meta-submit"]) ) {
mp-wp_genesis 874 $newoptions['title'] = strip_tags(stripslashes($_POST["meta-title"]));
mp-wp_genesis 875 }
mp-wp_genesis 876 if ( $options != $newoptions ) {
mp-wp_genesis 877 $options = $newoptions;
mp-wp_genesis 878 update_option('widget_meta', $options);
mp-wp_genesis 879 }
mp-wp_genesis 880 $title = attribute_escape($options['title']);
mp-wp_genesis 881 ?>
mp-wp_genesis 882 <p><label for="meta-title"><?php _e('Title:'); ?> <input class="widefat" id="meta-title" name="meta-title" type="text" value="<?php echo $title; ?>" /></label></p>
mp-wp_genesis 883 <input type="hidden" id="meta-submit" name="meta-submit" value="1" />
mp-wp_genesis 884 <?php
mp-wp_genesis 885 }
mp-wp_genesis 886
mp-wp_genesis 887 /**
mp-wp_genesis 888 * Display calendar widget.
mp-wp_genesis 889 *
mp-wp_genesis 890 * @since 2.2.0
mp-wp_genesis 891 *
mp-wp_genesis 892 * @param array $args Widget arguments.
mp-wp_genesis 893 */
mp-wp_genesis 894 function wp_widget_calendar($args) {
mp-wp_genesis 895 extract($args);
mp-wp_genesis 896 $options = get_option('widget_calendar');
mp-wp_genesis 897 $title = apply_filters('widget_title', $options['title']);
mp-wp_genesis 898 if ( empty($title) )
mp-wp_genesis 899 $title = ' ';
mp-wp_genesis 900 echo $before_widget . $before_title . $title . $after_title;
mp-wp_genesis 901 echo '<div id="calendar_wrap">';
mp-wp_genesis 902 get_calendar();
mp-wp_genesis 903 echo '</div>';
mp-wp_genesis 904 echo $after_widget;
mp-wp_genesis 905 }
mp-wp_genesis 906
mp-wp_genesis 907 /**
mp-wp_genesis 908 * Display and process calendar widget options form.
mp-wp_genesis 909 *
mp-wp_genesis 910 * @since 2.2.0
mp-wp_genesis 911 */
mp-wp_genesis 912 function wp_widget_calendar_control() {
mp-wp_genesis 913 $options = $newoptions = get_option('widget_calendar');
mp-wp_genesis 914 if ( isset($_POST["calendar-submit"]) ) {
mp-wp_genesis 915 $newoptions['title'] = strip_tags(stripslashes($_POST["calendar-title"]));
mp-wp_genesis 916 }
mp-wp_genesis 917 if ( $options != $newoptions ) {
mp-wp_genesis 918 $options = $newoptions;
mp-wp_genesis 919 update_option('widget_calendar', $options);
mp-wp_genesis 920 }
mp-wp_genesis 921 $title = attribute_escape($options['title']);
mp-wp_genesis 922 ?>
mp-wp_genesis 923 <p><label for="calendar-title"><?php _e('Title:'); ?> <input class="widefat" id="calendar-title" name="calendar-title" type="text" value="<?php echo $title; ?>" /></label></p>
mp-wp_genesis 924 <input type="hidden" id="calendar-submit" name="calendar-submit" value="1" />
mp-wp_genesis 925 <?php
mp-wp_genesis 926 }
mp-wp_genesis 927
mp-wp_genesis 928 /**
mp-wp_genesis 929 * Display the Text widget, depending on the widget number.
mp-wp_genesis 930 *
mp-wp_genesis 931 * Supports multiple text widgets and keeps track of the widget number by using
mp-wp_genesis 932 * the $widget_args parameter. The option 'widget_text' is used to store the
mp-wp_genesis 933 * content for the widgets. The content and title are passed through the
mp-wp_genesis 934 * 'widget_text' and 'widget_title' filters respectively.
mp-wp_genesis 935 *
mp-wp_genesis 936 * @since 2.2.0
mp-wp_genesis 937 *
mp-wp_genesis 938 * @param array $args Widget arguments.
mp-wp_genesis 939 * @param int $number Widget number.
mp-wp_genesis 940 */
mp-wp_genesis 941 function wp_widget_text($args, $widget_args = 1) {
mp-wp_genesis 942 extract( $args, EXTR_SKIP );
mp-wp_genesis 943 if ( is_numeric($widget_args) )
mp-wp_genesis 944 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 945 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 946 extract( $widget_args, EXTR_SKIP );
mp-wp_genesis 947
mp-wp_genesis 948 $options = get_option('widget_text');
mp-wp_genesis 949 if ( !isset($options[$number]) )
mp-wp_genesis 950 return;
mp-wp_genesis 951
mp-wp_genesis 952 $title = apply_filters('widget_title', $options[$number]['title']);
mp-wp_genesis 953 $text = apply_filters( 'widget_text', $options[$number]['text'] );
mp-wp_genesis 954 ?>
mp-wp_genesis 955 <?php echo $before_widget; ?>
mp-wp_genesis 956 <?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
mp-wp_genesis 957 <div class="textwidget"><?php echo $text; ?></div>
mp-wp_genesis 958 <?php echo $after_widget; ?>
mp-wp_genesis 959 <?php
mp-wp_genesis 960 }
mp-wp_genesis 961
mp-wp_genesis 962 /**
mp-wp_genesis 963 * Display and process text widget options form.
mp-wp_genesis 964 *
mp-wp_genesis 965 * @since 2.2.0
mp-wp_genesis 966 *
mp-wp_genesis 967 * @param int $widget_args Widget number.
mp-wp_genesis 968 */
mp-wp_genesis 969 function wp_widget_text_control($widget_args) {
mp-wp_genesis 970 global $wp_registered_widgets;
mp-wp_genesis 971 static $updated = false;
mp-wp_genesis 972
mp-wp_genesis 973 if ( is_numeric($widget_args) )
mp-wp_genesis 974 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 975 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 976 extract( $widget_args, EXTR_SKIP );
mp-wp_genesis 977
mp-wp_genesis 978 $options = get_option('widget_text');
mp-wp_genesis 979 if ( !is_array($options) )
mp-wp_genesis 980 $options = array();
mp-wp_genesis 981
mp-wp_genesis 982 if ( !$updated && !empty($_POST['sidebar']) ) {
mp-wp_genesis 983 $sidebar = (string) $_POST['sidebar'];
mp-wp_genesis 984
mp-wp_genesis 985 $sidebars_widgets = wp_get_sidebars_widgets();
mp-wp_genesis 986 if ( isset($sidebars_widgets[$sidebar]) )
mp-wp_genesis 987 $this_sidebar =& $sidebars_widgets[$sidebar];
mp-wp_genesis 988 else
mp-wp_genesis 989 $this_sidebar = array();
mp-wp_genesis 990
mp-wp_genesis 991 foreach ( (array) $this_sidebar as $_widget_id ) {
mp-wp_genesis 992 if ( 'wp_widget_text' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
mp-wp_genesis 993 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
mp-wp_genesis 994 if ( !in_array( "text-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
mp-wp_genesis 995 unset($options[$widget_number]);
mp-wp_genesis 996 }
mp-wp_genesis 997 }
mp-wp_genesis 998
mp-wp_genesis 999 foreach ( (array) $_POST['widget-text'] as $widget_number => $widget_text ) {
mp-wp_genesis 1000 if ( !isset($widget_text['text']) && isset($options[$widget_number]) ) // user clicked cancel
mp-wp_genesis 1001 continue;
mp-wp_genesis 1002 $title = strip_tags(stripslashes($widget_text['title']));
mp-wp_genesis 1003 if ( current_user_can('unfiltered_html') )
mp-wp_genesis 1004 $text = stripslashes( $widget_text['text'] );
mp-wp_genesis 1005 else
mp-wp_genesis 1006 $text = stripslashes(wp_filter_post_kses( $widget_text['text'] ));
mp-wp_genesis 1007 $options[$widget_number] = compact( 'title', 'text' );
mp-wp_genesis 1008 }
mp-wp_genesis 1009
mp-wp_genesis 1010 update_option('widget_text', $options);
mp-wp_genesis 1011 $updated = true;
mp-wp_genesis 1012 }
mp-wp_genesis 1013
mp-wp_genesis 1014 if ( -1 == $number ) {
mp-wp_genesis 1015 $title = '';
mp-wp_genesis 1016 $text = '';
mp-wp_genesis 1017 $number = '%i%';
mp-wp_genesis 1018 } else {
mp-wp_genesis 1019 $title = attribute_escape($options[$number]['title']);
mp-wp_genesis 1020 $text = format_to_edit($options[$number]['text']);
mp-wp_genesis 1021 }
mp-wp_genesis 1022 ?>
mp-wp_genesis 1023 <p>
mp-wp_genesis 1024 <input class="widefat" id="text-title-<?php echo $number; ?>" name="widget-text[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
mp-wp_genesis 1025 <textarea class="widefat" rows="16" cols="20" id="text-text-<?php echo $number; ?>" name="widget-text[<?php echo $number; ?>][text]"><?php echo $text; ?></textarea>
mp-wp_genesis 1026 <input type="hidden" name="widget-text[<?php echo $number; ?>][submit]" value="1" />
mp-wp_genesis 1027 </p>
mp-wp_genesis 1028 <?php
mp-wp_genesis 1029 }
mp-wp_genesis 1030
mp-wp_genesis 1031 /**
mp-wp_genesis 1032 * Register text widget on startup.
mp-wp_genesis 1033 *
mp-wp_genesis 1034 * @since 2.2.0
mp-wp_genesis 1035 */
mp-wp_genesis 1036 function wp_widget_text_register() {
mp-wp_genesis 1037 if ( !$options = get_option('widget_text') )
mp-wp_genesis 1038 $options = array();
mp-wp_genesis 1039 $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
mp-wp_genesis 1040 $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'text');
mp-wp_genesis 1041 $name = __('Text');
mp-wp_genesis 1042
mp-wp_genesis 1043 $id = false;
mp-wp_genesis 1044 foreach ( (array) array_keys($options) as $o ) {
mp-wp_genesis 1045 // Old widgets can have null values for some reason
mp-wp_genesis 1046 if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) )
mp-wp_genesis 1047 continue;
mp-wp_genesis 1048 $id = "text-$o"; // Never never never translate an id
mp-wp_genesis 1049 wp_register_sidebar_widget($id, $name, 'wp_widget_text', $widget_ops, array( 'number' => $o ));
mp-wp_genesis 1050 wp_register_widget_control($id, $name, 'wp_widget_text_control', $control_ops, array( 'number' => $o ));
mp-wp_genesis 1051 }
mp-wp_genesis 1052
mp-wp_genesis 1053 // If there are none, we register the widget's existance with a generic template
mp-wp_genesis 1054 if ( !$id ) {
mp-wp_genesis 1055 wp_register_sidebar_widget( 'text-1', $name, 'wp_widget_text', $widget_ops, array( 'number' => -1 ) );
mp-wp_genesis 1056 wp_register_widget_control( 'text-1', $name, 'wp_widget_text_control', $control_ops, array( 'number' => -1 ) );
mp-wp_genesis 1057 }
mp-wp_genesis 1058 }
mp-wp_genesis 1059
mp-wp_genesis 1060 /**
mp-wp_genesis 1061 * Display categories widget.
mp-wp_genesis 1062 *
mp-wp_genesis 1063 * Allows multiple category widgets.
mp-wp_genesis 1064 *
mp-wp_genesis 1065 * @since 2.2.0
mp-wp_genesis 1066 *
mp-wp_genesis 1067 * @param array $args Widget arguments.
mp-wp_genesis 1068 * @param int $number Widget number.
mp-wp_genesis 1069 */
mp-wp_genesis 1070 function wp_widget_categories($args, $widget_args = 1) {
mp-wp_genesis 1071 extract($args, EXTR_SKIP);
mp-wp_genesis 1072 if ( is_numeric($widget_args) )
mp-wp_genesis 1073 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 1074 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 1075 extract($widget_args, EXTR_SKIP);
mp-wp_genesis 1076
mp-wp_genesis 1077 $options = get_option('widget_categories');
mp-wp_genesis 1078 if ( !isset($options[$number]) )
mp-wp_genesis 1079 return;
mp-wp_genesis 1080
mp-wp_genesis 1081 $c = $options[$number]['count'] ? '1' : '0';
mp-wp_genesis 1082 $h = $options[$number]['hierarchical'] ? '1' : '0';
mp-wp_genesis 1083 $d = $options[$number]['dropdown'] ? '1' : '0';
mp-wp_genesis 1084
mp-wp_genesis 1085 $title = empty($options[$number]['title']) ? __('Categories') : apply_filters('widget_title', $options[$number]['title']);
mp-wp_genesis 1086
mp-wp_genesis 1087 echo $before_widget;
mp-wp_genesis 1088 echo $before_title . $title . $after_title;
mp-wp_genesis 1089
mp-wp_genesis 1090 $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
mp-wp_genesis 1091
mp-wp_genesis 1092 if ( $d ) {
mp-wp_genesis 1093 $cat_args['show_option_none'] = __('Select Category');
mp-wp_genesis 1094 wp_dropdown_categories($cat_args);
mp-wp_genesis 1095 ?>
mp-wp_genesis 1096
mp-wp_genesis 1097 <script type='text/javascript'>
mp-wp_genesis 1098 /* <![CDATA[ */
mp-wp_genesis 1099 var dropdown = document.getElementById("cat");
mp-wp_genesis 1100 function onCatChange() {
mp-wp_genesis 1101 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
mp-wp_genesis 1102 location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
mp-wp_genesis 1103 }
mp-wp_genesis 1104 }
mp-wp_genesis 1105 dropdown.onchange = onCatChange;
mp-wp_genesis 1106 /* ]]> */
mp-wp_genesis 1107 </script>
mp-wp_genesis 1108
mp-wp_genesis 1109 <?php
mp-wp_genesis 1110 } else {
mp-wp_genesis 1111 ?>
mp-wp_genesis 1112 <ul>
mp-wp_genesis 1113 <?php
mp-wp_genesis 1114 $cat_args['title_li'] = '';
mp-wp_genesis 1115 wp_list_categories($cat_args);
mp-wp_genesis 1116 ?>
mp-wp_genesis 1117 </ul>
mp-wp_genesis 1118 <?php
mp-wp_genesis 1119 }
mp-wp_genesis 1120
mp-wp_genesis 1121 echo $after_widget;
mp-wp_genesis 1122 }
mp-wp_genesis 1123
mp-wp_genesis 1124 /**
mp-wp_genesis 1125 * Display and process categories widget options form.
mp-wp_genesis 1126 *
mp-wp_genesis 1127 * @since 2.2.0
mp-wp_genesis 1128 *
mp-wp_genesis 1129 * @param int $widget_args Widget number.
mp-wp_genesis 1130 */
mp-wp_genesis 1131 function wp_widget_categories_control( $widget_args ) {
mp-wp_genesis 1132 global $wp_registered_widgets;
mp-wp_genesis 1133 static $updated = false;
mp-wp_genesis 1134
mp-wp_genesis 1135 if ( is_numeric($widget_args) )
mp-wp_genesis 1136 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 1137 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 1138 extract($widget_args, EXTR_SKIP);
mp-wp_genesis 1139
mp-wp_genesis 1140 $options = get_option('widget_categories');
mp-wp_genesis 1141
mp-wp_genesis 1142 if ( !is_array( $options ) )
mp-wp_genesis 1143 $options = array();
mp-wp_genesis 1144
mp-wp_genesis 1145 if ( !$updated && !empty($_POST['sidebar']) ) {
mp-wp_genesis 1146 $sidebar = (string) $_POST['sidebar'];
mp-wp_genesis 1147
mp-wp_genesis 1148 $sidebars_widgets = wp_get_sidebars_widgets();
mp-wp_genesis 1149 if ( isset($sidebars_widgets[$sidebar]) )
mp-wp_genesis 1150 $this_sidebar =& $sidebars_widgets[$sidebar];
mp-wp_genesis 1151 else
mp-wp_genesis 1152 $this_sidebar = array();
mp-wp_genesis 1153
mp-wp_genesis 1154 foreach ( (array) $this_sidebar as $_widget_id ) {
mp-wp_genesis 1155 if ( 'wp_widget_categories' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
mp-wp_genesis 1156 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
mp-wp_genesis 1157 if ( !in_array( "categories-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
mp-wp_genesis 1158 unset($options[$widget_number]);
mp-wp_genesis 1159 }
mp-wp_genesis 1160 }
mp-wp_genesis 1161
mp-wp_genesis 1162 foreach ( (array) $_POST['widget-categories'] as $widget_number => $widget_cat ) {
mp-wp_genesis 1163 if ( !isset($widget_cat['title']) && isset($options[$widget_number]) ) // user clicked cancel
mp-wp_genesis 1164 continue;
mp-wp_genesis 1165 $title = trim(strip_tags(stripslashes($widget_cat['title'])));
mp-wp_genesis 1166 $count = isset($widget_cat['count']);
mp-wp_genesis 1167 $hierarchical = isset($widget_cat['hierarchical']);
mp-wp_genesis 1168 $dropdown = isset($widget_cat['dropdown']);
mp-wp_genesis 1169 $options[$widget_number] = compact( 'title', 'count', 'hierarchical', 'dropdown' );
mp-wp_genesis 1170 }
mp-wp_genesis 1171
mp-wp_genesis 1172 update_option('widget_categories', $options);
mp-wp_genesis 1173 $updated = true;
mp-wp_genesis 1174 }
mp-wp_genesis 1175
mp-wp_genesis 1176 if ( -1 == $number ) {
mp-wp_genesis 1177 $title = '';
mp-wp_genesis 1178 $count = false;
mp-wp_genesis 1179 $hierarchical = false;
mp-wp_genesis 1180 $dropdown = false;
mp-wp_genesis 1181 $number = '%i%';
mp-wp_genesis 1182 } else {
mp-wp_genesis 1183 $title = attribute_escape( $options[$number]['title'] );
mp-wp_genesis 1184 $count = (bool) $options[$number]['count'];
mp-wp_genesis 1185 $hierarchical = (bool) $options[$number]['hierarchical'];
mp-wp_genesis 1186 $dropdown = (bool) $options[$number]['dropdown'];
mp-wp_genesis 1187 }
mp-wp_genesis 1188 ?>
mp-wp_genesis 1189 <p>
mp-wp_genesis 1190 <label for="categories-title-<?php echo $number; ?>">
mp-wp_genesis 1191 <?php _e( 'Title:' ); ?>
mp-wp_genesis 1192 <input class="widefat" id="categories-title-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
mp-wp_genesis 1193 </label>
mp-wp_genesis 1194 </p>
mp-wp_genesis 1195
mp-wp_genesis 1196 <p>
mp-wp_genesis 1197 <label for="categories-dropdown-<?php echo $number; ?>">
mp-wp_genesis 1198 <input type="checkbox" class="checkbox" id="categories-dropdown-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][dropdown]"<?php checked( $dropdown, true ); ?> />
mp-wp_genesis 1199 <?php _e( 'Show as dropdown' ); ?>
mp-wp_genesis 1200 </label>
mp-wp_genesis 1201 <br />
mp-wp_genesis 1202 <label for="categories-count-<?php echo $number; ?>">
mp-wp_genesis 1203 <input type="checkbox" class="checkbox" id="categories-count-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][count]"<?php checked( $count, true ); ?> />
mp-wp_genesis 1204 <?php _e( 'Show post counts' ); ?>
mp-wp_genesis 1205 </label>
mp-wp_genesis 1206 <br />
mp-wp_genesis 1207 <label for="categories-hierarchical-<?php echo $number; ?>">
mp-wp_genesis 1208 <input type="checkbox" class="checkbox" id="categories-hierarchical-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][hierarchical]"<?php checked( $hierarchical, true ); ?> />
mp-wp_genesis 1209 <?php _e( 'Show hierarchy' ); ?>
mp-wp_genesis 1210 </label>
mp-wp_genesis 1211 </p>
mp-wp_genesis 1212
mp-wp_genesis 1213 <input type="hidden" name="widget-categories[<?php echo $number; ?>][submit]" value="1" />
mp-wp_genesis 1214 <?php
mp-wp_genesis 1215 }
mp-wp_genesis 1216
mp-wp_genesis 1217 /**
mp-wp_genesis 1218 * Register categories widget on startup.
mp-wp_genesis 1219 *
mp-wp_genesis 1220 * @since 2.3.0
mp-wp_genesis 1221 */
mp-wp_genesis 1222 function wp_widget_categories_register() {
mp-wp_genesis 1223 if ( !$options = get_option( 'widget_categories' ) )
mp-wp_genesis 1224 $options = array();
mp-wp_genesis 1225
mp-wp_genesis 1226 if ( isset($options['title']) )
mp-wp_genesis 1227 $options = wp_widget_categories_upgrade();
mp-wp_genesis 1228
mp-wp_genesis 1229 $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
mp-wp_genesis 1230
mp-wp_genesis 1231 $name = __( 'Categories' );
mp-wp_genesis 1232
mp-wp_genesis 1233 $id = false;
mp-wp_genesis 1234 foreach ( (array) array_keys($options) as $o ) {
mp-wp_genesis 1235 // Old widgets can have null values for some reason
mp-wp_genesis 1236 if ( !isset($options[$o]['title']) )
mp-wp_genesis 1237 continue;
mp-wp_genesis 1238 $id = "categories-$o";
mp-wp_genesis 1239 wp_register_sidebar_widget( $id, $name, 'wp_widget_categories', $widget_ops, array( 'number' => $o ) );
mp-wp_genesis 1240 wp_register_widget_control( $id, $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => $o ) );
mp-wp_genesis 1241 }
mp-wp_genesis 1242
mp-wp_genesis 1243 // If there are none, we register the widget's existance with a generic template
mp-wp_genesis 1244 if ( !$id ) {
mp-wp_genesis 1245 wp_register_sidebar_widget( 'categories-1', $name, 'wp_widget_categories', $widget_ops, array( 'number' => -1 ) );
mp-wp_genesis 1246 wp_register_widget_control( 'categories-1', $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => -1 ) );
mp-wp_genesis 1247 }
mp-wp_genesis 1248 }
mp-wp_genesis 1249
mp-wp_genesis 1250 /**
mp-wp_genesis 1251 * Upgrade previous category widget to current version.
mp-wp_genesis 1252 *
mp-wp_genesis 1253 * @since 2.3.0
mp-wp_genesis 1254 *
mp-wp_genesis 1255 * @return array
mp-wp_genesis 1256 */
mp-wp_genesis 1257 function wp_widget_categories_upgrade() {
mp-wp_genesis 1258 $options = get_option( 'widget_categories' );
mp-wp_genesis 1259
mp-wp_genesis 1260 if ( !isset( $options['title'] ) )
mp-wp_genesis 1261 return $options;
mp-wp_genesis 1262
mp-wp_genesis 1263 $newoptions = array( 1 => $options );
mp-wp_genesis 1264
mp-wp_genesis 1265 update_option( 'widget_categories', $newoptions );
mp-wp_genesis 1266
mp-wp_genesis 1267 $sidebars_widgets = get_option( 'sidebars_widgets' );
mp-wp_genesis 1268 if ( is_array( $sidebars_widgets ) ) {
mp-wp_genesis 1269 foreach ( $sidebars_widgets as $sidebar => $widgets ) {
mp-wp_genesis 1270 if ( is_array( $widgets ) ) {
mp-wp_genesis 1271 foreach ( $widgets as $widget )
mp-wp_genesis 1272 $new_widgets[$sidebar][] = ( $widget == 'categories' ) ? 'categories-1' : $widget;
mp-wp_genesis 1273 } else {
mp-wp_genesis 1274 $new_widgets[$sidebar] = $widgets;
mp-wp_genesis 1275 }
mp-wp_genesis 1276 }
mp-wp_genesis 1277 if ( $new_widgets != $sidebars_widgets )
mp-wp_genesis 1278 update_option( 'sidebars_widgets', $new_widgets );
mp-wp_genesis 1279 }
mp-wp_genesis 1280
mp-wp_genesis 1281 return $newoptions;
mp-wp_genesis 1282 }
mp-wp_genesis 1283
mp-wp_genesis 1284 /**
mp-wp_genesis 1285 * Display recent entries widget.
mp-wp_genesis 1286 *
mp-wp_genesis 1287 * @since 2.2.0
mp-wp_genesis 1288 *
mp-wp_genesis 1289 * @param array $args Widget arguments.
mp-wp_genesis 1290 * @return int Displayed cache.
mp-wp_genesis 1291 */
mp-wp_genesis 1292 function wp_widget_recent_entries($args) {
mp-wp_genesis 1293 if ( '%BEG_OF_TITLE%' != $args['before_title'] ) {
mp-wp_genesis 1294 if ( $output = wp_cache_get('widget_recent_entries', 'widget') )
mp-wp_genesis 1295 return print($output);
mp-wp_genesis 1296 ob_start();
mp-wp_genesis 1297 }
mp-wp_genesis 1298
mp-wp_genesis 1299 extract($args);
mp-wp_genesis 1300 $options = get_option('widget_recent_entries');
mp-wp_genesis 1301 $title = empty($options['title']) ? __('Recent Posts') : apply_filters('widget_title', $options['title']);
mp-wp_genesis 1302 if ( !$number = (int) $options['number'] )
mp-wp_genesis 1303 $number = 10;
mp-wp_genesis 1304 else if ( $number < 1 )
mp-wp_genesis 1305 $number = 1;
mp-wp_genesis 1306 else if ( $number > 15 )
mp-wp_genesis 1307 $number = 15;
mp-wp_genesis 1308
mp-wp_genesis 1309 $r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
mp-wp_genesis 1310 if ($r->have_posts()) :
mp-wp_genesis 1311 ?>
mp-wp_genesis 1312 <?php echo $before_widget; ?>
mp-wp_genesis 1313 <?php echo $before_title . $title . $after_title; ?>
mp-wp_genesis 1314 <ul>
mp-wp_genesis 1315 <?php while ($r->have_posts()) : $r->the_post(); ?>
mp-wp_genesis 1316 <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
mp-wp_genesis 1317 <?php endwhile; ?>
mp-wp_genesis 1318 </ul>
mp-wp_genesis 1319 <?php echo $after_widget; ?>
mp-wp_genesis 1320 <?php
mp-wp_genesis 1321 wp_reset_query(); // Restore global post data stomped by the_post().
mp-wp_genesis 1322 endif;
mp-wp_genesis 1323
mp-wp_genesis 1324 if ( '%BEG_OF_TITLE%' != $args['before_title'] )
mp-wp_genesis 1325 wp_cache_add('widget_recent_entries', ob_get_flush(), 'widget');
mp-wp_genesis 1326 }
mp-wp_genesis 1327
mp-wp_genesis 1328 /**
mp-wp_genesis 1329 * Remove recent entries widget items cache.
mp-wp_genesis 1330 *
mp-wp_genesis 1331 * @since 2.2.0
mp-wp_genesis 1332 */
mp-wp_genesis 1333 function wp_flush_widget_recent_entries() {
mp-wp_genesis 1334 wp_cache_delete('widget_recent_entries', 'widget');
mp-wp_genesis 1335 }
mp-wp_genesis 1336
mp-wp_genesis 1337 add_action('save_post', 'wp_flush_widget_recent_entries');
mp-wp_genesis 1338 add_action('deleted_post', 'wp_flush_widget_recent_entries');
mp-wp_genesis 1339 add_action('switch_theme', 'wp_flush_widget_recent_entries');
mp-wp_genesis 1340
mp-wp_genesis 1341 /**
mp-wp_genesis 1342 * Display and process recent entries widget options form.
mp-wp_genesis 1343 *
mp-wp_genesis 1344 * @since 2.2.0
mp-wp_genesis 1345 */
mp-wp_genesis 1346 function wp_widget_recent_entries_control() {
mp-wp_genesis 1347 $options = $newoptions = get_option('widget_recent_entries');
mp-wp_genesis 1348 if ( isset($_POST["recent-entries-submit"]) ) {
mp-wp_genesis 1349 $newoptions['title'] = strip_tags(stripslashes($_POST["recent-entries-title"]));
mp-wp_genesis 1350 $newoptions['number'] = (int) $_POST["recent-entries-number"];
mp-wp_genesis 1351 }
mp-wp_genesis 1352 if ( $options != $newoptions ) {
mp-wp_genesis 1353 $options = $newoptions;
mp-wp_genesis 1354 update_option('widget_recent_entries', $options);
mp-wp_genesis 1355 wp_flush_widget_recent_entries();
mp-wp_genesis 1356 }
mp-wp_genesis 1357 $title = attribute_escape($options['title']);
mp-wp_genesis 1358 if ( !$number = (int) $options['number'] )
mp-wp_genesis 1359 $number = 5;
mp-wp_genesis 1360 ?>
mp-wp_genesis 1361
mp-wp_genesis 1362 <p><label for="recent-entries-title"><?php _e('Title:'); ?> <input class="widefat" id="recent-entries-title" name="recent-entries-title" type="text" value="<?php echo $title; ?>" /></label></p>
mp-wp_genesis 1363 <p>
mp-wp_genesis 1364 <label for="recent-entries-number"><?php _e('Number of posts to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-entries-number" name="recent-entries-number" type="text" value="<?php echo $number; ?>" /></label>
mp-wp_genesis 1365 <br />
mp-wp_genesis 1366 <small><?php _e('(at most 15)'); ?></small>
mp-wp_genesis 1367 </p>
mp-wp_genesis 1368 <input type="hidden" id="recent-entries-submit" name="recent-entries-submit" value="1" />
mp-wp_genesis 1369 <?php
mp-wp_genesis 1370 }
mp-wp_genesis 1371
mp-wp_genesis 1372 /**
mp-wp_genesis 1373 * Display recent comments widget.
mp-wp_genesis 1374 *
mp-wp_genesis 1375 * @since 2.2.0
mp-wp_genesis 1376 *
mp-wp_genesis 1377 * @param array $args Widget arguments.
mp-wp_genesis 1378 */
mp-wp_genesis 1379 function wp_widget_recent_comments($args) {
mp-wp_genesis 1380 global $wpdb, $comments, $comment;
mp-wp_genesis 1381 extract($args, EXTR_SKIP);
mp-wp_genesis 1382 $options = get_option('widget_recent_comments');
mp-wp_genesis 1383 $title = empty($options['title']) ? __('Recent Comments') : apply_filters('widget_title', $options['title']);
mp-wp_genesis 1384 if ( !$number = (int) $options['number'] )
mp-wp_genesis 1385 $number = 5;
mp-wp_genesis 1386 else if ( $number < 1 )
mp-wp_genesis 1387 $number = 1;
mp-wp_genesis 1388 else if ( $number > 15 )
mp-wp_genesis 1389 $number = 15;
mp-wp_genesis 1390
mp-wp_genesis 1391 if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
mp-wp_genesis 1392 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
mp-wp_genesis 1393 wp_cache_add( 'recent_comments', $comments, 'widget' );
mp-wp_genesis 1394 }
mp-wp_genesis 1395 ?>
mp-wp_genesis 1396
mp-wp_genesis 1397 <?php echo $before_widget; ?>
mp-wp_genesis 1398 <?php echo $before_title . $title . $after_title; ?>
mp-wp_genesis 1399 <ul id="recentcomments"><?php
mp-wp_genesis 1400 if ( $comments ) : foreach ( (array) $comments as $comment) :
mp-wp_genesis 1401 echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
mp-wp_genesis 1402 endforeach; endif;?></ul>
mp-wp_genesis 1403 <?php echo $after_widget; ?>
mp-wp_genesis 1404 <?php
mp-wp_genesis 1405 }
mp-wp_genesis 1406
mp-wp_genesis 1407 /**
mp-wp_genesis 1408 * Remove the cache for recent comments widget.
mp-wp_genesis 1409 *
mp-wp_genesis 1410 * @since 2.2.0
mp-wp_genesis 1411 */
mp-wp_genesis 1412 function wp_delete_recent_comments_cache() {
mp-wp_genesis 1413 wp_cache_delete( 'recent_comments', 'widget' );
mp-wp_genesis 1414 }
mp-wp_genesis 1415 add_action( 'comment_post', 'wp_delete_recent_comments_cache' );
mp-wp_genesis 1416 add_action( 'wp_set_comment_status', 'wp_delete_recent_comments_cache' );
mp-wp_genesis 1417
mp-wp_genesis 1418 /**
mp-wp_genesis 1419 * Display and process recent comments widget options form.
mp-wp_genesis 1420 *
mp-wp_genesis 1421 * @since 2.2.0
mp-wp_genesis 1422 */
mp-wp_genesis 1423 function wp_widget_recent_comments_control() {
mp-wp_genesis 1424 $options = $newoptions = get_option('widget_recent_comments');
mp-wp_genesis 1425 if ( isset($_POST["recent-comments-submit"]) ) {
mp-wp_genesis 1426 $newoptions['title'] = strip_tags(stripslashes($_POST["recent-comments-title"]));
mp-wp_genesis 1427 $newoptions['number'] = (int) $_POST["recent-comments-number"];
mp-wp_genesis 1428 }
mp-wp_genesis 1429 if ( $options != $newoptions ) {
mp-wp_genesis 1430 $options = $newoptions;
mp-wp_genesis 1431 update_option('widget_recent_comments', $options);
mp-wp_genesis 1432 wp_delete_recent_comments_cache();
mp-wp_genesis 1433 }
mp-wp_genesis 1434 $title = attribute_escape($options['title']);
mp-wp_genesis 1435 if ( !$number = (int) $options['number'] )
mp-wp_genesis 1436 $number = 5;
mp-wp_genesis 1437 ?>
mp-wp_genesis 1438 <p><label for="recent-comments-title"><?php _e('Title:'); ?> <input class="widefat" id="recent-comments-title" name="recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p>
mp-wp_genesis 1439 <p>
mp-wp_genesis 1440 <label for="recent-comments-number"><?php _e('Number of comments to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-comments-number" name="recent-comments-number" type="text" value="<?php echo $number; ?>" /></label>
mp-wp_genesis 1441 <br />
mp-wp_genesis 1442 <small><?php _e('(at most 15)'); ?></small>
mp-wp_genesis 1443 </p>
mp-wp_genesis 1444 <input type="hidden" id="recent-comments-submit" name="recent-comments-submit" value="1" />
mp-wp_genesis 1445 <?php
mp-wp_genesis 1446 }
mp-wp_genesis 1447
mp-wp_genesis 1448 /**
mp-wp_genesis 1449 * Display the style for recent comments widget.
mp-wp_genesis 1450 *
mp-wp_genesis 1451 * @since 2.2.0
mp-wp_genesis 1452 */
mp-wp_genesis 1453 function wp_widget_recent_comments_style() {
mp-wp_genesis 1454 ?>
mp-wp_genesis 1455 <style type="text/css">.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}</style>
mp-wp_genesis 1456 <?php
mp-wp_genesis 1457 }
mp-wp_genesis 1458
mp-wp_genesis 1459 /**
mp-wp_genesis 1460 * Register recent comments with control and hook for 'wp_head' action.
mp-wp_genesis 1461 *
mp-wp_genesis 1462 * @since 2.2.0
mp-wp_genesis 1463 */
mp-wp_genesis 1464 function wp_widget_recent_comments_register() {
mp-wp_genesis 1465 $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
mp-wp_genesis 1466 wp_register_sidebar_widget('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments', $widget_ops);
mp-wp_genesis 1467 wp_register_widget_control('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments_control');
mp-wp_genesis 1468
mp-wp_genesis 1469 if ( is_active_widget('wp_widget_recent_comments') )
mp-wp_genesis 1470 add_action('wp_head', 'wp_widget_recent_comments_style');
mp-wp_genesis 1471 }
mp-wp_genesis 1472
mp-wp_genesis 1473 /**
mp-wp_genesis 1474 * Display RSS widget.
mp-wp_genesis 1475 *
mp-wp_genesis 1476 * Allows for multiple widgets to be displayed.
mp-wp_genesis 1477 *
mp-wp_genesis 1478 * @since 2.2.0
mp-wp_genesis 1479 *
mp-wp_genesis 1480 * @param array $args Widget arguments.
mp-wp_genesis 1481 * @param int $number Widget number.
mp-wp_genesis 1482 */
mp-wp_genesis 1483 function wp_widget_rss($args, $widget_args = 1) {
mp-wp_genesis 1484 extract($args, EXTR_SKIP);
mp-wp_genesis 1485 if ( is_numeric($widget_args) )
mp-wp_genesis 1486 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 1487 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 1488 extract($widget_args, EXTR_SKIP);
mp-wp_genesis 1489
mp-wp_genesis 1490 $options = get_option('widget_rss');
mp-wp_genesis 1491
mp-wp_genesis 1492 if ( !isset($options[$number]) )
mp-wp_genesis 1493 return;
mp-wp_genesis 1494
mp-wp_genesis 1495 if ( isset($options[$number]['error']) && $options[$number]['error'] )
mp-wp_genesis 1496 return;
mp-wp_genesis 1497
mp-wp_genesis 1498 $url = $options[$number]['url'];
mp-wp_genesis 1499 while ( strstr($url, 'http') != $url )
mp-wp_genesis 1500 $url = substr($url, 1);
mp-wp_genesis 1501 if ( empty($url) )
mp-wp_genesis 1502 return;
mp-wp_genesis 1503
mp-wp_genesis 1504 require_once(ABSPATH . WPINC . '/rss.php');
mp-wp_genesis 1505
mp-wp_genesis 1506 $rss = fetch_rss($url);
mp-wp_genesis 1507 $link = clean_url(strip_tags($rss->channel['link']));
mp-wp_genesis 1508 while ( strstr($link, 'http') != $link )
mp-wp_genesis 1509 $link = substr($link, 1);
mp-wp_genesis 1510 $desc = attribute_escape(strip_tags(html_entity_decode($rss->channel['description'], ENT_QUOTES)));
mp-wp_genesis 1511 $title = $options[$number]['title'];
mp-wp_genesis 1512 if ( empty($title) )
mp-wp_genesis 1513 $title = htmlentities(strip_tags($rss->channel['title']));
mp-wp_genesis 1514 if ( empty($title) )
mp-wp_genesis 1515 $title = $desc;
mp-wp_genesis 1516 if ( empty($title) )
mp-wp_genesis 1517 $title = __('Unknown Feed');
mp-wp_genesis 1518 $title = apply_filters('widget_title', $title );
mp-wp_genesis 1519 $url = clean_url(strip_tags($url));
mp-wp_genesis 1520 if ( file_exists(dirname(__FILE__) . '/rss.png') )
mp-wp_genesis 1521 $icon = str_replace(ABSPATH, site_url() . '/', dirname(__FILE__)) . '/rss.png';
mp-wp_genesis 1522 else
mp-wp_genesis 1523 $icon = includes_url('images/rss.png');
mp-wp_genesis 1524 $title = "<a class='rsswidget' href='$url' title='" . attribute_escape(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
mp-wp_genesis 1525
mp-wp_genesis 1526 echo $before_widget;
mp-wp_genesis 1527 echo $before_title . $title . $after_title;
mp-wp_genesis 1528
mp-wp_genesis 1529 wp_widget_rss_output( $rss, $options[$number] );
mp-wp_genesis 1530
mp-wp_genesis 1531 echo $after_widget;
mp-wp_genesis 1532 }
mp-wp_genesis 1533
mp-wp_genesis 1534 /**
mp-wp_genesis 1535 * Display the RSS entries in a list.
mp-wp_genesis 1536 *
mp-wp_genesis 1537 * @since 2.5.0
mp-wp_genesis 1538 *
mp-wp_genesis 1539 * @param string|array|object $rss RSS url.
mp-wp_genesis 1540 * @param array $args Widget arguments.
mp-wp_genesis 1541 */
mp-wp_genesis 1542 function wp_widget_rss_output( $rss, $args = array() ) {
mp-wp_genesis 1543 if ( is_string( $rss ) ) {
mp-wp_genesis 1544 require_once(ABSPATH . WPINC . '/rss.php');
mp-wp_genesis 1545 if ( !$rss = fetch_rss($rss) )
mp-wp_genesis 1546 return;
mp-wp_genesis 1547 } elseif ( is_array($rss) && isset($rss['url']) ) {
mp-wp_genesis 1548 require_once(ABSPATH . WPINC . '/rss.php');
mp-wp_genesis 1549 $args = $rss;
mp-wp_genesis 1550 if ( !$rss = fetch_rss($rss['url']) )
mp-wp_genesis 1551 return;
mp-wp_genesis 1552 } elseif ( !is_object($rss) ) {
mp-wp_genesis 1553 return;
mp-wp_genesis 1554 }
mp-wp_genesis 1555
mp-wp_genesis 1556 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
mp-wp_genesis 1557 $args = wp_parse_args( $args, $default_args );
mp-wp_genesis 1558 extract( $args, EXTR_SKIP );
mp-wp_genesis 1559
mp-wp_genesis 1560 $items = (int) $items;
mp-wp_genesis 1561 if ( $items < 1 || 20 < $items )
mp-wp_genesis 1562 $items = 10;
mp-wp_genesis 1563 $show_summary = (int) $show_summary;
mp-wp_genesis 1564 $show_author = (int) $show_author;
mp-wp_genesis 1565 $show_date = (int) $show_date;
mp-wp_genesis 1566
mp-wp_genesis 1567 if ( is_array( $rss->items ) && !empty( $rss->items ) ) {
mp-wp_genesis 1568 $rss->items = array_slice($rss->items, 0, $items);
mp-wp_genesis 1569 echo '<ul>';
mp-wp_genesis 1570 foreach ( (array) $rss->items as $item ) {
mp-wp_genesis 1571 while ( strstr($item['link'], 'http') != $item['link'] )
mp-wp_genesis 1572 $item['link'] = substr($item['link'], 1);
mp-wp_genesis 1573 $link = clean_url(strip_tags($item['link']));
mp-wp_genesis 1574 $title = attribute_escape(strip_tags($item['title']));
mp-wp_genesis 1575 if ( empty($title) )
mp-wp_genesis 1576 $title = __('Untitled');
mp-wp_genesis 1577 $desc = '';
mp-wp_genesis 1578 if ( isset( $item['description'] ) && is_string( $item['description'] ) )
mp-wp_genesis 1579 $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES))));
mp-wp_genesis 1580 elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) )
mp-wp_genesis 1581 $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['summary'], ENT_QUOTES))));
mp-wp_genesis 1582 if ( 360 < strlen( $desc ) )
mp-wp_genesis 1583 $desc = wp_html_excerpt( $desc, 360 ) . ' […]';
mp-wp_genesis 1584 $summary = $desc;
mp-wp_genesis 1585
mp-wp_genesis 1586 if ( $show_summary ) {
mp-wp_genesis 1587 $desc = '';
mp-wp_genesis 1588 $summary = wp_specialchars( $summary );
mp-wp_genesis 1589 $summary = "<div class='rssSummary'>$summary</div>";
mp-wp_genesis 1590 } else {
mp-wp_genesis 1591 $summary = '';
mp-wp_genesis 1592 }
mp-wp_genesis 1593
mp-wp_genesis 1594 $date = '';
mp-wp_genesis 1595 if ( $show_date ) {
mp-wp_genesis 1596 if ( isset($item['pubdate']) )
mp-wp_genesis 1597 $date = $item['pubdate'];
mp-wp_genesis 1598 elseif ( isset($item['published']) )
mp-wp_genesis 1599 $date = $item['published'];
mp-wp_genesis 1600
mp-wp_genesis 1601 if ( $date ) {
mp-wp_genesis 1602 if ( $date_stamp = strtotime( $date ) )
mp-wp_genesis 1603 $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>';
mp-wp_genesis 1604 else
mp-wp_genesis 1605 $date = '';
mp-wp_genesis 1606 }
mp-wp_genesis 1607 }
mp-wp_genesis 1608
mp-wp_genesis 1609 $author = '';
mp-wp_genesis 1610 if ( $show_author ) {
mp-wp_genesis 1611 if ( isset($item['dc']['creator']) )
mp-wp_genesis 1612 $author = ' <cite>' . wp_specialchars( strip_tags( $item['dc']['creator'] ) ) . '</cite>';
mp-wp_genesis 1613 elseif ( isset($item['author_name']) )
mp-wp_genesis 1614 $author = ' <cite>' . wp_specialchars( strip_tags( $item['author_name'] ) ) . '</cite>';
mp-wp_genesis 1615 }
mp-wp_genesis 1616
mp-wp_genesis 1617 if ( $link == '' ) {
mp-wp_genesis 1618 echo "<li>$title{$date}{$summary}{$author}</li>";
mp-wp_genesis 1619 } else {
mp-wp_genesis 1620 echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
mp-wp_genesis 1621 }
mp-wp_genesis 1622 }
mp-wp_genesis 1623 echo '</ul>';
mp-wp_genesis 1624 } else {
mp-wp_genesis 1625 echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
mp-wp_genesis 1626 }
mp-wp_genesis 1627 }
mp-wp_genesis 1628
mp-wp_genesis 1629 /**
mp-wp_genesis 1630 * Display and process RSS widget control form.
mp-wp_genesis 1631 *
mp-wp_genesis 1632 * @since 2.2.0
mp-wp_genesis 1633 *
mp-wp_genesis 1634 * @param int $widget_args Widget number.
mp-wp_genesis 1635 */
mp-wp_genesis 1636 function wp_widget_rss_control($widget_args) {
mp-wp_genesis 1637 global $wp_registered_widgets;
mp-wp_genesis 1638 static $updated = false;
mp-wp_genesis 1639
mp-wp_genesis 1640 if ( is_numeric($widget_args) )
mp-wp_genesis 1641 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 1642 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 1643 extract($widget_args, EXTR_SKIP);
mp-wp_genesis 1644
mp-wp_genesis 1645 $options = get_option('widget_rss');
mp-wp_genesis 1646 if ( !is_array($options) )
mp-wp_genesis 1647 $options = array();
mp-wp_genesis 1648
mp-wp_genesis 1649 $urls = array();
mp-wp_genesis 1650 foreach ( (array) $options as $option )
mp-wp_genesis 1651 if ( isset($option['url']) )
mp-wp_genesis 1652 $urls[$option['url']] = true;
mp-wp_genesis 1653
mp-wp_genesis 1654 if ( !$updated && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['sidebar']) ) {
mp-wp_genesis 1655 $sidebar = (string) $_POST['sidebar'];
mp-wp_genesis 1656
mp-wp_genesis 1657 $sidebars_widgets = wp_get_sidebars_widgets();
mp-wp_genesis 1658 if ( isset($sidebars_widgets[$sidebar]) )
mp-wp_genesis 1659 $this_sidebar =& $sidebars_widgets[$sidebar];
mp-wp_genesis 1660 else
mp-wp_genesis 1661 $this_sidebar = array();
mp-wp_genesis 1662
mp-wp_genesis 1663 foreach ( (array) $this_sidebar as $_widget_id ) {
mp-wp_genesis 1664 if ( 'wp_widget_rss' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
mp-wp_genesis 1665 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
mp-wp_genesis 1666 if ( !in_array( "rss-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
mp-wp_genesis 1667 unset($options[$widget_number]);
mp-wp_genesis 1668 }
mp-wp_genesis 1669 }
mp-wp_genesis 1670
mp-wp_genesis 1671 foreach( (array) $_POST['widget-rss'] as $widget_number => $widget_rss ) {
mp-wp_genesis 1672 if ( !isset($widget_rss['url']) && isset($options[$widget_number]) ) // user clicked cancel
mp-wp_genesis 1673 continue;
mp-wp_genesis 1674 $widget_rss = stripslashes_deep( $widget_rss );
mp-wp_genesis 1675 $url = sanitize_url(strip_tags($widget_rss['url']));
mp-wp_genesis 1676 $options[$widget_number] = wp_widget_rss_process( $widget_rss, !isset($urls[$url]) );
mp-wp_genesis 1677 }
mp-wp_genesis 1678
mp-wp_genesis 1679 update_option('widget_rss', $options);
mp-wp_genesis 1680 $updated = true;
mp-wp_genesis 1681 }
mp-wp_genesis 1682
mp-wp_genesis 1683 if ( -1 == $number ) {
mp-wp_genesis 1684 $title = '';
mp-wp_genesis 1685 $url = '';
mp-wp_genesis 1686 $items = 10;
mp-wp_genesis 1687 $error = false;
mp-wp_genesis 1688 $number = '%i%';
mp-wp_genesis 1689 $show_summary = 0;
mp-wp_genesis 1690 $show_author = 0;
mp-wp_genesis 1691 $show_date = 0;
mp-wp_genesis 1692 } else {
mp-wp_genesis 1693 extract( (array) $options[$number] );
mp-wp_genesis 1694 }
mp-wp_genesis 1695
mp-wp_genesis 1696 wp_widget_rss_form( compact( 'number', 'title', 'url', 'items', 'error', 'show_summary', 'show_author', 'show_date' ) );
mp-wp_genesis 1697 }
mp-wp_genesis 1698
mp-wp_genesis 1699 /**
mp-wp_genesis 1700 * Display RSS widget options form.
mp-wp_genesis 1701 *
mp-wp_genesis 1702 * The options for what fields are displayed for the RSS form are all booleans
mp-wp_genesis 1703 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
mp-wp_genesis 1704 * 'show_date'.
mp-wp_genesis 1705 *
mp-wp_genesis 1706 * @since 2.5.0
mp-wp_genesis 1707 *
mp-wp_genesis 1708 * @param array|string $args Values for input fields.
mp-wp_genesis 1709 * @param array $inputs Override default display options.
mp-wp_genesis 1710 */
mp-wp_genesis 1711 function wp_widget_rss_form( $args, $inputs = null ) {
mp-wp_genesis 1712
mp-wp_genesis 1713 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
mp-wp_genesis 1714 $inputs = wp_parse_args( $inputs, $default_inputs );
mp-wp_genesis 1715 extract( $args );
mp-wp_genesis 1716 extract( $inputs, EXTR_SKIP);
mp-wp_genesis 1717
mp-wp_genesis 1718 $number = attribute_escape( $number );
mp-wp_genesis 1719 $title = attribute_escape( $title );
mp-wp_genesis 1720 $url = attribute_escape( $url );
mp-wp_genesis 1721 $items = (int) $items;
mp-wp_genesis 1722 if ( $items < 1 || 20 < $items )
mp-wp_genesis 1723 $items = 10;
mp-wp_genesis 1724 $show_summary = (int) $show_summary;
mp-wp_genesis 1725 $show_author = (int) $show_author;
mp-wp_genesis 1726 $show_date = (int) $show_date;
mp-wp_genesis 1727
mp-wp_genesis 1728 if ( $inputs['url'] ) :
mp-wp_genesis 1729 ?>
mp-wp_genesis 1730 <p>
mp-wp_genesis 1731 <label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?>
mp-wp_genesis 1732 <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" />
mp-wp_genesis 1733 </label>
mp-wp_genesis 1734 </p>
mp-wp_genesis 1735 <?php endif; if ( $inputs['title'] ) : ?>
mp-wp_genesis 1736 <p>
mp-wp_genesis 1737 <label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?>
mp-wp_genesis 1738 <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
mp-wp_genesis 1739 </label>
mp-wp_genesis 1740 </p>
mp-wp_genesis 1741 <?php endif; if ( $inputs['items'] ) : ?>
mp-wp_genesis 1742 <p>
mp-wp_genesis 1743 <label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?>
mp-wp_genesis 1744 <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
mp-wp_genesis 1745 <?php
mp-wp_genesis 1746 for ( $i = 1; $i <= 20; ++$i )
mp-wp_genesis 1747 echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
mp-wp_genesis 1748 ?>
mp-wp_genesis 1749 </select>
mp-wp_genesis 1750 </label>
mp-wp_genesis 1751 </p>
mp-wp_genesis 1752 <?php endif; if ( $inputs['show_summary'] ) : ?>
mp-wp_genesis 1753 <p>
mp-wp_genesis 1754 <label for="rss-show-summary-<?php echo $number; ?>">
mp-wp_genesis 1755 <input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>
mp-wp_genesis 1756 <?php _e('Display item content?'); ?>
mp-wp_genesis 1757 </label>
mp-wp_genesis 1758 </p>
mp-wp_genesis 1759 <?php endif; if ( $inputs['show_author'] ) : ?>
mp-wp_genesis 1760 <p>
mp-wp_genesis 1761 <label for="rss-show-author-<?php echo $number; ?>">
mp-wp_genesis 1762 <input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>
mp-wp_genesis 1763 <?php _e('Display item author if available?'); ?>
mp-wp_genesis 1764 </label>
mp-wp_genesis 1765 </p>
mp-wp_genesis 1766 <?php endif; if ( $inputs['show_date'] ) : ?>
mp-wp_genesis 1767 <p>
mp-wp_genesis 1768 <label for="rss-show-date-<?php echo $number; ?>">
mp-wp_genesis 1769 <input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>
mp-wp_genesis 1770 <?php _e('Display item date?'); ?>
mp-wp_genesis 1771 </label>
mp-wp_genesis 1772 </p>
mp-wp_genesis 1773 <input type="hidden" name="widget-rss[<?php echo $number; ?>][submit]" value="1" />
mp-wp_genesis 1774 <?php
mp-wp_genesis 1775 endif;
mp-wp_genesis 1776 foreach ( array_keys($default_inputs) as $input ) :
mp-wp_genesis 1777 if ( 'hidden' === $inputs[$input] ) :
mp-wp_genesis 1778 $id = str_replace( '_', '-', $input );
mp-wp_genesis 1779 ?>
mp-wp_genesis 1780 <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
mp-wp_genesis 1781 <?php
mp-wp_genesis 1782 endif;
mp-wp_genesis 1783 endforeach;
mp-wp_genesis 1784 }
mp-wp_genesis 1785
mp-wp_genesis 1786 /**
mp-wp_genesis 1787 * Process RSS feed widget data and optionally retrieve feed items.
mp-wp_genesis 1788 *
mp-wp_genesis 1789 * The feed widget can not have more than 20 items or it will reset back to the
mp-wp_genesis 1790 * default, which is 10.
mp-wp_genesis 1791 *
mp-wp_genesis 1792 * The resulting array has the feed title, feed url, feed link (from channel),
mp-wp_genesis 1793 * feed items, error (if any), and whether to show summary, author, and date.
mp-wp_genesis 1794 * All respectively in the order of the array elements.
mp-wp_genesis 1795 *
mp-wp_genesis 1796 * @since 2.5.0
mp-wp_genesis 1797 *
mp-wp_genesis 1798 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
mp-wp_genesis 1799 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
mp-wp_genesis 1800 * @return array
mp-wp_genesis 1801 */
mp-wp_genesis 1802 function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
mp-wp_genesis 1803 $items = (int) $widget_rss['items'];
mp-wp_genesis 1804 if ( $items < 1 || 20 < $items )
mp-wp_genesis 1805 $items = 10;
mp-wp_genesis 1806 $url = sanitize_url(strip_tags( $widget_rss['url'] ));
mp-wp_genesis 1807 $title = trim(strip_tags( $widget_rss['title'] ));
mp-wp_genesis 1808 $show_summary = (int) $widget_rss['show_summary'];
mp-wp_genesis 1809 $show_author = (int) $widget_rss['show_author'];
mp-wp_genesis 1810 $show_date = (int) $widget_rss['show_date'];
mp-wp_genesis 1811
mp-wp_genesis 1812 if ( $check_feed ) {
mp-wp_genesis 1813 require_once(ABSPATH . WPINC . '/rss.php');
mp-wp_genesis 1814 $rss = fetch_rss($url);
mp-wp_genesis 1815 $error = false;
mp-wp_genesis 1816 $link = '';
mp-wp_genesis 1817 if ( !is_object($rss) ) {
mp-wp_genesis 1818 $url = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1);
mp-wp_genesis 1819 $error = sprintf(__('Error in RSS %1$d'), $widget_number );
mp-wp_genesis 1820 } else {
mp-wp_genesis 1821 $link = clean_url(strip_tags($rss->channel['link']));
mp-wp_genesis 1822 while ( strstr($link, 'http') != $link )
mp-wp_genesis 1823 $link = substr($link, 1);
mp-wp_genesis 1824 }
mp-wp_genesis 1825 }
mp-wp_genesis 1826
mp-wp_genesis 1827 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
mp-wp_genesis 1828 }
mp-wp_genesis 1829
mp-wp_genesis 1830 /**
mp-wp_genesis 1831 * Register RSS widget to allow multiple RSS widgets on startup.
mp-wp_genesis 1832 *
mp-wp_genesis 1833 * @since 2.2.0
mp-wp_genesis 1834 */
mp-wp_genesis 1835 function wp_widget_rss_register() {
mp-wp_genesis 1836 if ( !$options = get_option('widget_rss') )
mp-wp_genesis 1837 $options = array();
mp-wp_genesis 1838 $widget_ops = array('classname' => 'widget_rss', 'description' => __( 'Entries from any RSS or Atom feed' ));
mp-wp_genesis 1839 $control_ops = array('width' => 400, 'height' => 200, 'id_base' => 'rss');
mp-wp_genesis 1840 $name = __('RSS');
mp-wp_genesis 1841
mp-wp_genesis 1842 $id = false;
mp-wp_genesis 1843 foreach ( (array) array_keys($options) as $o ) {
mp-wp_genesis 1844 // Old widgets can have null values for some reason
mp-wp_genesis 1845 if ( !isset($options[$o]['url']) || !isset($options[$o]['title']) || !isset($options[$o]['items']) )
mp-wp_genesis 1846 continue;
mp-wp_genesis 1847 $id = "rss-$o"; // Never never never translate an id
mp-wp_genesis 1848 wp_register_sidebar_widget($id, $name, 'wp_widget_rss', $widget_ops, array( 'number' => $o ));
mp-wp_genesis 1849 wp_register_widget_control($id, $name, 'wp_widget_rss_control', $control_ops, array( 'number' => $o ));
mp-wp_genesis 1850 }
mp-wp_genesis 1851
mp-wp_genesis 1852 // If there are none, we register the widget's existance with a generic template
mp-wp_genesis 1853 if ( !$id ) {
mp-wp_genesis 1854 wp_register_sidebar_widget( 'rss-1', $name, 'wp_widget_rss', $widget_ops, array( 'number' => -1 ) );
mp-wp_genesis 1855 wp_register_widget_control( 'rss-1', $name, 'wp_widget_rss_control', $control_ops, array( 'number' => -1 ) );
mp-wp_genesis 1856 }
mp-wp_genesis 1857 }
mp-wp_genesis 1858
mp-wp_genesis 1859 /**
mp-wp_genesis 1860 * Display tag cloud widget.
mp-wp_genesis 1861 *
mp-wp_genesis 1862 * @since 2.3.0
mp-wp_genesis 1863 *
mp-wp_genesis 1864 * @param array $args Widget arguments.
mp-wp_genesis 1865 */
mp-wp_genesis 1866 function wp_widget_tag_cloud($args) {
mp-wp_genesis 1867 extract($args);
mp-wp_genesis 1868 $options = get_option('widget_tag_cloud');
mp-wp_genesis 1869 $title = empty($options['title']) ? __('Tags') : apply_filters('widget_title', $options['title']);
mp-wp_genesis 1870
mp-wp_genesis 1871 echo $before_widget;
mp-wp_genesis 1872 echo $before_title . $title . $after_title;
mp-wp_genesis 1873 wp_tag_cloud();
mp-wp_genesis 1874 echo $after_widget;
mp-wp_genesis 1875 }
mp-wp_genesis 1876
mp-wp_genesis 1877 /**
mp-wp_genesis 1878 * Manage WordPress Tag Cloud widget options.
mp-wp_genesis 1879 *
mp-wp_genesis 1880 * Displays management form for changing the tag cloud widget title.
mp-wp_genesis 1881 *
mp-wp_genesis 1882 * @since 2.3.0
mp-wp_genesis 1883 */
mp-wp_genesis 1884 function wp_widget_tag_cloud_control() {
mp-wp_genesis 1885 $options = $newoptions = get_option('widget_tag_cloud');
mp-wp_genesis 1886
mp-wp_genesis 1887 if ( isset($_POST['tag-cloud-submit']) ) {
mp-wp_genesis 1888 $newoptions['title'] = strip_tags(stripslashes($_POST['tag-cloud-title']));
mp-wp_genesis 1889 }
mp-wp_genesis 1890
mp-wp_genesis 1891 if ( $options != $newoptions ) {
mp-wp_genesis 1892 $options = $newoptions;
mp-wp_genesis 1893 update_option('widget_tag_cloud', $options);
mp-wp_genesis 1894 }
mp-wp_genesis 1895
mp-wp_genesis 1896 $title = attribute_escape( $options['title'] );
mp-wp_genesis 1897 ?>
mp-wp_genesis 1898 <p><label for="tag-cloud-title">
mp-wp_genesis 1899 <?php _e('Title:') ?> <input type="text" class="widefat" id="tag-cloud-title" name="tag-cloud-title" value="<?php echo $title ?>" /></label>
mp-wp_genesis 1900 </p>
mp-wp_genesis 1901 <input type="hidden" name="tag-cloud-submit" id="tag-cloud-submit" value="1" />
mp-wp_genesis 1902 <?php
mp-wp_genesis 1903 }
mp-wp_genesis 1904
mp-wp_genesis 1905 /**
mp-wp_genesis 1906 * Register all of the default WordPress widgets on startup.
mp-wp_genesis 1907 *
mp-wp_genesis 1908 * Calls 'widgets_init' action after all of the WordPress widgets have been
mp-wp_genesis 1909 * registered.
mp-wp_genesis 1910 *
mp-wp_genesis 1911 * @since 2.2.0
mp-wp_genesis 1912 */
mp-wp_genesis 1913 function wp_widgets_init() {
mp-wp_genesis 1914 if ( !is_blog_installed() )
mp-wp_genesis 1915 return;
mp-wp_genesis 1916
mp-wp_genesis 1917 $widget_ops = array('classname' => 'widget_pages', 'description' => __( "Your blog's WordPress Pages") );
mp-wp_genesis 1918 wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $widget_ops);
mp-wp_genesis 1919 wp_register_widget_control('pages', __('Pages'), 'wp_widget_pages_control' );
mp-wp_genesis 1920
mp-wp_genesis 1921 $widget_ops = array('classname' => 'widget_calendar', 'description' => __( "A calendar of your blog's posts") );
mp-wp_genesis 1922 wp_register_sidebar_widget('calendar', __('Calendar'), 'wp_widget_calendar', $widget_ops);
mp-wp_genesis 1923 wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control' );
mp-wp_genesis 1924
mp-wp_genesis 1925 $widget_ops = array('classname' => 'widget_archive', 'description' => __( "A monthly archive of your blog's posts") );
mp-wp_genesis 1926 wp_register_sidebar_widget('archives', __('Archives'), 'wp_widget_archives', $widget_ops);
mp-wp_genesis 1927 wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control' );
mp-wp_genesis 1928
mp-wp_genesis 1929 $widget_ops = array('classname' => 'widget_links', 'description' => __( "Your blogroll") );
mp-wp_genesis 1930 wp_register_sidebar_widget('links', __('Links'), 'wp_widget_links', $widget_ops);
mp-wp_genesis 1931
mp-wp_genesis 1932 $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
mp-wp_genesis 1933 wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $widget_ops);
mp-wp_genesis 1934 wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control' );
mp-wp_genesis 1935
mp-wp_genesis 1936 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") );
mp-wp_genesis 1937 wp_register_sidebar_widget('search', __('Search'), 'wp_widget_search', $widget_ops);
mp-wp_genesis 1938
mp-wp_genesis 1939 $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your blog") );
mp-wp_genesis 1940 wp_register_sidebar_widget('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries', $widget_ops);
mp-wp_genesis 1941 wp_register_widget_control('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries_control' );
mp-wp_genesis 1942
mp-wp_genesis 1943 $widget_ops = array('classname' => 'widget_tag_cloud', 'description' => __( "Your most used tags in cloud format") );
mp-wp_genesis 1944 wp_register_sidebar_widget('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud', $widget_ops);
mp-wp_genesis 1945 wp_register_widget_control('tag_cloud', __('Tag Cloud'), 'wp_widget_tag_cloud_control' );
mp-wp_genesis 1946
mp-wp_genesis 1947 wp_widget_categories_register();
mp-wp_genesis 1948 wp_widget_text_register();
mp-wp_genesis 1949 wp_widget_rss_register();
mp-wp_genesis 1950 wp_widget_recent_comments_register();
mp-wp_genesis 1951
mp-wp_genesis 1952 do_action('widgets_init');
mp-wp_genesis 1953 }
mp-wp_genesis 1954
mp-wp_genesis 1955 add_action('init', 'wp_widgets_init', 1);
mp-wp_genesis 1956
mp-wp_genesis 1957 /*
mp-wp_genesis 1958 * Pattern for multi-widget (allows multiple instances such as the text widget).
mp-wp_genesis 1959 *
mp-wp_genesis 1960 * Make sure to close the comments after copying.
mp-wp_genesis 1961
mp-wp_genesis 1962 /**
mp-wp_genesis 1963 * Displays widget.
mp-wp_genesis 1964 *
mp-wp_genesis 1965 * Supports multiple widgets.
mp-wp_genesis 1966 *
mp-wp_genesis 1967 * @param array $args Widget arguments.
mp-wp_genesis 1968 * @param array|int $widget_args Widget number. Which of the several widgets of this type do we mean.
mp-wp_genesis 1969 * /
mp-wp_genesis 1970 function widget_many( $args, $widget_args = 1 ) {
mp-wp_genesis 1971 extract( $args, EXTR_SKIP );
mp-wp_genesis 1972 if ( is_numeric($widget_args) )
mp-wp_genesis 1973 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 1974 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 1975 extract( $widget_args, EXTR_SKIP );
mp-wp_genesis 1976
mp-wp_genesis 1977 // Data should be stored as array: array( number => data for that instance of the widget, ... )
mp-wp_genesis 1978 $options = get_option('widget_many');
mp-wp_genesis 1979 if ( !isset($options[$number]) )
mp-wp_genesis 1980 return;
mp-wp_genesis 1981
mp-wp_genesis 1982 echo $before_widget;
mp-wp_genesis 1983
mp-wp_genesis 1984 // Do stuff for this widget, drawing data from $options[$number]
mp-wp_genesis 1985
mp-wp_genesis 1986 echo $after_widget;
mp-wp_genesis 1987 }
mp-wp_genesis 1988
mp-wp_genesis 1989 /**
mp-wp_genesis 1990 * Displays form for a particular instance of the widget.
mp-wp_genesis 1991 *
mp-wp_genesis 1992 * Also updates the data after a POST submit.
mp-wp_genesis 1993 *
mp-wp_genesis 1994 * @param array|int $widget_args Widget number. Which of the several widgets of this type do we mean.
mp-wp_genesis 1995 * /
mp-wp_genesis 1996 function widget_many_control( $widget_args = 1 ) {
mp-wp_genesis 1997 global $wp_registered_widgets;
mp-wp_genesis 1998 static $updated = false; // Whether or not we have already updated the data after a POST submit
mp-wp_genesis 1999
mp-wp_genesis 2000 if ( is_numeric($widget_args) )
mp-wp_genesis 2001 $widget_args = array( 'number' => $widget_args );
mp-wp_genesis 2002 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
mp-wp_genesis 2003 extract( $widget_args, EXTR_SKIP );
mp-wp_genesis 2004
mp-wp_genesis 2005 // Data should be stored as array: array( number => data for that instance of the widget, ... )
mp-wp_genesis 2006 $options = get_option('widget_many');
mp-wp_genesis 2007 if ( !is_array($options) )
mp-wp_genesis 2008 $options = array();
mp-wp_genesis 2009
mp-wp_genesis 2010 // We need to update the data
mp-wp_genesis 2011 if ( !$updated && !empty($_POST['sidebar']) ) {
mp-wp_genesis 2012 // Tells us what sidebar to put the data in
mp-wp_genesis 2013 $sidebar = (string) $_POST['sidebar'];
mp-wp_genesis 2014
mp-wp_genesis 2015 $sidebars_widgets = wp_get_sidebars_widgets();
mp-wp_genesis 2016 if ( isset($sidebars_widgets[$sidebar]) )
mp-wp_genesis 2017 $this_sidebar =& $sidebars_widgets[$sidebar];
mp-wp_genesis 2018 else
mp-wp_genesis 2019 $this_sidebar = array();
mp-wp_genesis 2020
mp-wp_genesis 2021 foreach ( $this_sidebar as $_widget_id ) {
mp-wp_genesis 2022 // Remove all widgets of this type from the sidebar. We'll add the new data in a second. This makes sure we don't get any duplicate data
mp-wp_genesis 2023 // since widget ids aren't necessarily persistent across multiple updates
mp-wp_genesis 2024 if ( 'widget_many' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
mp-wp_genesis 2025 $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
mp-wp_genesis 2026 if ( !in_array( "many-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed. "many-$widget_number" is "{id_base}-{widget_number}
mp-wp_genesis 2027 unset($options[$widget_number]);
mp-wp_genesis 2028 }
mp-wp_genesis 2029 }
mp-wp_genesis 2030
mp-wp_genesis 2031 foreach ( (array) $_POST['widget-many'] as $widget_number => $widget_many_instance ) {
mp-wp_genesis 2032 // compile data from $widget_many_instance
mp-wp_genesis 2033 if ( !isset($widget_many_instance['something']) && isset($options[$widget_number]) ) // user clicked cancel
mp-wp_genesis 2034 continue;
mp-wp_genesis 2035 $something = wp_specialchars( $widget_many_instance['something'] );
mp-wp_genesis 2036 $options[$widget_number] = array( 'something' => $something ); // Even simple widgets should store stuff in array, rather than in scalar
mp-wp_genesis 2037 }
mp-wp_genesis 2038
mp-wp_genesis 2039 update_option('widget_many', $options);
mp-wp_genesis 2040
mp-wp_genesis 2041 $updated = true; // So that we don't go through this more than once
mp-wp_genesis 2042 }
mp-wp_genesis 2043
mp-wp_genesis 2044
mp-wp_genesis 2045 // Here we echo out the form
mp-wp_genesis 2046 if ( -1 == $number ) { // We echo out a template for a form which can be converted to a specific form later via JS
mp-wp_genesis 2047 $something = '';
mp-wp_genesis 2048 $number = '%i%';
mp-wp_genesis 2049 } else {
mp-wp_genesis 2050 $something = attribute_escape($options[$number]['something']);
mp-wp_genesis 2051 }
mp-wp_genesis 2052
mp-wp_genesis 2053 // The form has inputs with names like widget-many[$number][something] so that all data for that instance of
mp-wp_genesis 2054 // the widget are stored in one $_POST variable: $_POST['widget-many'][$number]
mp-wp_genesis 2055 ?>
mp-wp_genesis 2056 <p>
mp-wp_genesis 2057 <input class="widefat" id="widget-many-something-<?php echo $number; ?>" name="widget-many[<?php echo $number; ?>][something]" type="text" value="<?php echo $data; ?>" />
mp-wp_genesis 2058 <input type="hidden" id="widget-many-submit-<?php echo $number; ?>" name="widget-many[<?php echo $number; ?>][submit]" value="1" />
mp-wp_genesis 2059 </p>
mp-wp_genesis 2060 <?php
mp-wp_genesis 2061 }
mp-wp_genesis 2062
mp-wp_genesis 2063 /**
mp-wp_genesis 2064 * Registers each instance of our widget on startup.
mp-wp_genesis 2065 * /
mp-wp_genesis 2066 function widget_many_register() {
mp-wp_genesis 2067 if ( !$options = get_option('widget_many') )
mp-wp_genesis 2068 $options = array();
mp-wp_genesis 2069
mp-wp_genesis 2070 $widget_ops = array('classname' => 'widget_many', 'description' => __('Widget which allows multiple instances'));
mp-wp_genesis 2071 $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'many');
mp-wp_genesis 2072 $name = __('Many');
mp-wp_genesis 2073
mp-wp_genesis 2074 $registered = false;
mp-wp_genesis 2075 foreach ( array_keys($options) as $o ) {
mp-wp_genesis 2076 // Old widgets can have null values for some reason
mp-wp_genesis 2077 if ( !isset($options[$o]['something']) ) // we used 'something' above in our exampple. Replace with with whatever your real data are.
mp-wp_genesis 2078 continue;
mp-wp_genesis 2079
mp-wp_genesis 2080 // $id should look like {$id_base}-{$o}
mp-wp_genesis 2081 $id = "many-$o"; // Never never never translate an id
mp-wp_genesis 2082 $registered = true;
mp-wp_genesis 2083 wp_register_sidebar_widget( $id, $name, 'widget_many', $widget_ops, array( 'number' => $o ) );
mp-wp_genesis 2084 wp_register_widget_control( $id, $name, 'widget_many_control', $control_ops, array( 'number' => $o ) );
mp-wp_genesis 2085 }
mp-wp_genesis 2086
mp-wp_genesis 2087 // If there are none, we register the widget's existance with a generic template
mp-wp_genesis 2088 if ( !$registered ) {
mp-wp_genesis 2089 wp_register_sidebar_widget( 'many-1', $name, 'widget_many', $widget_ops, array( 'number' => -1 ) );
mp-wp_genesis 2090 wp_register_widget_control( 'many-1', $name, 'widget_many_control', $control_ops, array( 'number' => -1 ) );
mp-wp_genesis 2091 }
mp-wp_genesis 2092 }
mp-wp_genesis 2093
mp-wp_genesis 2094 // This is important
mp-wp_genesis 2095 add_action( 'widgets_init', 'widget_many_register' )
mp-wp_genesis 2096
mp-wp_genesis 2097 */
mp-wp_genesis 2098
mp-wp_genesis 2099 ?>