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,
33 public function ajax_user_can() {
34 return current_user_can( 'manage_links' );
41 * @global string $orderby
42 * @global string $order
44 public function prepare_items() {
45 global $cat_id, $s, $orderby, $order;
47 wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
49 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
51 if ( 'all' != $cat_id )
52 $args['category'] = $cat_id;
55 if ( !empty( $orderby ) )
56 $args['orderby'] = $orderby;
57 if ( !empty( $order ) )
58 $args['order'] = $order;
60 $this->items = get_bookmarks( $args );
66 public function no_items() {
67 _e( 'No links found.' );
74 protected function get_bulk_actions() {
76 $actions['delete'] = __( 'Delete' );
84 * @param string $which
86 protected function extra_tablenav( $which ) {
89 if ( 'top' != $which )
92 <div class="alignleft actions">
94 $dropdown_options = array(
95 'selected' => $cat_id,
97 'taxonomy' => 'link_category',
98 'show_option_all' => __( 'All categories' ),
105 echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>';
106 wp_dropdown_categories( $dropdown_options );
107 submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
117 public function get_columns() {
119 'cb' => '<input type="checkbox" />',
120 'name' => _x( 'Name', 'link name' ),
121 'url' => __( 'URL' ),
122 'categories' => __( 'Categories' ),
123 'rel' => __( 'Relationship' ),
124 'visible' => __( 'Visible' ),
125 'rating' => __( 'Rating' )
133 protected function get_sortable_columns() {
137 'visible' => 'visible',
143 * Get the name of the default primary column.
148 * @return string Name of the default primary column, in this case, 'name'.
150 protected function get_default_primary_column_name() {
155 * Handles the checkbox column ouput.
160 * @param object $link The current link object.
162 public function column_cb( $link ) {
164 <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
165 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
170 * Handles the link name column ouput.
175 * @param object $link The current link object.
177 public function column_name( $link ) {
178 $edit_link = get_edit_bookmark_link( $link );
180 <strong><a class="row-title" href="<?php echo $edit_link ?>" title="<?php
181 echo esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) );
182 ?>"><?php echo $link->link_name ?></a></strong><br />
187 * Handles the link URL column ouput.
192 * @param object $link The current link object.
194 public function column_url( $link ) {
195 $short_url = url_shorten( $link->link_url );
196 echo "<a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a>";
200 * Handles the link categories column output.
207 * @param object $link The current link object.
209 public function column_categories( $link ) {
212 $cat_names = array();
213 foreach ( $link->link_category as $category ) {
214 $cat = get_term( $category, 'link_category', OBJECT, 'display' );
215 if ( is_wp_error( $cat ) ) {
216 echo $cat->get_error_message();
218 $cat_name = $cat->name;
219 if ( $cat_id != $category ) {
220 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
222 $cat_names[] = $cat_name;
224 echo implode( ', ', $cat_names );
228 * Handles the link relation column ouput.
233 * @param object $link The current link object.
235 public function column_rel( $link ) {
236 echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
240 * Handles the link visibility column ouput.
245 * @param object $link The current link object.
247 public function column_visible( $link ) {
248 if ( 'Y' === $link->link_visible ) {
256 * Handles the link rating column ouput.
261 * @param object $link The current link object.
263 public function column_rating( $link ) {
264 echo $link->link_rating;
268 * Handles the default column output.
273 * @param object $link Link object.
274 * @param string $column_name Current column name.
276 public function column_default( $link, $column_name ) {
278 * Fires for each registered custom link column.
282 * @param string $column_name Name of the custom column.
283 * @param int $link_id Link ID.
285 do_action( 'manage_link_custom_column', $column_name, $link->link_id );
288 public function display_rows() {
289 foreach ( $this->items as $link ) {
290 $link = sanitize_bookmark( $link );
291 $link->link_name = esc_attr( $link->link_name );
292 $link->link_category = wp_get_link_cats( $link->link_id );
294 <tr id="link-<?php echo $link->link_id; ?>">
295 <?php $this->single_row_columns( $link ) ?>
302 * Generates and displays row action links.
307 * @param object $link Link being acted upon.
308 * @param string $column_name Current column name.
309 * @param string $primary Primary column name.
310 * @return string Row action output for links.
312 protected function handle_row_actions( $link, $column_name, $primary ) {
313 if ( $primary !== $column_name ) {
317 $edit_link = get_edit_bookmark_link( $link );
320 $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
321 $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>";
322 return $this->row_actions( $actions );