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' => __( 'All categories' ),
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 ouput.
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 ouput.
183 * @param object $link The current link object.
185 public function column_name( $link ) {
186 $edit_link = get_edit_bookmark_link( $link );
188 <strong><a class="row-title" href="<?php echo $edit_link ?>" title="<?php
189 echo esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) );
190 ?>"><?php echo $link->link_name ?></a></strong><br />
195 * Handles the link URL column ouput.
200 * @param object $link The current link object.
202 public function column_url( $link ) {
203 $short_url = url_shorten( $link->link_url );
204 echo "<a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a>";
208 * Handles the link categories column output.
215 * @param object $link The current link object.
217 public function column_categories( $link ) {
220 $cat_names = array();
221 foreach ( $link->link_category as $category ) {
222 $cat = get_term( $category, 'link_category', OBJECT, 'display' );
223 if ( is_wp_error( $cat ) ) {
224 echo $cat->get_error_message();
226 $cat_name = $cat->name;
227 if ( $cat_id != $category ) {
228 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
230 $cat_names[] = $cat_name;
232 echo implode( ', ', $cat_names );
236 * Handles the link relation column ouput.
241 * @param object $link The current link object.
243 public function column_rel( $link ) {
244 echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
248 * Handles the link visibility column ouput.
253 * @param object $link The current link object.
255 public function column_visible( $link ) {
256 if ( 'Y' === $link->link_visible ) {
264 * Handles the link rating column ouput.
269 * @param object $link The current link object.
271 public function column_rating( $link ) {
272 echo $link->link_rating;
276 * Handles the default column output.
281 * @param object $link Link object.
282 * @param string $column_name Current column name.
284 public function column_default( $link, $column_name ) {
286 * Fires for each registered custom link column.
290 * @param string $column_name Name of the custom column.
291 * @param int $link_id Link ID.
293 do_action( 'manage_link_custom_column', $column_name, $link->link_id );
296 public function display_rows() {
297 foreach ( $this->items as $link ) {
298 $link = sanitize_bookmark( $link );
299 $link->link_name = esc_attr( $link->link_name );
300 $link->link_category = wp_get_link_cats( $link->link_id );
302 <tr id="link-<?php echo $link->link_id; ?>">
303 <?php $this->single_row_columns( $link ) ?>
310 * Generates and displays row action links.
315 * @param object $link Link being acted upon.
316 * @param string $column_name Current column name.
317 * @param string $primary Primary column name.
318 * @return string Row action output for links.
320 protected function handle_row_actions( $link, $column_name, $primary ) {
321 if ( $primary !== $column_name ) {
325 $edit_link = get_edit_bookmark_link( $link );
328 $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
329 $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>";
330 return $this->row_actions( $actions );