3 * Links Manager List Table class.
6 * @subpackage List_Table
10 class WP_Links_List_Table extends WP_List_Table {
18 * @see WP_List_Table::__construct() for more information on default arguments.
20 * @param array $args An associative array of arguments.
22 public function __construct( $args = array() ) {
23 parent::__construct( array(
24 'plural' => 'bookmarks',
25 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
29 public function ajax_user_can() {
30 return current_user_can( 'manage_links' );
33 public function prepare_items() {
34 global $cat_id, $s, $orderby, $order;
36 wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
38 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
40 if ( 'all' != $cat_id )
41 $args['category'] = $cat_id;
44 if ( !empty( $orderby ) )
45 $args['orderby'] = $orderby;
46 if ( !empty( $order ) )
47 $args['order'] = $order;
49 $this->items = get_bookmarks( $args );
52 public function no_items() {
53 _e( 'No links found.' );
56 protected function get_bulk_actions() {
58 $actions['delete'] = __( 'Delete' );
63 protected function extra_tablenav( $which ) {
66 if ( 'top' != $which )
69 <div class="alignleft actions">
71 $dropdown_options = array(
72 'selected' => $cat_id,
74 'taxonomy' => 'link_category',
75 'show_option_all' => __( 'All categories' ),
82 echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>';
83 wp_dropdown_categories( $dropdown_options );
84 submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
90 public function get_columns() {
92 'cb' => '<input type="checkbox" />',
93 'name' => _x( 'Name', 'link name' ),
95 'categories' => __( 'Categories' ),
96 'rel' => __( 'Relationship' ),
97 'visible' => __( 'Visible' ),
98 'rating' => __( 'Rating' )
102 protected function get_sortable_columns() {
106 'visible' => 'visible',
111 public function display_rows() {
116 foreach ( $this->items as $link ) {
117 $link = sanitize_bookmark( $link );
118 $link->link_name = esc_attr( $link->link_name );
119 $link->link_category = wp_get_link_cats( $link->link_id );
121 $short_url = url_shorten( $link->link_url );
123 $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' );
124 $rating = $link->link_rating;
125 $style = ( $alt++ % 2 ) ? '' : ' class="alternate"';
127 $edit_link = get_edit_bookmark_link( $link );
129 <tr id="link-<?php echo $link->link_id; ?>" <?php echo $style; ?>>
132 list( $columns, $hidden ) = $this->get_column_info();
134 foreach ( $columns as $column_name => $column_display_name ) {
135 $class = "class='column-$column_name'";
138 if ( in_array( $column_name, $hidden ) )
139 $style = ' style="display:none;"';
141 $attributes = $class . $style;
143 switch ( $column_name ) {
145 <th scope="row" class="check-column">
146 <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
147 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
153 echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />";
156 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
157 $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>";
158 echo $this->row_actions( $actions );
163 echo "<td $attributes><a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a></td>";
166 ?><td <?php echo $attributes ?>><?php
167 $cat_names = array();
168 foreach ( $link->link_category as $category ) {
169 $cat = get_term( $category, 'link_category', OBJECT, 'display' );
170 if ( is_wp_error( $cat ) )
171 echo $cat->get_error_message();
172 $cat_name = $cat->name;
173 if ( $cat_id != $category )
174 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
175 $cat_names[] = $cat_name;
177 echo implode( ', ', $cat_names );
181 ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php
184 ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
187 ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
191 <td <?php echo $attributes ?>><?php
193 * Fires for each registered custom link column.
197 * @param string $column_name Name of the custom column.
198 * @param int $link_id Link ID.
200 do_action( 'manage_link_custom_column', $column_name, $link->link_id );