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
if ( !function_exists( 'wp_link_category_checklist' ) ) { require_once ABSPATH . '/wp-admin/includes/template.php'; } // The link id. $link_id = -1; // NOTICE! Understand what this does before running. $result = wp_link_category_checklist($link_id);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/template.php
- function wp_link_category_checklist( $link_id = 0 ) {
- $default = 1;
- $checked_categories = array();
- if ( $link_id ) {
- $checked_categories = wp_get_link_cats( $link_id );
- // No selected categories, strange
- if ( ! count( $checked_categories ) ) {
- $checked_categories[] = $default;
- }
- } else {
- $checked_categories[] = $default;
- }
- $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
- if ( empty( $categories ) )
- return;
- foreach ( $categories as $category ) {
- $cat_id = $category->term_id;
- /** This filter is documented in wp-includes/category-template.php */
- $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
- 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>";
- }
- }