Ticket #11160: 11160.diff
| File 11160.diff, 4.7 KB (added by , 17 years ago) |
|---|
-
wp-includes/widgets.php
448 448 } 449 449 450 450 /** 451 * Return the ID of a sidebar given it's name or ID. 452 * 453 * Since register_sidebar() supports it, this function will look for sidebars 454 * named as integers or as a default id (like 2 or 'sidebar-13') first and check 455 * those as IDs if the name fails (and those IDs exist). 456 * ie: $id = get_sidebar_id(1); 457 * $id = get_sidebar_id('Sidebar Top'); 458 * 459 * get_sidebar_id() will also take an array of arguments. The array can contain a 460 * sidebar ID, a sidebar name or both. key/values pairs are ignored. 461 * $id = get_sidebar_id( array('id' => 'sidebar-1') ); 462 * 463 * @since 2.9.0 464 * 465 * @param int|string|array $args The name or id of the wigdet specified by 466 * register_sidebar(s) functions. As an array use the register_sidebar() syntax 467 * identifying sidebar by name or id or both. 468 * @return mixed returns false if id not found or returns sidebar id. 469 */ 470 function get_sidebar_id($args) { 471 global $wp_registered_sidebars; 472 473 if ( is_int($args) || is_string($args) ) { 474 475 // $args is a name or an id 476 $name_or_id = $args; 477 478 // for backward compatibility 479 if ( is_int($name_or_id) ) { 480 return "sidebar-{$name_or_id}"; 481 482 } else { 483 $name_or_id = sanitize_title($name_or_id); 484 foreach ( (array) $wp_registered_sidebars as $id => $value ) { 485 if ( sanitize_title($value['name']) == $name_or_id ) { 486 return $id; 487 } 488 } 489 } 490 491 return $name_or_id; 492 493 } elseif ( is_array($args) ) { 494 495 if ( !array_key_exists('id', $args) and !array_key_exists('name', $args) ) 496 return false; 497 498 // $args is an array holding a name, an id or both. 499 if ( array_key_exists('id', $args) && array_key_exists($args['id'], $wp_registered_sidebars) ) 500 return $args['id']; 501 502 if ( array_key_exists('name', $args) ) { 503 $name = sanitize_title($args['name']); 504 foreach ( (array) $wp_registered_sidebars as $id => $value ) { 505 if ( sanitize_title($value['name']) == $name ) { 506 return $id; 507 } 508 } 509 } 510 } 511 512 return false; 513 } 514 515 516 /** 451 517 * Creates multiple sidebars. 452 518 * 453 519 * If you wanted to quickly create multiple sidebars for a theme or internally. … … 564 630 * 565 631 * @uses $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID. 566 632 * 567 * @param string $name The ID of the sidebar when it was added. 633 * @param int|string|array $args The name or id of the wigdet specified by 634 * register_sidebar(s) functions. As an array use the register_sidebar() syntax 635 * identifying sidebar by name or id or both. 568 636 */ 569 function unregister_sidebar( $name) {637 function unregister_sidebar($name) { 570 638 global $wp_registered_sidebars; 571 639 640 $name = get_sidebar_id($name); 641 572 642 if ( isset( $wp_registered_sidebars[$name] ) ) 573 643 unset( $wp_registered_sidebars[$name] ); 574 644 } … … 802 872 * 803 873 * @since 2.2.0 804 874 * 805 * @param int|string $index Optional, default is 1. Name or ID of dynamic sidebar. 875 * @param int|string|array $args Optional, default is 1. The name or id of the wigdet 876 * specified by register_sidebar(s) functions. As an array use the register_sidebar() 877 * syntax identifying sidebar by name or id or both. 806 878 * @return bool True, if widget sidebar was found and called. False if not found or not called. 807 879 */ 808 880 function dynamic_sidebar($index = 1) { 809 881 global $wp_registered_sidebars, $wp_registered_widgets; 810 882 811 if ( is_int($index) ) { 812 $index = "sidebar-$index"; 813 } else { 814 $index = sanitize_title($index); 815 foreach ( (array) $wp_registered_sidebars as $key => $value ) { 816 if ( sanitize_title($value['name']) == $index ) { 817 $index = $key; 818 break; 819 } 820 } 821 } 883 $index = get_sidebar_id($index); 822 884 823 885 $sidebars_widgets = wp_get_sidebars_widgets(); 824 886 … … 930 992 * 931 993 * @since 2.8 932 994 * 933 * @param mixed $index, sidebar name, id or number to check. 995 * @param int|string|array $args The name or id of the wigdet specified by 996 * register_sidebar(s) functions. As an array use the register_sidebar() syntax 997 * identifying sidebar by name or id or both. 934 998 * @return bool true if the sidebar is in use, false otherwise. 935 999 */ 936 1000 function is_active_sidebar( $index ) { 937 $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index); 1001 1002 $index = get_sidebar_id($index); 1003 938 1004 $sidebars_widgets = wp_get_sidebars_widgets(); 939 1005 if ( isset($sidebars_widgets[$index]) && !empty($sidebars_widgets[$index]) ) 940 1006 return true;
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)