### Eclipse Workspace Patch 1.0
#P wordpress-trunk
|
|
|
844 | 844 | if ( is_int($index) ) { |
845 | 845 | $index = "sidebar-$index"; |
846 | 846 | } else { |
847 | | $index = sanitize_title($index); |
848 | | foreach ( (array) $wp_registered_sidebars as $key => $value ) { |
849 | | if ( sanitize_title($value['name']) == $index ) { |
850 | | $index = $key; |
851 | | break; |
852 | | } |
853 | | } |
| 847 | $names = array_map( create_function( '$b', 'return $b["name"];' ), $wp_registered_sidebars ); |
| 848 | $names = array_flip( $names ); |
| 849 | if ( isset( $names[$index] ) ) |
| 850 | $index = $names[$index]; |
| 851 | $index = sanitize_title( $index ); |
854 | 852 | } |
855 | 853 | |
856 | 854 | $sidebars_widgets = wp_get_sidebars_widgets(); |
857 | 855 | |
858 | | if ( empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) ) |
| 856 | if ( empty( $wp_registered_sidebars[$index] ) || !is_array($sidebars_widgets[$index]) || empty( $sidebars_widgets[$index] ) ) |
859 | 857 | return false; |
860 | 858 | |
861 | 859 | $sidebar = $wp_registered_sidebars[$index]; |
| 860 | |
| 861 | // only take those id that are in sidebar and exist in registered widgets |
| 862 | $sidebars_widgets_ids = array_intersect( $sidebars_widgets[$index], array_keys( $wp_registered_widgets ) ); |
862 | 863 | |
| 864 | // look for additional css classnames - first, last ... |
| 865 | $find = array(); |
| 866 | foreach ( $sidebars_widgets_ids as $id ) { |
| 867 | // normalize classname(s) into array if they are not yet |
| 868 | if ( ! is_array( $wp_registered_widgets[$id]['classname'] ) ) |
| 869 | $wp_registered_widgets[$id]['classname'] = (array) $wp_registered_widgets[$id]['classname']; |
| 870 | |
| 871 | $callback = $wp_registered_widgets[$id]['callback']; |
| 872 | if ( is_callable( $callback ) ) { |
| 873 | if ( empty( $find['first'] ) ) $find['first'] = $id; |
| 874 | $find['last'] = $id; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | // ... and add classnames as needed |
| 879 | foreach ( $find as $class => $id ) { |
| 880 | $wp_registered_widgets[$id]['classname'][] = $class; |
| 881 | } |
| 882 | |
863 | 883 | $did_one = false; |
864 | | foreach ( (array) $sidebars_widgets[$index] as $id ) { |
| 884 | foreach ( $sidebars_widgets_ids as $id ) { |
865 | 885 | |
866 | | if ( !isset($wp_registered_widgets[$id]) ) continue; |
867 | | |
868 | 886 | $params = array_merge( |
869 | 887 | array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), |
870 | 888 | (array) $wp_registered_widgets[$id]['params'] |
871 | 889 | ); |
872 | 890 | |
873 | | // Substitute HTML id and class attributes into before_widget |
874 | | $classname_ = ''; |
875 | | foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { |
876 | | if ( is_string($cn) ) |
877 | | $classname_ .= '_' . $cn; |
878 | | elseif ( is_object($cn) ) |
879 | | $classname_ .= '_' . get_class($cn); |
| 891 | // Substitute HTML id and class attributes into before_widget |
| 892 | $classes = array(); |
| 893 | foreach ( $wp_registered_widgets[$id]['classname'] as $cn ) { |
| 894 | if ( is_object($cn) ) $cn = get_class($cn); |
| 895 | if ( is_string($cn) ) $classes[] = $cn; |
880 | 896 | } |
881 | | $classname_ = ltrim($classname_, '_'); |
| 897 | $classname_ = implode(' ', $classes); |
882 | 898 | $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); |
883 | 899 | |
884 | 900 | $params = apply_filters( 'dynamic_sidebar_params', $params ); |