WP_Links_List_Table

Core class used to implement displaying links in a list table.

Defined (1)

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

/wp-admin/includes/class-wp-links-list-table.php  
  1. class WP_Links_List_Table extends WP_List_Table { 
  2.  
  3. /** 
  4. * Constructor. 
  5. * @since 3.1.0 
  6. * @access public 
  7. * @see WP_List_Table::__construct() for more information on default arguments. 
  8. * @param array $args An associative array of arguments. 
  9. */ 
  10. public function __construct( $args = array() ) { 
  11. parent::__construct( array( 
  12. 'plural' => 'bookmarks',  
  13. 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,  
  14. ) ); 
  15.  
  16. /** 
  17. * @return bool 
  18. */ 
  19. public function ajax_user_can() { 
  20. return current_user_can( 'manage_links' ); 
  21.  
  22. /** 
  23. * @global int $cat_id 
  24. * @global string $s 
  25. * @global string $orderby 
  26. * @global string $order 
  27. */ 
  28. public function prepare_items() { 
  29. global $cat_id, $s, $orderby, $order; 
  30.  
  31. wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) ); 
  32.  
  33. $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 ); 
  34.  
  35. if ( 'all' != $cat_id ) 
  36. $args['category'] = $cat_id; 
  37. if ( !empty( $s ) ) 
  38. $args['search'] = $s; 
  39. if ( !empty( $orderby ) ) 
  40. $args['orderby'] = $orderby; 
  41. if ( !empty( $order ) ) 
  42. $args['order'] = $order; 
  43.  
  44. $this->items = get_bookmarks( $args ); 
  45.  
  46. /** 
  47. * @access public 
  48. */ 
  49. public function no_items() { 
  50. _e( 'No links found.' ); 
  51.  
  52. /** 
  53. * @return array 
  54. */ 
  55. protected function get_bulk_actions() { 
  56. $actions = array(); 
  57. $actions['delete'] = __( 'Delete' ); 
  58.  
  59. return $actions; 
  60.  
  61. /** 
  62. * @global int $cat_id 
  63. * @param string $which 
  64. */ 
  65. protected function extra_tablenav( $which ) { 
  66. global $cat_id; 
  67.  
  68. if ( 'top' != $which ) 
  69. return; 
  70. ?> 
  71. <div class="alignleft actions"> 
  72. <?php 
  73. $dropdown_options = array( 
  74. 'selected' => $cat_id,  
  75. 'name' => 'cat_id',  
  76. 'taxonomy' => 'link_category',  
  77. 'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items,  
  78. 'hide_empty' => true,  
  79. 'hierarchical' => 1,  
  80. 'show_count' => 0,  
  81. 'orderby' => 'name',  
  82. ); 
  83.  
  84. echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>'; 
  85. wp_dropdown_categories( $dropdown_options ); 
  86. submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 
  87. ?> 
  88. </div> 
  89. <?php 
  90.  
  91. /** 
  92. * @return array 
  93. */ 
  94. public function get_columns() { 
  95. return array( 
  96. 'cb' => '<input type="checkbox" />',  
  97. 'name' => _x( 'Name', 'link name' ),  
  98. 'url' => __( 'URL' ),  
  99. 'categories' => __( 'Categories' ),  
  100. 'rel' => __( 'Relationship' ),  
  101. 'visible' => __( 'Visible' ),  
  102. 'rating' => __( 'Rating' ) 
  103. ); 
  104.  
  105. /** 
  106. * @return array 
  107. */ 
  108. protected function get_sortable_columns() { 
  109. return array( 
  110. 'name' => 'name',  
  111. 'url' => 'url',  
  112. 'visible' => 'visible',  
  113. 'rating' => 'rating' 
  114. ); 
  115.  
  116. /** 
  117. * Get the name of the default primary column. 
  118. * @since 4.3.0 
  119. * @access protected 
  120. * @return string Name of the default primary column, in this case, 'name'. 
  121. */ 
  122. protected function get_default_primary_column_name() { 
  123. return 'name'; 
  124.  
  125. /** 
  126. * Handles the checkbox column output. 
  127. * @since 4.3.0 
  128. * @access public 
  129. * @param object $link The current link object. 
  130. */ 
  131. public function column_cb( $link ) { 
  132. ?> 
  133. <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label> 
  134. <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" /> 
  135. <?php 
  136.  
  137. /** 
  138. * Handles the link name column output. 
  139. * @since 4.3.0 
  140. * @access public 
  141. * @param object $link The current link object. 
  142. */ 
  143. public function column_name( $link ) { 
  144. $edit_link = get_edit_bookmark_link( $link ); 
  145. printf( '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',  
  146. $edit_link,  
  147. /** translators: %s: link name */ 
  148. esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ),  
  149. $link->link_name 
  150. ); 
  151.  
  152. /** 
  153. * Handles the link URL column output. 
  154. * @since 4.3.0 
  155. * @access public 
  156. * @param object $link The current link object. 
  157. */ 
  158. public function column_url( $link ) { 
  159. $short_url = url_shorten( $link->link_url ); 
  160. echo "<a href='$link->link_url'>$short_url</a>"; 
  161.  
  162. /** 
  163. * Handles the link categories column output. 
  164. * @since 4.3.0 
  165. * @access public 
  166. * @global $cat_id 
  167. * @param object $link The current link object. 
  168. */ 
  169. public function column_categories( $link ) { 
  170. global $cat_id; 
  171.  
  172. $cat_names = array(); 
  173. foreach ( $link->link_category as $category ) { 
  174. $cat = get_term( $category, 'link_category', OBJECT, 'display' ); 
  175. if ( is_wp_error( $cat ) ) { 
  176. echo $cat->get_error_message(); 
  177. $cat_name = $cat->name; 
  178. if ( $cat_id != $category ) { 
  179. $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>"; 
  180. $cat_names[] = $cat_name; 
  181. echo implode( ', ', $cat_names ); 
  182.  
  183. /** 
  184. * Handles the link relation column output. 
  185. * @since 4.3.0 
  186. * @access public 
  187. * @param object $link The current link object. 
  188. */ 
  189. public function column_rel( $link ) { 
  190. echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; 
  191.  
  192. /** 
  193. * Handles the link visibility column output. 
  194. * @since 4.3.0 
  195. * @access public 
  196. * @param object $link The current link object. 
  197. */ 
  198. public function column_visible( $link ) { 
  199. if ( 'Y' === $link->link_visible ) { 
  200. _e( 'Yes' ); 
  201. } else { 
  202. _e( 'No' ); 
  203.  
  204. /** 
  205. * Handles the link rating column output. 
  206. * @since 4.3.0 
  207. * @access public 
  208. * @param object $link The current link object. 
  209. */ 
  210. public function column_rating( $link ) { 
  211. echo $link->link_rating; 
  212.  
  213. /** 
  214. * Handles the default column output. 
  215. * @since 4.3.0 
  216. * @access public 
  217. * @param object $link Link object. 
  218. * @param string $column_name Current column name. 
  219. */ 
  220. public function column_default( $link, $column_name ) { 
  221. /** 
  222. * Fires for each registered custom link column. 
  223. * @since 2.1.0 
  224. * @param string $column_name Name of the custom column. 
  225. * @param int $link_id Link ID. 
  226. */ 
  227. do_action( 'manage_link_custom_column', $column_name, $link->link_id ); 
  228.  
  229. public function display_rows() { 
  230. foreach ( $this->items as $link ) { 
  231. $link = sanitize_bookmark( $link ); 
  232. $link->link_name = esc_attr( $link->link_name ); 
  233. $link->link_category = wp_get_link_cats( $link->link_id ); 
  234. ?> 
  235. <tr id="link-<?php echo $link->link_id; ?>"> 
  236. <?php $this->single_row_columns( $link ) ?> 
  237. </tr> 
  238. <?php 
  239.  
  240. /** 
  241. * Generates and displays row action links. 
  242. * @since 4.3.0 
  243. * @access protected 
  244. * @param object $link Link being acted upon. 
  245. * @param string $column_name Current column name. 
  246. * @param string $primary Primary column name. 
  247. * @return string Row action output for links. 
  248. */ 
  249. protected function handle_row_actions( $link, $column_name, $primary ) { 
  250. if ( $primary !== $column_name ) { 
  251. return ''; 
  252.  
  253. $edit_link = get_edit_bookmark_link( $link ); 
  254.  
  255. $actions = array(); 
  256. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; 
  257. $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm( '" . esc_js(sprintf(__("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name)) . "' ) ) { return true;}return false;\">" . __('Delete') . "</a>"; 
  258. return $this->row_actions( $actions );