_walk_bookmarks

The formatted output of a list of bookmarks.

Description

(string) _walk_bookmarks( (array) $bookmarks, (string) $args = '' ); 

The $bookmarks array must contain bookmark objects and will be iterated over to retrieve the bookmark to be used in the output.

The output is formatted as HTML with no way to change that format. However, what is between, before, and after can be changed. The link itself will be HTML.

This function is used internally by wp_list_bookmarks() and should not be used by themes.

Returns (string)

Formatted output in HTML

Parameters (2)

0. $bookmarks (array)
List of bookmarks to traverse.
1. $args — Optional. (string) => ''
Bookmarks arguments.

Options

  • show_updated (int|bool) => 0

    Whether to show the time the bookmark was last updated. Accepts 1|true or 0|false.

  • show_description (int|bool) => 0

    Whether to show the bookmakr description. Accepts 1|true, Accepts 1|true or 0|false.

  • show_images (int|bool) => 1

    Whether to show the link image if available. Accepts 1|true or 0|false.

  • show_name (int|bool) => 0

    Whether to show link name if available. Accepts 1|true or 0|false.

  • before (string) => ''

    The HTML or text to prepend to each bookmark.

  • after (string) => ''

    The HTML or text to append to each bookmark.

  • link_before (string) => ''

    The HTML or text to prepend to each bookmark inside the anchor tags.

  • link_after (string) => ''

    The HTML or text to append to each bookmark inside the anchor tags.

  • between (string) => "\n"

    The string for use in between the link, description, and image.

array(

    /**
     * Whether to show the time the bookmark was last updated. Accepts 1|true or 0|false.
     *
     * @type int|bool
     */
    'show_updated' => 0,

    /**
     * Whether to show the bookmakr description. Accepts 1|true, Accepts 1|true or 0|false.
     *
     * @type int|bool
     */
    'show_description' => 0,

    /**
     * Whether to show the link image if available. Accepts 1|true or 0|false.
     *
     * @type int|bool
     * @default 1
     */
    'show_images' => 1,

    /**
     * Whether to show link name if available. Accepts 1|true or 0|false.
     *
     * @type int|bool
     */
    'show_name' => 0,

    /**
     * The HTML or text to prepend to each bookmark.
     *
     * @type string
     * @default ''
     */
    'before' => '',

    /**
     * The HTML or text to append to each bookmark.
     *
     * @type string
     * @default ''
     */
    'after' => '',

    /**
     * The HTML or text to prepend to each bookmark inside the anchor tags.
     *
     * @type string
     * @default ''
     */
    'link_before' => '',

    /**
     * The HTML or text to append to each bookmark inside the anchor tags.
     *
     * @type string
     * @default ''
     */
    'link_after' => '',

    /**
     * The string for use in between the link, description, and image.
     *
     * @type string
     * @default "\n"
     */
    'between' => "\n"
);        


Usage

  1. if ( !function_exists( '_walk_bookmarks' ) ) { 
  2. require_once ABSPATH . WPINC . '/bookmark-template.php'; 
  3.  
  4. // List of bookmarks to traverse. 
  5. $bookmarks = array(); 
  6.  
  7. // Optional. Bookmarks arguments. 
  8. $args = array( 
  9. 'show_updated' => 0, 
  10. 'show_description' => 0, 
  11. 'show_images' => 1, 
  12. 'show_name' => 0, 
  13. 'before' => '', 
  14. 'after' => '', 
  15. 'link_before' => '', 
  16. 'link_after' => '', 
  17. 'between' => "\n" 
  18. ); 
  19.  
  20. // NOTICE! Understand what this does before running. 
  21. $result = _walk_bookmarks($bookmarks, $args); 
  22.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/bookmark-template.php  
  1. function _walk_bookmarks( $bookmarks, $args = '' ) { 
  2. $defaults = array( 
  3. 'show_updated' => 0, 'show_description' => 0,  
  4. 'show_images' => 1, 'show_name' => 0,  
  5. 'before' => '<li>', 'after' => '</li>', 'between' => "\n",  
  6. 'show_rating' => 0, 'link_before' => '', 'link_after' => '' 
  7. ); 
  8.  
  9. $r = wp_parse_args( $args, $defaults ); 
  10.  
  11. $output = ''; // Blank string to start with. 
  12.  
  13. foreach ( (array) $bookmarks as $bookmark ) { 
  14. if ( ! isset( $bookmark->recently_updated ) ) { 
  15. $bookmark->recently_updated = false; 
  16. $output .= $r['before']; 
  17. if ( $r['show_updated'] && $bookmark->recently_updated ) { 
  18. $output .= '<em>'; 
  19. $the_link = '#'; 
  20. if ( ! empty( $bookmark->link_url ) ) { 
  21. $the_link = esc_url( $bookmark->link_url ); 
  22. $desc = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) ); 
  23. $name = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) ); 
  24. $title = $desc; 
  25.  
  26. if ( $r['show_updated'] ) { 
  27. if ( '00' != substr( $bookmark->link_updated_f, 0, 2 ) ) { 
  28. $title .= ' ('; 
  29. $title .= sprintf( 
  30. __('Last updated: %s'),  
  31. date( 
  32. get_option( 'links_updated_date_format' ),  
  33. $bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS
  34. ); 
  35. $title .= ')'; 
  36. $alt = ' alt="' . $name . ( $r['show_description'] ? ' ' . $title : '' ) . '"'; 
  37.  
  38. if ( '' != $title ) { 
  39. $title = ' title="' . $title . '"'; 
  40. $rel = $bookmark->link_rel; 
  41. if ( '' != $rel ) { 
  42. $rel = ' rel="' . esc_attr($rel) . '"'; 
  43. $target = $bookmark->link_target; 
  44. if ( '' != $target ) { 
  45. $target = ' target="' . $target . '"'; 
  46. $output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>'; 
  47.  
  48. $output .= $r['link_before']; 
  49.  
  50. if ( $bookmark->link_image != null && $r['show_images'] ) { 
  51. if ( strpos( $bookmark->link_image, 'http' ) === 0 ) { 
  52. $output .= "<img src=\"$bookmark->link_image\" $alt $title />"; 
  53. } else { // If it's a relative path 
  54. $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; 
  55. if ( $r['show_name'] ) { 
  56. $output .= " $name"; 
  57. } else { 
  58. $output .= $name; 
  59.  
  60. $output .= $r['link_after']; 
  61.  
  62. $output .= '</a>'; 
  63.  
  64. if ( $r['show_updated'] && $bookmark->recently_updated ) { 
  65. $output .= '</em>'; 
  66.  
  67. if ( $r['show_description'] && '' != $desc ) { 
  68. $output .= $r['between'] . $desc; 
  69.  
  70. if ( $r['show_rating'] ) { 
  71. $output .= $r['between'] . sanitize_bookmark_field
  72. 'link_rating',  
  73. $bookmark->link_rating,  
  74. $bookmark->link_id,  
  75. 'display' 
  76. ); 
  77. $output .= $r['after'] . "\n"; 
  78. } // end while 
  79.  
  80. return $output;