26 * @param string|array $args { |
26 * @param string|array $args { |
27 * Optional. Bookmarks arguments. |
27 * Optional. Bookmarks arguments. |
28 * |
28 * |
29 * @type int|bool $show_updated Whether to show the time the bookmark was last updated. |
29 * @type int|bool $show_updated Whether to show the time the bookmark was last updated. |
30 * Accepts 1|true or 0|false. Default 0|false. |
30 * Accepts 1|true or 0|false. Default 0|false. |
31 * @type int|bool $show_description Whether to show the bookmakr description. Accepts 1|true, |
31 * @type int|bool $show_description Whether to show the bookmark description. Accepts 1|true, |
32 * Accepts 1|true or 0|false. Default 0|false. |
32 * Accepts 1|true or 0|false. Default 0|false. |
33 * @type int|bool $show_images Whether to show the link image if available. Accepts 1|true |
33 * @type int|bool $show_images Whether to show the link image if available. Accepts 1|true |
34 * or 0|false. Default 1|true. |
34 * or 0|false. Default 1|true. |
35 * @type int|bool $show_name Whether to show link name if available. Accepts 1|true or |
35 * @type int|bool $show_name Whether to show link name if available. Accepts 1|true or |
36 * 0|false. Default 0|false. |
36 * 0|false. Default 0|false. |
70 } |
76 } |
71 $the_link = '#'; |
77 $the_link = '#'; |
72 if ( ! empty( $bookmark->link_url ) ) { |
78 if ( ! empty( $bookmark->link_url ) ) { |
73 $the_link = esc_url( $bookmark->link_url ); |
79 $the_link = esc_url( $bookmark->link_url ); |
74 } |
80 } |
75 $desc = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) ); |
81 $desc = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) ); |
76 $name = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) ); |
82 $name = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) ); |
77 $title = $desc; |
83 $title = $desc; |
78 |
84 |
79 if ( $r['show_updated'] ) { |
85 if ( $r['show_updated'] ) { |
80 if ( '00' != substr( $bookmark->link_updated_f, 0, 2 ) ) { |
86 if ( '00' != substr( $bookmark->link_updated_f, 0, 2 ) ) { |
81 $title .= ' ('; |
87 $title .= ' ('; |
82 $title .= sprintf( |
88 $title .= sprintf( |
83 __('Last updated: %s'), |
89 __( 'Last updated: %s' ), |
84 date( |
90 date( |
85 get_option( 'links_updated_date_format' ), |
91 get_option( 'links_updated_date_format' ), |
86 $bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) |
92 $bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) |
87 ) |
93 ) |
88 ); |
94 ); |
197 * } |
203 * } |
198 * @return string|void Will only return if echo option is set to not echo. Default is not return anything. |
204 * @return string|void Will only return if echo option is set to not echo. Default is not return anything. |
199 */ |
205 */ |
200 function wp_list_bookmarks( $args = '' ) { |
206 function wp_list_bookmarks( $args = '' ) { |
201 $defaults = array( |
207 $defaults = array( |
202 'orderby' => 'name', 'order' => 'ASC', |
208 'orderby' => 'name', |
203 'limit' => -1, 'category' => '', 'exclude_category' => '', |
209 'order' => 'ASC', |
204 'category_name' => '', 'hide_invisible' => 1, |
210 'limit' => -1, |
205 'show_updated' => 0, 'echo' => 1, |
211 'category' => '', |
206 'categorize' => 1, 'title_li' => __('Bookmarks'), |
212 'exclude_category' => '', |
207 'title_before' => '<h2>', 'title_after' => '</h2>', |
213 'category_name' => '', |
208 'category_orderby' => 'name', 'category_order' => 'ASC', |
214 'hide_invisible' => 1, |
209 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">', |
215 'show_updated' => 0, |
210 'category_after' => '</li>' |
216 'echo' => 1, |
|
217 'categorize' => 1, |
|
218 'title_li' => __( 'Bookmarks' ), |
|
219 'title_before' => '<h2>', |
|
220 'title_after' => '</h2>', |
|
221 'category_orderby' => 'name', |
|
222 'category_order' => 'ASC', |
|
223 'class' => 'linkcat', |
|
224 'category_before' => '<li id="%id" class="%class">', |
|
225 'category_after' => '</li>', |
211 ); |
226 ); |
212 |
227 |
213 $r = wp_parse_args( $args, $defaults ); |
228 $r = wp_parse_args( $args, $defaults ); |
214 |
229 |
215 $output = ''; |
230 $output = ''; |
216 |
231 |
217 if ( ! is_array( $r['class'] ) ) { |
232 if ( ! is_array( $r['class'] ) ) { |
218 $r['class'] = explode( ' ', $r['class'] ); |
233 $r['class'] = explode( ' ', $r['class'] ); |
219 } |
234 } |
220 $r['class'] = array_map( 'sanitize_html_class', $r['class'] ); |
235 $r['class'] = array_map( 'sanitize_html_class', $r['class'] ); |
221 $r['class'] = trim( join( ' ', $r['class'] ) ); |
236 $r['class'] = trim( join( ' ', $r['class'] ) ); |
222 |
237 |
223 if ( $r['categorize'] ) { |
238 if ( $r['categorize'] ) { |
224 $cats = get_terms( 'link_category', array( |
239 $cats = get_terms( |
225 'name__like' => $r['category_name'], |
240 'link_category', |
226 'include' => $r['category'], |
241 array( |
227 'exclude' => $r['exclude_category'], |
242 'name__like' => $r['category_name'], |
228 'orderby' => $r['category_orderby'], |
243 'include' => $r['category'], |
229 'order' => $r['category_order'], |
244 'exclude' => $r['exclude_category'], |
230 'hierarchical' => 0 |
245 'orderby' => $r['category_orderby'], |
231 ) ); |
246 'order' => $r['category_order'], |
|
247 'hierarchical' => 0, |
|
248 ) |
|
249 ); |
232 if ( empty( $cats ) ) { |
250 if ( empty( $cats ) ) { |
233 $r['categorize'] = false; |
251 $r['categorize'] = false; |
234 } |
252 } |
235 } |
253 } |
236 |
254 |
237 if ( $r['categorize'] ) { |
255 if ( $r['categorize'] ) { |
238 // Split the bookmarks into ul's for each category |
256 // Split the bookmarks into ul's for each category |
239 foreach ( (array) $cats as $cat ) { |
257 foreach ( (array) $cats as $cat ) { |
240 $params = array_merge( $r, array( 'category' => $cat->term_id ) ); |
258 $params = array_merge( $r, array( 'category' => $cat->term_id ) ); |
241 $bookmarks = get_bookmarks( $params ); |
259 $bookmarks = get_bookmarks( $params ); |
242 if ( empty( $bookmarks ) ) { |
260 if ( empty( $bookmarks ) ) { |
243 continue; |
261 continue; |
244 } |
262 } |
245 $output .= str_replace( |
263 $output .= str_replace( |
246 array( '%id', '%class' ), |
264 array( '%id', '%class' ), |
247 array( "linkcat-$cat->term_id", $r['class'] ), |
265 array( "linkcat-$cat->term_id", $r['class'] ), |
248 $r['category_before'] |
266 $r['category_before'] |
249 ); |
267 ); |
250 /** |
268 /** |
251 * Filters the bookmarks category name. |
269 * Filters the category name. |
252 * |
270 * |
253 * @since 2.2.0 |
271 * @since 2.2.0 |
254 * |
272 * |
255 * @param string $cat_name The category name of bookmarks. |
273 * @param string $cat_name The category name. |
256 */ |
274 */ |
257 $catname = apply_filters( 'link_category', $cat->name ); |
275 $catname = apply_filters( 'link_category', $cat->name ); |
258 |
276 |
259 $output .= $r['title_before']; |
277 $output .= $r['title_before']; |
260 $output .= $catname; |
278 $output .= $catname; |