3 * List Table API: WP_Links_List_Table class
6 * @subpackage Administration
11 * Core class used to implement displaying links in a list table.
18 class WP_Links_List_Table extends WP_List_Table {
26 * @see WP_List_Table::__construct() for more information on default arguments.
28 * @param array $args An associative array of arguments.
30 public function __construct( $args = array() ) {
31 parent::__construct( array(
32 'plural' => 'bookmarks',
33 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
41 public function ajax_user_can() {
42 return current_user_can( 'manage_links' );
49 * @global string $orderby
50 * @global string $order
52 public function prepare_items() {
53 global $cat_id, $s, $orderby, $order;
55 wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
57 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
59 if ( 'all' != $cat_id )
60 $args['category'] = $cat_id;
63 if ( !empty( $orderby ) )
64 $args['orderby'] = $orderby;
65 if ( !empty( $order ) )
66 $args['order'] = $order;
68 $this->items = get_bookmarks( $args );
74 public function no_items() {
75 _e( 'No links found.' );
82 protected function get_bulk_actions() {
84 $actions['delete'] = __( 'Delete' );
92 * @param string $which
94 protected function extra_tablenav( $which ) {
97 if ( 'top' != $which )
100 <div class="alignleft actions">
102 $dropdown_options = array(
103 'selected' => $cat_id,
105 'taxonomy' => 'link_category',
106 'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items,
107 'hide_empty' => true,
113 echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>';
114 wp_dropdown_categories( $dropdown_options );
115 submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
125 public function get_columns() {
127 'cb' => '<input type="checkbox" />',
128 'name' => _x( 'Name', 'link name' ),
129 'url' => __( 'URL' ),
130 'categories' => __( 'Categories' ),
131 'rel' => __( 'Relationship' ),
132 'visible' => __( 'Visible' ),
133 'rating' => __( 'Rating' )
141 protected function get_sortable_columns() {
145 'visible' => 'visible',
151 * Get the name of the default primary column.
156 * @return string Name of the default primary column, in this case, 'name'.
158 protected function get_default_primary_column_name() {
163 * Handles the checkbox column output.
168 * @param object $link The current link object.
170 public function column_cb( $link ) {
172 <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
173 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
178 * Handles the link name column output.
183 * @param object $link The current link object.
185 public function column_name( $link ) {
186 $edit_link = get_edit_bookmark_link( $link );
187 printf( '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',
189 /* translators: %s: link name */
190 esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ),
196 * Handles the link URL column output.
201 * @param object $link The current link object.
203 public function column_url( $link ) {
204 $short_url = url_shorten( $link->link_url );
205 echo "<a href='$link->link_url'>$short_url</a>";
209 * Handles the link categories column output.
216 * @param object $link The current link object.
218 public function column_categories( $link ) {
221 $cat_names = array();
222 foreach ( $link->link_category as $category ) {
223 $cat = get_term( $category, 'link_category', OBJECT, 'display' );
224 if ( is_wp_error( $cat ) ) {
225 echo $cat->get_error_message();
227 $cat_name = $cat->name;
228 if ( $cat_id != $category ) {
229 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
231 $cat_names[] = $cat_name;
233 echo implode( ', ', $cat_names );
237 * Handles the link relation column output.
242 * @param object $link The current link object.
244 public function column_rel( $link ) {
245 echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
249 * Handles the link visibility column output.
254 * @param object $link The current link object.
256 public function column_visible( $link ) {
257 if ( 'Y' === $link->link_visible ) {
265 * Handles the link rating column output.
270 * @param object $link The current link object.
272 public function column_rating( $link ) {
273 echo $link->link_rating;
277 * Handles the default column output.
282 * @param object $link Link object.
283 * @param string $column_name Current column name.
285 public function column_default( $link, $column_name ) {
287 * Fires for each registered custom link column.
291 * @param string $column_name Name of the custom column.
292 * @param int $link_id Link ID.
294 do_action( 'manage_link_custom_column', $column_name, $link->link_id );
297 public function display_rows() {
298 foreach ( $this->items as $link ) {
299 $link = sanitize_bookmark( $link );
300 $link->link_name = esc_attr( $link->link_name );
301 $link->link_category = wp_get_link_cats( $link->link_id );
303 <tr id="link-<?php echo $link->link_id; ?>">
304 <?php $this->single_row_columns( $link ) ?>
311 * Generates and displays row action links.
316 * @param object $link Link being acted upon.
317 * @param string $column_name Current column name.
318 * @param string $primary Primary column name.
319 * @return string Row action output for links.
321 protected function handle_row_actions( $link, $column_name, $primary ) {
322 if ( $primary !== $column_name ) {
326 $edit_link = get_edit_bookmark_link( $link );
329 $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
330 $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>";
331 return $this->row_actions( $actions );