wp_link_category_checklist

Outputs a link category checklist element.

Description

wp_link_category_checklist( (int) $link_id = 0 ); 

Parameters (1)

0. $link_id — Optional. (int)
The link id.

Usage

  1. if ( !function_exists( 'wp_link_category_checklist' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // The link id. 
  5. $link_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_link_category_checklist($link_id); 
  9.  

Defined (1)

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

/wp-admin/includes/template.php  
  1. function wp_link_category_checklist( $link_id = 0 ) { 
  2. $default = 1; 
  3.  
  4. $checked_categories = array(); 
  5.  
  6. if ( $link_id ) { 
  7. $checked_categories = wp_get_link_cats( $link_id ); 
  8. // No selected categories, strange 
  9. if ( ! count( $checked_categories ) ) { 
  10. $checked_categories[] = $default; 
  11. } else { 
  12. $checked_categories[] = $default; 
  13.  
  14. $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); 
  15.  
  16. if ( empty( $categories ) ) 
  17. return; 
  18.  
  19. foreach ( $categories as $category ) { 
  20. $cat_id = $category->term_id; 
  21.  
  22. /** This filter is documented in wp-includes/category-template.php */ 
  23. $name = esc_html( apply_filters( 'the_category', $category->name ) ); 
  24. $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; 
  25. echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";