3 * Links Manager List Table class.
6 * @subpackage List_Table
10 class WP_Links_List_Table extends WP_List_Table {
12 function __construct( $args = array() ) {
13 parent::__construct( array(
14 'plural' => 'bookmarks',
15 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
19 function ajax_user_can() {
20 return current_user_can( 'manage_links' );
23 function prepare_items() {
24 global $cat_id, $s, $orderby, $order;
26 wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
28 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
30 if ( 'all' != $cat_id )
31 $args['category'] = $cat_id;
34 if ( !empty( $orderby ) )
35 $args['orderby'] = $orderby;
36 if ( !empty( $order ) )
37 $args['order'] = $order;
39 $this->items = get_bookmarks( $args );
43 _e( 'No links found.' );
46 function get_bulk_actions() {
48 $actions['delete'] = __( 'Delete' );
53 function extra_tablenav( $which ) {
56 if ( 'top' != $which )
59 <div class="alignleft actions">
61 $dropdown_options = array(
62 'selected' => $cat_id,
64 'taxonomy' => 'link_category',
65 'show_option_all' => __( 'View all categories' ),
71 wp_dropdown_categories( $dropdown_options );
72 submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) );
78 function get_columns() {
80 'cb' => '<input type="checkbox" />',
81 'name' => _x( 'Name', 'link name' ),
83 'categories' => __( 'Categories' ),
84 'rel' => __( 'Relationship' ),
85 'visible' => __( 'Visible' ),
86 'rating' => __( 'Rating' )
90 function get_sortable_columns() {
94 'visible' => 'visible',
99 function display_rows() {
104 foreach ( $this->items as $link ) {
105 $link = sanitize_bookmark( $link );
106 $link->link_name = esc_attr( $link->link_name );
107 $link->link_category = wp_get_link_cats( $link->link_id );
109 $short_url = url_shorten( $link->link_url );
111 $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' );
112 $rating = $link->link_rating;
113 $style = ( $alt++ % 2 ) ? '' : ' class="alternate"';
115 $edit_link = get_edit_bookmark_link( $link );
117 <tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>>
120 list( $columns, $hidden ) = $this->get_column_info();
122 foreach ( $columns as $column_name => $column_display_name ) {
123 $class = "class='column-$column_name'";
126 if ( in_array( $column_name, $hidden ) )
127 $style = ' style="display:none;"';
129 $attributes = $class . $style;
131 switch ( $column_name ) {
133 <th scope="row" class="check-column">
134 <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
135 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
141 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 />";
144 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
145 $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>";
146 echo $this->row_actions( $actions );
151 echo "<td $attributes><a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a></td>";
154 ?><td <?php echo $attributes ?>><?php
155 $cat_names = array();
156 foreach ( $link->link_category as $category ) {
157 $cat = get_term( $category, 'link_category', OBJECT, 'display' );
158 if ( is_wp_error( $cat ) )
159 echo $cat->get_error_message();
160 $cat_name = $cat->name;
161 if ( $cat_id != $category )
162 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
163 $cat_names[] = $cat_name;
165 echo implode( ', ', $cat_names );
169 ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php
172 ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
175 ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
179 <td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td>