| 20 | | |
|---|
| 21 | | $name = ( !empty( $args['name'] ) ) ? $args['name'] : __( 'Sidebar' ); |
|---|
| 22 | | |
|---|
| 23 | | for ( $i = 1; $i <= $number; $i++ ) { |
|---|
| 24 | | if ( isset( $args['name'] ) && $number > 1 ) { |
|---|
| 25 | | if ( strpos( $name, '%d' ) === false ) { |
|---|
| 26 | | $name = $name . ' %d'; |
|---|
| | 29 | $_args['id'] = isset($args['id']) ? $args['id'] : "sidebar-$i"; |
|---|
| | 30 | register_sidebar($_args); |
|---|
| | 31 | ++$i; |
|---|
| | 32 | } |
|---|
| | 33 | } |
|---|
| | 34 | endif; |
|---|
| | 35 | |
|---|
| | 36 | if ( !function_exists( 'register_sidebar' ) ): |
|---|
| | 37 | function register_sidebar($args = array()) { |
|---|
| | 38 | global $wp_registered_sidebars; |
|---|
| | 39 | |
|---|
| | 40 | if ( is_string($args) ) |
|---|
| | 41 | parse_str($args, $args); |
|---|
| | 42 | |
|---|
| | 43 | $i = count($wp_registered_sidebars) + 1; |
|---|
| | 44 | |
|---|
| | 45 | $defaults = array( |
|---|
| | 46 | 'name' => sprintf(__('Sidebar %d'), count($wp_registered_sidebars) + 1 ), |
|---|
| | 47 | 'id' => "sidebar-$i", |
|---|
| | 48 | 'before_widget' => '<li id="%1$s" class="widget %2$s">', |
|---|
| | 49 | 'after_widget' => "</li>\n", |
|---|
| | 50 | 'before_title' => '<h2 class="widgettitle">', |
|---|
| | 51 | 'after_title' => "</h2>\n", |
|---|
| | 52 | ); |
|---|
| | 53 | |
|---|
| | 54 | $sidebar = array_merge($defaults, $args); |
|---|
| | 55 | |
|---|
| | 56 | $wp_registered_sidebars[$sidebar['id']] = $sidebar; |
|---|
| | 57 | |
|---|
| | 58 | return $sidebar['id']; |
|---|
| | 59 | } |
|---|
| | 60 | endif; |
|---|
| | 61 | |
|---|
| | 62 | if ( !function_exists( 'unregister_sidebar' ) ): |
|---|
| | 63 | function unregister_sidebar( $name ) { |
|---|
| | 64 | global $wp_registered_sidebars; |
|---|
| | 65 | |
|---|
| | 66 | if ( isset( $wp_registered_sidebars[$name] ) ) |
|---|
| | 67 | unset( $wp_registered_sidebars[$name] ); |
|---|
| | 68 | } |
|---|
| | 69 | endif; |
|---|
| | 70 | |
|---|
| | 71 | if ( !function_exists( 'register_sidebar_widget' ) ): |
|---|
| | 72 | function register_sidebar_widget($name, $output_callback, $classname = '', $id = '') { |
|---|
| | 73 | global $wp_registered_widgets, $wp_register_widget_defaults; |
|---|
| | 74 | |
|---|
| | 75 | // Compat |
|---|
| | 76 | if ( is_array($name) ) { |
|---|
| | 77 | if ( count($name) == 3 ) |
|---|
| | 78 | $name = sprintf($name[0], $name[2]); |
|---|
| | 79 | else |
|---|
| | 80 | $name = $name[0]; |
|---|
| | 81 | } |
|---|
| | 82 | |
|---|
| | 83 | // Last resort -- this can be broken when names get translated so please provide a unique id. |
|---|
| | 84 | if ( !isset($id) ) |
|---|
| | 85 | $id = sanitize_title($name); |
|---|
| | 86 | |
|---|
| | 87 | if ( (!isset($classname) || empty($classname) || !is_string($classname)) && is_string($output_callback) ) |
|---|
| | 88 | $classname = $output_callback; |
|---|
| | 89 | |
|---|
| | 90 | $widget = array( |
|---|
| | 91 | 'name' => $name, |
|---|
| | 92 | 'id' => $id, |
|---|
| | 93 | 'callback' => $output_callback, |
|---|
| | 94 | 'classname' => $classname, |
|---|
| | 95 | 'params' => array_slice(func_get_args(), 4) |
|---|
| | 96 | ); |
|---|
| | 97 | |
|---|
| | 98 | if ( empty($output_callback) ) |
|---|
| | 99 | unset($wp_registered_widgets[$id]); |
|---|
| | 100 | elseif ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || !$wp_register_widget_defaults) ) |
|---|
| | 101 | $wp_registered_widgets[$id] = $widget; |
|---|
| | 102 | } |
|---|
| | 103 | endif; |
|---|
| | 104 | |
|---|
| | 105 | if ( !function_exists( 'unregister_sidebar_widget' ) ): |
|---|
| | 106 | function unregister_sidebar_widget($id) { |
|---|
| | 107 | $id = sanitize_title($id); |
|---|
| | 108 | register_sidebar_widget('', '', '', $id); |
|---|
| | 109 | unregister_widget_control($id); |
|---|
| | 110 | } |
|---|
| | 111 | endif; |
|---|
| | 112 | |
|---|
| | 113 | if ( !function_exists( 'register_widget_control' ) ): |
|---|
| | 114 | function register_widget_control($name, $control_callback, $width = 300, $height = 200, $id = '') { |
|---|
| | 115 | global $wp_registered_widget_controls, $wp_register_widget_defaults; |
|---|
| | 116 | |
|---|
| | 117 | // Compat |
|---|
| | 118 | if ( is_array($name) ) { |
|---|
| | 119 | if ( count($name) == 3 ) |
|---|
| | 120 | $name = sprintf($name[0], $name[2]); |
|---|
| | 121 | else |
|---|
| | 122 | $name = $name[0]; |
|---|
| | 123 | } |
|---|
| | 124 | |
|---|
| | 125 | if ( !isset($id) || empty($id) ) |
|---|
| | 126 | $id = $name; |
|---|
| | 127 | |
|---|
| | 128 | $id = sanitize_title($id); |
|---|
| | 129 | |
|---|
| | 130 | $width = (int) $width > 90 ? (int) $width + 60 : 360; |
|---|
| | 131 | $height = (int) $height > 60 ? (int) $height + 40 : 240; |
|---|
| | 132 | |
|---|
| | 133 | if ( empty($control_callback) ) |
|---|
| | 134 | unset($wp_registered_widget_controls[$name]); |
|---|
| | 135 | elseif ( !isset($wp_registered_widget_controls[$name]) || !$wp_register_widget_defaults ) |
|---|
| | 136 | $wp_registered_widget_controls[$id] = array( |
|---|
| | 137 | 'name' => $name, |
|---|
| | 138 | 'id' => $id, |
|---|
| | 139 | 'callback' => $control_callback, |
|---|
| | 140 | 'width' => $width, |
|---|
| | 141 | 'height' => $height, |
|---|
| | 142 | 'params' => array_slice(func_get_args(), 5) |
|---|
| | 143 | ); |
|---|
| | 144 | } |
|---|
| | 145 | endif; |
|---|
| | 146 | |
|---|
| | 147 | if ( !function_exists( 'unregister_widget_control' ) ): |
|---|
| | 148 | function unregister_widget_control($id) { |
|---|
| | 149 | $id = sanitize_title($id); |
|---|
| | 150 | return register_widget_control($id, ''); |
|---|
| | 151 | } |
|---|
| | 152 | endif; |
|---|
| | 153 | |
|---|
| | 154 | if ( !function_exists( 'dynamic_sidebar' ) ): |
|---|
| | 155 | function dynamic_sidebar($index = 1) { |
|---|
| | 156 | global $wp_registered_sidebars, $wp_registered_widgets; |
|---|
| | 157 | |
|---|
| | 158 | if ( is_int($index) ) { |
|---|
| | 159 | $index = "sidebar-$index"; |
|---|
| | 160 | } else { |
|---|
| | 161 | $index = sanitize_title($index); |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | $sidebars_widgets = wp_get_sidebars_widgets(); |
|---|
| | 165 | |
|---|
| | 166 | if ( empty($wp_registered_sidebars[$index]) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) ) |
|---|
| | 167 | return false; |
|---|
| | 168 | |
|---|
| | 169 | $sidebar = $wp_registered_sidebars[$index]; |
|---|
| | 170 | |
|---|
| | 171 | $did_one = false; |
|---|
| | 172 | foreach ( $sidebars_widgets[$index] as $id ) { |
|---|
| | 173 | $callback = $wp_registered_widgets[$id]['callback']; |
|---|
| | 174 | |
|---|
| | 175 | $params = array_merge(array($sidebar), (array) $wp_registered_widgets[$id]['params']); |
|---|
| | 176 | |
|---|
| | 177 | // Substitute HTML id and class attributes into before_widget |
|---|
| | 178 | $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $wp_registered_widgets[$id]['classname']); |
|---|
| | 179 | |
|---|
| | 180 | if ( is_callable($callback) ) { |
|---|
| | 181 | call_user_func_array($callback, $params); |
|---|
| | 182 | $did_one = true; |
|---|
| | 183 | } |
|---|
| | 184 | } |
|---|
| | 185 | |
|---|
| | 186 | return $did_one; |
|---|
| | 187 | } |
|---|
| | 188 | endif; |
|---|
| | 189 | |
|---|
| | 190 | if ( !function_exists( 'is_active_widget' ) ): |
|---|
| | 191 | function is_active_widget($callback) { |
|---|
| | 192 | global $wp_registered_widgets; |
|---|
| | 193 | |
|---|
| | 194 | $sidebars_widgets = wp_get_sidebars_widgets(false); |
|---|
| | 195 | |
|---|
| | 196 | if ( is_array($sidebars_widgets) ) foreach ( $sidebars_widgets as $sidebar => $widgets ) |
|---|
| | 197 | if ( is_array($widgets) ) foreach ( $widgets as $widget ) |
|---|
| | 198 | if ( $wp_registered_widgets[$widget]['callback'] == $callback ) |
|---|
| | 199 | return true; |
|---|
| | 200 | |
|---|
| | 201 | return false; |
|---|
| | 202 | } |
|---|
| | 203 | endif; |
|---|
| | 204 | |
|---|
| | 205 | if ( !function_exists( 'is_dynamic_sidebar' ) ): |
|---|
| | 206 | function is_dynamic_sidebar() { |
|---|
| | 207 | global $wp_registered_widgets, $wp_registered_sidebars; |
|---|
| | 208 | $sidebars_widgets = get_option('sidebars_widgets'); |
|---|
| | 209 | foreach ( $wp_registered_sidebars as $index => $sidebar ) { |
|---|
| | 210 | if ( count($sidebars_widgets[$index]) ) { |
|---|
| | 211 | foreach ( $sidebars_widgets[$index] as $widget ) |
|---|
| | 212 | if ( array_key_exists($widget, $wp_registered_widgets) ) |
|---|
| | 213 | return true; |
|---|
| | 214 | } |
|---|
| | 215 | } |
|---|
| | 216 | return false; |
|---|
| | 217 | } |
|---|
| | 218 | endif; |
|---|
| | 219 | |
|---|
| | 220 | /* Internal Functions */ |
|---|
| | 221 | |
|---|
| | 222 | function wp_get_sidebars_widgets($update = true) { |
|---|
| | 223 | global $wp_registered_widgets; |
|---|
| | 224 | |
|---|
| | 225 | $sidebars_widgets = get_option('sidebars_widgets'); |
|---|
| | 226 | $_sidebars_widgets = array(); |
|---|
| | 227 | |
|---|
| | 228 | if ( !isset($sidebars_widgets['array_version']) ) |
|---|
| | 229 | $sidebars_widgets['array_version'] = 1; |
|---|
| | 230 | |
|---|
| | 231 | switch ( $sidebars_widgets['array_version'] ) { |
|---|
| | 232 | case 1 : |
|---|
| | 233 | foreach ( $sidebars_widgets as $index => $sidebar ) |
|---|
| | 234 | if ( is_array($sidebar) ) |
|---|
| | 235 | foreach ( $sidebar as $i => $name ) { |
|---|
| | 236 | $id = strtolower($name); |
|---|
| | 237 | if ( isset($wp_registered_widgets[$id]) ) { |
|---|
| | 238 | $_sidebars_widgets[$index][$i] = $id; |
|---|
| | 239 | continue; |
|---|
| 31 | | |
|---|
| 32 | | register_sidebar( $args ); |
|---|
| 33 | | } |
|---|
| 34 | | } |
|---|
| 35 | | } |
|---|
| 36 | | |
|---|
| 37 | | if ( !function_exists( 'register_sidebar' ) ) { |
|---|
| 38 | | function register_sidebar( $args = array() ) { |
|---|
| 39 | | global $wp_registered_sidebars; |
|---|
| 40 | | |
|---|
| 41 | | if ( is_string( $args ) ) { |
|---|
| 42 | | parse_str( $args, $args ); |
|---|
| 43 | | } |
|---|
| 44 | | |
|---|
| 45 | | $defaults = array( |
|---|
| 46 | | 'name' => sprintf( __( 'Sidebar %d' ), count( $wp_registered_sidebars ) + 1 ), |
|---|
| 47 | | 'before_widget' => '<li id="%1$s" class="widget %2$s">', |
|---|
| 48 | | 'after_widget' => "</li>\n", |
|---|
| 49 | | 'before_title' => '<h2 class="widgettitle">', |
|---|
| 50 | | 'after_title' => "</h2>\n" |
|---|
| 51 | | ); |
|---|
| 52 | | |
|---|
| 53 | | $defaults = apply_filters( 'register_sidebar_defaults', $defaults, $args ); |
|---|
| 54 | | |
|---|
| 55 | | $sidebar = array_merge( $defaults, $args ); |
|---|
| 56 | | |
|---|
| 57 | | $sidebar['id'] = sanitize_title( $sidebar['name'] ); |
|---|
| 58 | | |
|---|
| 59 | | $wp_registered_sidebars[$sidebar['id']] = $sidebar; |
|---|
| 60 | | |
|---|
| 61 | | return $sidebar['id']; |
|---|
| 62 | | } |
|---|
| 63 | | } |
|---|
| 64 | | |
|---|
| 65 | | if ( !function_exists( 'unregister_sidebar' ) ) { |
|---|
| 66 | | function unregister_sidebar( $name ) { |
|---|
| 67 | | global $wp_registered_sidebars; |
|---|
| 68 | | |
|---|
| 69 | | if ( isset( $wp_registered_sidebars[$name] ) ) { |
|---|
| 70 | | unset( $wp_registered_sidebars[$name] ); |
|---|
| 71 | | } |
|---|
| 72 | | } |
|---|
| 73 | | } |
|---|
| 74 | | |
|---|
| 75 | | if ( !function_exists( 'register_sidebar_widget' ) ) { |
|---|
| 76 | | function register_sidebar_widget( $name, $output_callback, $classname = '' ) { |
|---|
| 77 | | global $wp_registered_widgets, $wp_register_widget_defaults; |
|---|
| 78 | | |
|---|
| 79 | | if ( is_array( $name ) ) { |
|---|
| 80 | | $id = sanitize_title( sprintf( $name[0], $name[2] ) ); |
|---|
| 81 | | $name = sprintf( __( $name[0], $name[1] ), $name[2] ); |
|---|
| 82 | | } else { |
|---|
| 83 | | $id = sanitize_title( $name ); |
|---|
| 84 | | $name = __( $name ); |
|---|
| 85 | | } |
|---|
| 86 | | |
|---|
| 87 | | if ( ( empty( $classname ) || !is_string( $classname ) ) && is_string( $output_callback ) ) { |
|---|
| 88 | | $classname = $output_callback; |
|---|
| 89 | | } |
|---|
| 90 | | |
|---|
| 91 | | $widget = array( |
|---|
| 92 | | 'id' => $id, |
|---|
| 93 | | 'callback' => $output_callback, |
|---|
| 94 | | 'classname' => $classname, |
|---|
| 95 | | 'params' => array_slice( func_get_args(), 2 ) |
|---|
| 96 | | ); |
|---|
| 97 | | |
|---|
| 98 | | if ( empty( $output_callback ) ) { |
|---|
| 99 | | unset( $wp_registered_widgets[$name] ); |
|---|
| 100 | | } elseif ( is_callable( $output_callback ) && ( !isset( $wp_registered_widgets[$name] ) || !$wp_register_widget_defaults ) ) { |
|---|
| 101 | | $wp_registered_widgets[$name] = $widget; |
|---|
| 102 | | } |
|---|
| 103 | | } |
|---|
| 104 | | } |
|---|
| 105 | | |
|---|
| 106 | | if ( !function_exists( 'unregister_sidebar_widget' ) ) { |
|---|
| 107 | | function unregister_sidebar_widget( $name ) { |
|---|
| 108 | | register_sidebar_widget( $name, '' ); |
|---|
| 109 | | unregister_widget_control( $name ); |
|---|
| 110 | | } |
|---|
| 111 | | } |
|---|
| 112 | | |
|---|
| 113 | | if ( !function_exists( 'register_widget_control' ) ) { |
|---|
| 114 | | function register_widget_control( $name, $control_callback, $width = 300, $height = 200 ) { |
|---|
| 115 | | global $wp_registered_widget_controls, $wp_registered_sidebar_defaults; |
|---|
| 116 | | |
|---|
| 117 | | $width = (int) $width; |
|---|
| 118 | | $height = (int) $height; |
|---|
| 119 | | |
|---|
| 120 | | if ( is_array( $name ) ) { |
|---|
| 121 | | $id = sanitize_title( sprintf( $name[0], $name[2] ) ); |
|---|
| 122 | | $name = sprintf( __( $name[0], $name[1] ), $name[2] ); |
|---|
| 123 | | } else { |
|---|
| 124 | | $id = sanitize_title( $name ); |
|---|
| 125 | | $name = __( $name ); |
|---|
| 126 | | } |
|---|
| 127 | | |
|---|
| 128 | | $width = ( $width > 90 ) ? $width + 60 : 360; |
|---|
| 129 | | $height = ( $height > 60 ) ? $height + 40 : 240; |
|---|
| 130 | | |
|---|
| 131 | | if ( empty( $control_callback ) ) { |
|---|
| 132 | | unset( $wp_registered_widget_controls[$name] ); |
|---|
| 133 | | } elseif ( !isset( $wp_registered_widget_controls[$name] ) || !$wp_registered_sidebar_defaults ) { |
|---|
| 134 | | $wp_registered_widget_controls[$name] = array( |
|---|
| 135 | | 'id' => $id, |
|---|
| 136 | | 'callback' => $control_callback, |
|---|
| 137 | | 'width' => $width, |
|---|
| 138 | | 'height' => $height, |
|---|
| 139 | | 'params' => array_slice( func_get_args(), 4 ) |
|---|
| 140 | | ); |
|---|
| 141 | | } |
|---|
| 142 | | } |
|---|
| 143 | | } |
|---|
| 144 | | |
|---|
| 145 | | if ( !function_exists( 'unregister_widget_control' ) ) { |
|---|
| 146 | | function unregister_widget_control( $name ) { |
|---|
| 147 | | register_sidebar_control( $name, '' ); |
|---|
| 148 | | } |
|---|
| 149 | | } |
|---|
| 150 | | |
|---|
| 151 | | if ( !function_exists( 'dynamic_sidebar' ) ) { |
|---|
| 152 | | function dynamic_sidebar( $name = 1 ) { |
|---|
| 153 | | global $wp_registered_sidebars, $wp_registered_widgets; |
|---|
| 154 | | |
|---|
| 155 | | if ( is_int( $name ) ) { |
|---|
| 156 | | $index = sanitize_title( __( 'Sidebar' ) . ' ' . $name ); |
|---|
| 157 | | $name = sprintf( __( 'Sidebar %d' ), $name ); |
|---|
| 158 | | } else { |
|---|
| 159 | | $index = sanitize_title( $name ); |
|---|
| 160 | | } |
|---|
| 161 | | |
|---|
| 162 | | $sidebars_widgets = wp_get_sidebars_widgets(); |
|---|
| 163 | | |
|---|
| 164 | | $sidebar = $wp_registered_sidebars[$index]; |
|---|
| 165 | | |
|---|
| 166 | | if ( empty( $sidebar ) || !is_array( $sidebars_widgets[$index] ) || empty( $sidebars_widgets[$index] ) ) { |
|---|
| 167 | | return false; |
|---|
| 168 | | } |
|---|
| 169 | | |
|---|
| 170 | | $did_one = false; |
|---|
| 171 | | |
|---|
| 172 | | foreach ( $sidebars_widgets[$index] as $name ) { |
|---|
| 173 | | $callback = $wp_registered_widgets[$name]['callback']; |
|---|
| 174 | | |
|---|
| 175 | | $params = array_merge( array( $sidebar ), (array) $wp_registered_widgets[$name]['params'] ); |
|---|
| 176 | | $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $wp_registered_widgets[$name]['id'], $wp_registered_widgets[$name]['classname'] ); |
|---|
| 177 | | |
|---|
| 178 | | if ( is_callable( $callback ) ) { |
|---|
| 179 | | call_user_func_array( $callback, $params ); |
|---|
| 180 | | $did_one = true; |
|---|
| 181 | | } |
|---|
| 182 | | } |
|---|
| 183 | | |
|---|
| 184 | | return $did_one; |
|---|
| 185 | | } |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | if ( !function_exists( 'is_active_widget' ) ) { |
|---|
| 189 | | function is_active_widget( $callback ) { |
|---|
| 190 | | global $wp_registered_widgets; |
|---|
| 191 | | |
|---|
| 192 | | $sidebars_widgets = wp_get_sidebars_widgets(); |
|---|
| 193 | | |
|---|
| 194 | | if ( is_array( $sidebars_widgets ) ) { |
|---|
| 195 | | foreach ( $sidebars_widgets as $sidebar => $widgets ) { |
|---|
| 196 | | if ( is_array( $widgets) ) { |
|---|
| 197 | | foreach ( $widgets as $widget ) { |
|---|
| 198 | | if ( $wp_registered_widgets[$widget]['callback'] == $callback ) { |
|---|
| 199 | | return true; |
|---|
| 200 | | } |
|---|
| 201 | | } |
|---|
| 202 | | } |
|---|
| 203 | | } |
|---|
| 204 | | } |
|---|
| 205 | | |
|---|
| 206 | | return false; |
|---|
| 207 | | } |
|---|
| 208 | | } |
|---|
| 209 | | |
|---|
| 210 | | if ( !function_exists( 'is_dynamic_sidebar' ) ) { |
|---|
| 211 | | function is_dynamic_sidebar() { |
|---|
| 212 | | global $wp_registered_sidebars, $wp_registered_widgets; |
|---|
| 213 | | |
|---|
| 214 | | $sidebars_widgets = wp_get_sidebars_widgets(); |
|---|
| 215 | | |
|---|
| 216 | | foreach ( $wp_registered_sidebars as $index => $sidebar ) { |
|---|
| 217 | | if ( count( $sidebars_widgets[$index] ) > 0 ) { |
|---|
| 218 | | foreach ( $sidebars_widgets[$index] as $widget ) { |
|---|
| 219 | | if ( array_key_exists( $widget, $wp_registered_sidebars ) ) { |
|---|
| 220 | | return true; |
|---|
| 221 | | } |
|---|
| 222 | | } |
|---|
| 223 | | } |
|---|
| 224 | | } |
|---|
| 225 | | |
|---|
| 226 | | return false; |
|---|
| 227 | | } |
|---|
| 228 | | } |
|---|
| 229 | | |
|---|
| 230 | | /* Internal Functions */ |
|---|
| 231 | | |
|---|
| 232 | | function wp_get_sidebars_widgets() { |
|---|
| 233 | | return get_option( 'wp_sidebars_widgets' ); |
|---|
| | 248 | $_sidebars_widgets['array_version'] = 2; |
|---|
| | 249 | if ( $update ) |
|---|
| | 250 | update_option('sidebars_widgets', $_sidebars_widgets); |
|---|
| | 251 | break; |
|---|
| | 252 | case 2 : |
|---|
| | 253 | $_sidebars_widgets = $sidebars_widgets; |
|---|
| | 254 | break; |
|---|
| | 255 | } |
|---|
| | 256 | |
|---|
| | 257 | unset($_sidebars_widgets['array_version']); |
|---|
| | 258 | |
|---|
| | 259 | return $_sidebars_widgets; |
|---|
| 328 | | $options = $newoptions = get_option( 'wp_widget_archives' ); |
|---|
| 329 | | |
|---|
| 330 | | if ( isset( $_POST['archives-submit'] ) ) { |
|---|
| 331 | | $newoptions['count'] = isset( $_POST['archives-count'] ); |
|---|
| 332 | | $newoptions['title'] = strip_tags( stripslashes( $_POST['archives-title'] ) ); |
|---|
| 333 | | |
|---|
| 334 | | if ( $newoptions != $options ) { |
|---|
| 335 | | $options = $newoptions; |
|---|
| 336 | | update_option( 'wp_widget_archives', $options ); |
|---|
| 337 | | } |
|---|
| 338 | | } |
|---|
| 339 | | |
|---|
| 340 | | $count = ( isset( $options['count'] ) ) ? ' checked="checked"' : ''; |
|---|
| 341 | | $title = htmlspecialchars( $options['title'], ENT_QUOTES ); |
|---|
| 342 | | ?> |
|---|
| 343 | | <p><label for="archives-title"><?php _e( 'Title:' ); ?> <input style="width:250px" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p> |
|---|
| 344 | | <p style="text-align:right;margin-right:40px"><label for="archives-count"><?php _e( 'Show post counts?' ); ?> <input type="checkbox" class="checkbox" name="archives-count" id="archives-count" <?php echo $count; ?>/></p> |
|---|
| 345 | | <input type="hidden" name="archives-submit" id="archives-submit" value="1" /> |
|---|
| 346 | | <?php |
|---|
| 347 | | } |
|---|
| 348 | | |
|---|
| 349 | | function wp_widget_meta( $args ) { |
|---|
| 350 | | extract( $args ); |
|---|
| 351 | | |
|---|
| 352 | | $options = get_option( 'wp_widget_meta' ); |
|---|
| 353 | | $title = ( empty( $options['title'] ) ) ? __( 'Meta' ) : $options['title']; |
|---|
| | 345 | $options = $newoptions = get_option('widget_archives'); |
|---|
| | 346 | if ( $_POST["archives-submit"] ) { |
|---|
| | 347 | $newoptions['count'] = isset($_POST['archives-count']); |
|---|
| | 348 | $newoptions['title'] = strip_tags(stripslashes($_POST["archives-title"])); |
|---|
| | 349 | } |
|---|
| | 350 | if ( $options != $newoptions ) { |
|---|
| | 351 | $options = $newoptions; |
|---|
| | 352 | update_option('widget_archives', $options); |
|---|
| | 353 | } |
|---|
| | 354 | $count = $options['count'] ? 'checked="checked"' : ''; |
|---|
| | 355 | $title = htmlspecialchars($options['title'], ENT_QUOTES); |
|---|
| | 356 | ?> |
|---|
| | 357 | <p><label for="archives-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="archives-title" name="archives-title" type="text" value="<?php echo $title; ?>" /></label></p> |
|---|
| | 358 | <p style="text-align:right;margin-right:40px;"><label for="archives-count">Show post counts <input class="checkbox" type="checkbox" <?php echo $count; ?> id="archives-count" name="archives-count" /></label></p> |
|---|
| | 359 | <input type="hidden" id="archives-submit" name="archives-submit" value="1" /> |
|---|
| | 360 | <?php |
|---|
| | 361 | } |
|---|
| | 362 | |
|---|
| | 363 | function wp_widget_meta($args) { |
|---|
| | 364 | extract($args); |
|---|
| | 365 | $options = get_option('widget_meta'); |
|---|
| | 366 | $title = empty($options['title']) ? __('Meta') : $options['title']; |
|---|
| 370 | | $options = $newoptions = get_option( 'wp_widget_meta' ); |
|---|
| 371 | | |
|---|
| 372 | | if ( isset( $_POST['meta-submit'] ) ) { |
|---|
| 373 | | $newoptions['title'] = strip_tags( stripslashes( $_POST['meta-title'] ) ); |
|---|
| 374 | | |
|---|
| 375 | | if ( $newoptions != $options ) { |
|---|
| 376 | | $options = $newoptions; |
|---|
| 377 | | update_option( 'wp_widget_meta', $options ); |
|---|
| 378 | | } |
|---|
| 379 | | } |
|---|
| 380 | | |
|---|
| 381 | | $title = htmlspecialchars( $options['title'], ENT_QUOTES ); |
|---|
| 382 | | ?> |
|---|
| 383 | | <p><label for="meta-title"><?php _e( 'Title:' ); ?> <input type="text" name="meta-title" id="meta-title" style="width:250px" value="<?php echo $title; ?>" /></label></p> |
|---|
| 384 | | <input type="hidden" name="meta-submit" id="meta-submit" value="1" /> |
|---|
| 385 | | <?php |
|---|
| 386 | | } |
|---|
| 387 | | |
|---|
| 388 | | function wp_widget_calendar( $args ) { |
|---|
| 389 | | extract( $args ); |
|---|
| 390 | | |
|---|
| 391 | | $title = ( empty( $options['title'] ) ) ? ' ' : $options['title']; |
|---|
| | 382 | $options = $newoptions = get_option('widget_meta'); |
|---|
| | 383 | if ( $_POST["meta-submit"] ) { |
|---|
| | 384 | $newoptions['title'] = strip_tags(stripslashes($_POST["meta-title"])); |
|---|
| | 385 | } |
|---|
| | 386 | if ( $options != $newoptions ) { |
|---|
| | 387 | $options = $newoptions; |
|---|
| | 388 | update_option('widget_meta', $options); |
|---|
| | 389 | } |
|---|
| | 390 | $title = htmlspecialchars($options['title'], ENT_QUOTES); |
|---|
| | 391 | ?> |
|---|
| | 392 | <p><label for="meta-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="meta-title" name="meta-title" type="text" value="<?php echo $title; ?>" /></label></p> |
|---|
| | 393 | <input type="hidden" id="meta-submit" name="meta-submit" value="1" /> |
|---|
| | 394 | <?php |
|---|
| | 395 | } |
|---|
| | 396 | |
|---|
| | 397 | function wp_widget_calendar($args) { |
|---|
| | 398 | extract($args); |
|---|
| | 399 | $options = get_option('widget_calendar'); |
|---|
| | 400 | $title = $options['title']; |
|---|
| | 401 | if ( empty($title) ) |
|---|
| | 402 | $title = ' '; |
|---|
| | 403 | echo $before_widget . $before_title . $title . $after_title; |
|---|
| | 404 | echo '<div id="calendar_wrap">'; |
|---|
| | 405 | get_calendar(); |
|---|
| | 406 | echo '</div>'; |
|---|
| | 407 | echo $after_widget; |
|---|
| | 408 | } |
|---|
| | 409 | function wp_widget_calendar_control() { |
|---|
| | 410 | $options = $newoptions = get_option('widget_calendar'); |
|---|
| | 411 | if ( $_POST["calendar-submit"] ) { |
|---|
| | 412 | $newoptions['title'] = strip_tags(stripslashes($_POST["calendar-title"])); |
|---|
| | 413 | } |
|---|
| | 414 | if ( $options != $newoptions ) { |
|---|
| | 415 | $options = $newoptions; |
|---|
| | 416 | update_option('widget_calendar', $options); |
|---|
| | 417 | } |
|---|
| | 418 | $title = htmlspecialchars($options['title'], ENT_QUOTES); |
|---|
| | 419 | ?> |
|---|
| | 420 | <p><label for="calendar-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="calendar-title" name="calendar-title" type="text" value="<?php echo $title; ?>" /></label></p> |
|---|
| | 421 | <input type="hidden" id="calendar-submit" name="calendar-submit" value="1" /> |
|---|
| | 422 | <?php |
|---|
| | 423 | } |
|---|
| | 424 | |
|---|
| | 425 | function wp_widget_text($args, $number = 1) { |
|---|
| | 426 | extract($args); |
|---|
| | 427 | $options = get_option('widget_text'); |
|---|
| | 428 | $title = $options[$number]['title']; |
|---|
| | 429 | if ( empty($title) ) |
|---|
| | 430 | $title = ' '; |
|---|
| | 431 | $text = $options[$number]['text']; |
|---|
| 435 | | function wp_widget_text_control( $i ) { |
|---|
| 436 | | $options = $newoptions = get_option( 'wp_widget_text' ); |
|---|
| 437 | | |
|---|
| 438 | | if ( isset( $_POST['text-submit-' . $i] ) ) { |
|---|
| 439 | | $newoptions[$i]['title'] = strip_tags( stripslashes( $_POST['text-title-' . $i] ) ); |
|---|
| 440 | | $newoptions[$i]['text'] = stripslashes( $_POST['text-text-' . $i] ); |
|---|
| 441 | | |
|---|
| 442 | | if ( !current_user_can( 'unfiltered_html' ) ) { |
|---|
| 443 | | $newoptions[$i]['text'] = stripslashes( wp_filter_post_kses( $newoptions[$i]['text'] ) ); |
|---|
| 444 | | } |
|---|
| 445 | | |
|---|
| 446 | | if ( $newoptions != $options ) { |
|---|
| 447 | | $options = $newoptions; |
|---|
| 448 | | update_options( 'wp_widget_text', $options ); |
|---|
| 449 | | } |
|---|
| 450 | | } |
|---|
| 451 | | |
|---|
| 452 | | $title = htmlspecialchars( $options[$i]['title'], ENT_QUOTES ); |
|---|
| 453 | | $text = htmlspecialchars( $options[$i]['text'], ENT_QUOTES ); |
|---|
| 454 | | ?> |
|---|
| 455 | | <input style="width:450px" id="text-title-<?php echo $i; ?>" name="text-title-<?php echo $i; ?>" type="text" value="<?php echo $title; ?>" /> |
|---|
| 456 | | <textarea style="width:450px;height:280px" id="text-text-<?php echo $i; ?>" name="text-text-<?php echo $i; ?>"><?php echo $text; ?></textarea> |
|---|
| 457 | | <input type="hidden" id="text-submit-<?php echo $i; ?>" name="text-submit-<?php echo $i; ?>" value="1" /> |
|---|
| | 440 | function wp_widget_text_control($number) { |
|---|
| | 441 | $options = $newoptions = get_option('widget_text'); |
|---|
| | 442 | if ( !is_array($options) ) |
|---|
| | 443 | $options = $newoptions = array(); |
|---|
| | 444 | if ( $_POST["text-submit-$number"] ) { |
|---|
| | 445 | $newoptions[$number]['title'] = strip_tags(stripslashes($_POST["text-title-$number"])); |
|---|
| | 446 | $newoptions[$number]['text'] = stripslashes($_POST["text-text-$number"]); |
|---|
| | 447 | if ( !current_user_can('unfiltered_html') ) |
|---|
| | 448 | $newoptions[$number]['text'] = stripslashes(wp_filter_post_kses($newoptions[$number]['text'])); |
|---|
| | 449 | } |
|---|
| | 450 | if ( $options != $newoptions ) { |
|---|
| | 451 | $options = $newoptions; |
|---|
| | 452 | update_option('widget_text', $options); |
|---|
| | 453 | } |
|---|
| | 454 | $title = htmlspecialchars($options[$number]['title'], ENT_QUOTES); |
|---|
| | 455 | $text = htmlspecialchars($options[$number]['text'], ENT_QUOTES); |
|---|
| | 456 | ?> |
|---|
| | 457 | <input style="width: 450px;" id="text-title-<?php echo "$number"; ?>" name="text-title-<?php echo "$number"; ?>" type="text" value="<?php echo $title; ?>" /> |
|---|
| | 458 | <textarea style="width: 450px; height: 280px;" id="text-text-<?php echo "$number"; ?>" name="text-text-<?php echo "$number"; ?>"><?php echo $text; ?></textarea> |
|---|
| | 459 | <input type="hidden" id="text-submit-<?php echo "$number"; ?>" name="text-submit-<?php echo "$number"; ?>" value="1" /> |
|---|
| 505 | | $options = get_option( 'wp_widget_text' ); |
|---|
| 506 | | |
|---|
| 507 | | $i = $options['number']; |
|---|
| 508 | | |
|---|
| 509 | | if ( $i < 1 ) { |
|---|
| 510 | | $i = 1; |
|---|
| 511 | | } elseif ( $i > 9 ) { |
|---|
| 512 | | $i = 9; |
|---|
| 513 | | } |
|---|
| 514 | | |
|---|
| 515 | | for ( $j = 1; $j <= 9; $j++ ) { |
|---|
| 516 | | $name = array( 'Text %s', '', $i ); |
|---|
| 517 | | register_sidebar_widget( $name, ( $j <= $i ) ? 'wp_widget_text' : '', $j ); |
|---|
| 518 | | register_widget_control( $name, ( $j <= $i ) ? 'wp_widget_text_control' : '', 460, 350, $j ); |
|---|
| 519 | | } |
|---|
| 520 | | |
|---|
| 521 | | add_action( 'sidebar_admin_setup', 'wp_widget_text_setup' ); |
|---|
| 522 | | add_action( 'sidebar_admin_page', 'wp_widget_text_page' ); |
|---|
| 523 | | } |
|---|
| 524 | | |
|---|
| 525 | | function wp_widget_categories( $args ) { |
|---|
| 526 | | extract( $args ); |
|---|
| 527 | | |
|---|
| 528 | | $options = get_option( 'wp_widget_categories' ); |
|---|
| 529 | | |
|---|
| 530 | | $title = ( empty( $options['title'] ) ) ? __( 'Categories' ) : $options['title']; |
|---|
| 531 | | $c = ( $options['count'] ) ? '1' : '0'; |
|---|
| 532 | | $h = ( $options['hierarchical'] ) ? '1' : '0'; |
|---|
| | 495 | $options = get_option('widget_text'); |
|---|
| | 496 | $number = $options['number']; |
|---|
| | 497 | if ( $number < 1 ) $number = 1; |
|---|
| | 498 | if ( $number > 9 ) $number = 9; |
|---|
| | 499 | for ($i = 1; $i <= 9; $i++) { |
|---|
| | 500 | $name = sprintf(__('Text %d'), $i); |
|---|
| | 501 | $id = "text-$i"; // Never never never translate an id |
|---|
| | 502 | register_sidebar_widget($name, $i <= $number ? 'widget_text' : /* unregister */ '', null, $id, $i); |
|---|
| | 503 | register_widget_control($name, $i <= $number ? 'widget_text_control' : /* unregister */ '', 460, 350, $id, $i); |
|---|
| | 504 | } |
|---|
| | 505 | add_action('sidebar_admin_setup', 'wp_widget_text_setup'); |
|---|
| | 506 | add_action('sidebar_admin_page', 'wp_widget_text_page'); |
|---|
| | 507 | } |
|---|
| | 508 | |
|---|
| | 509 | function wp_widget_categories($args) { |
|---|
| | 510 | extract($args); |
|---|
| | 511 | $options = get_option('widget_categories'); |
|---|
| | 512 | $c = $options['count'] ? '1' : '0'; |
|---|
| | 513 | $h = $options['hierarchical'] ? '1' : '0'; |
|---|
| | 514 | $title = empty($options['title']) ? __('Categories') : $options['title']; |
|---|
| 544 | | $options = $newoptions = get_option( 'wp_widget_categories' ); |
|---|
| 545 | | |
|---|
| 546 | | if ( isset( $_POST['categories-submit'] ) ) { |
|---|
| 547 | | $newoptions['count'] = isset( $_POST['categories-count'] ); |
|---|
| 548 | | $newoptions['hierarchical'] = isset( $_POST['categories-hierarchical'] ); |
|---|
| 549 | | $newoptions['title'] = strip_tags( stripslashes( $_POST['categories-title'] ) ); |
|---|
| 550 | | |
|---|
| 551 | | if ( $newoptions != $options ) { |
|---|
| 552 | | $options = $newoptions; |
|---|
| 553 | | update_option( 'wp_widget_categories', $options ); |
|---|
| 554 | | } |
|---|
| 555 | | } |
|---|
| 556 | | |
|---|
| 557 | | $count = ( $options['count'] ) ? ' checked="checked"' : ''; |
|---|
| 558 | | $hierarchical = ( $options['hierarchical'] ) ? ' checked="checked"' : ''; |
|---|
| 559 | | $title = wp_specialchars( $options['title'] ); |
|---|
| 560 | | ?> |
|---|
| 561 | | <p><label for="categories-title"><?php _e( 'Title:' ); ?> <input type="text" value="<?php echo $title; ?>" id="categories-title" name="categories-title" /></label></p> |
|---|
| 562 | | <p style="text-align:right;margin-right:40px"><label for="categories-count"><?php _e( 'Show post counts? '); ?> <input type="checkbox" class="checkbox"<?php echo $count; ?> id="categories-count" name="categories-count" /></label></p> |
|---|
| 563 | | <p style="text-align:right;margin-right:40px"><label for="categories-hierarchical"><?php _e( 'Show hierarchy?' ); ?> <input type="checkbox" class="checkbox"<?php echo $hierarchical; ?> id="categories-hierarchical" name="categories-hierarchical" /></label></p> |
|---|
| 564 | | <input type="hidden" name="categories-submit" id="categories-submit" value="1" /> |
|---|
| 565 | | <?php |
|---|
| 566 | | } |
|---|
| 567 | | |
|---|
| 568 | | function wp_widget_recent_entries( $args ) { |
|---|
| 569 | | extract( $args ); |
|---|
| 570 | | |
|---|
| 571 | | $title = __( 'Recent Posts' ); |
|---|
| 572 | | |
|---|
| 573 | | $query = new WP_Query( 'showposts=10' ); |
|---|
| 574 | | |
|---|
| 575 | | if ( !$query->have_posts() ) { |
|---|
| 576 | | return; |
|---|
| 577 | | } |
|---|
| | 526 | $options = $newoptions = get_option('widget_categories'); |
|---|
| | 527 | if ( $_POST['categories-submit'] ) { |
|---|
| | 528 | $newoptions['count'] = isset($_POST['categories-count']); |
|---|
| | 529 | $newoptions['hierarchical'] = isset($_POST['categories-hierarchical']); |
|---|
| | 530 | $newoptions['title'] = strip_tags(stripslashes($_POST['categories-title'])); |
|---|
| | 531 | } |
|---|
| | 532 | if ( $options != $newoptions ) { |
|---|
| | 533 | $options = $newoptions; |
|---|
| | 534 | update_option('widget_categories', $options); |
|---|
| | 535 | } |
|---|
| | 536 | $count = $options['count'] ? 'checked="checked"' : ''; |
|---|
| | 537 | $hierarchical = $options['hierarchical'] ? 'checked="checked"' : ''; |
|---|
| | 538 | $title = wp_specialchars($options['title']); |
|---|
| | 539 | ?> |
|---|
| | 540 | <p><label for="categories-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php echo $title; ?>" /></label></p> |
|---|
| | 541 | <p style="text-align:right;margin-right:40px;"><label for="categories-count"><?php _e('Show post counts'); ?> <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count" name="categories-count" /></label></p> |
|---|
| | 542 | <p style="text-align:right;margin-right:40px;"><label for="categories-hierarchical" style="text-align:right;"><?php _e('Show hierarchy'); ?> <input class="checkbox" type="checkbox" <?php echo $hierarchical; ?> id="categories-hierarchical" name="categories-hierarchical" /></label></p> |
|---|
| | 543 | <input type="hidden" id="categories-submit" name="categories-submit" value="1" /> |
|---|
| | 544 | <?php |
|---|
| | 545 | } |
|---|
| | 546 | |
|---|
| | 547 | function wp_widget_recent_entries($args) { |
|---|
| | 548 | if ( $output = wp_cache_get('widget_recent_entries') ) |
|---|
| | 549 | return print($output); |
|---|
| | 550 | |
|---|
| | 551 | ob_start(); |
|---|
| | 552 | extract($args); |
|---|
| | 553 | $options = get_option('widget_recent_entries'); |
|---|
| | 554 | $title = empty($options['title']) ? __('Recent Posts') : $options['title']; |
|---|
| | 555 | if ( !$number = (int) $options['number'] ) |
|---|
| | 556 | $number = 10; |
|---|
| | 557 | else if ( $number < 1 ) |
|---|
| | 558 | $number = 1; |
|---|
| | 559 | else if ( $number > 15 ) |
|---|
| | 560 | $number = 15; |
|---|
| | 561 | |
|---|
| | 562 | $r = new WP_Query("showposts=$number&what_to_show=posts&nopaging=0"); |
|---|
| | 563 | if ($r->have_posts()) : |
|---|