[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * List Table API: WP_Links_List_Table class 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 3.1.0 8 */ 9 10 /** 11 * Core class used to implement displaying links in a list table. 12 * 13 * @since 3.1.0 14 * 15 * @see WP_List_Table 16 */ 17 class WP_Links_List_Table extends WP_List_Table { 18 19 /** 20 * Constructor. 21 * 22 * @since 3.1.0 23 * 24 * @see WP_List_Table::__construct() for more information on default arguments. 25 * 26 * @param array $args An associative array of arguments. 27 */ 28 public function __construct( $args = array() ) { 29 parent::__construct( 30 array( 31 'plural' => 'bookmarks', 32 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 33 ) 34 ); 35 } 36 37 /** 38 * @return bool 39 */ 40 public function ajax_user_can() { 41 return current_user_can( 'manage_links' ); 42 } 43 44 /** 45 * @global int $cat_id 46 * @global string $s 47 * @global string $orderby 48 * @global string $order 49 */ 50 public function prepare_items() { 51 global $cat_id, $s, $orderby, $order; 52 53 wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) ); 54 55 $args = array( 56 'hide_invisible' => 0, 57 'hide_empty' => 0, 58 ); 59 60 if ( 'all' !== $cat_id ) { 61 $args['category'] = $cat_id; 62 } 63 if ( ! empty( $s ) ) { 64 $args['search'] = $s; 65 } 66 if ( ! empty( $orderby ) ) { 67 $args['orderby'] = $orderby; 68 } 69 if ( ! empty( $order ) ) { 70 $args['order'] = $order; 71 } 72 73 $this->items = get_bookmarks( $args ); 74 } 75 76 /** 77 */ 78 public function no_items() { 79 _e( 'No links found.' ); 80 } 81 82 /** 83 * @return array 84 */ 85 protected function get_bulk_actions() { 86 $actions = array(); 87 $actions['delete'] = __( 'Delete' ); 88 89 return $actions; 90 } 91 92 /** 93 * @global int $cat_id 94 * @param string $which 95 */ 96 protected function extra_tablenav( $which ) { 97 global $cat_id; 98 99 if ( 'top' !== $which ) { 100 return; 101 } 102 ?> 103 <div class="alignleft actions"> 104 <?php 105 $dropdown_options = array( 106 'selected' => $cat_id, 107 'name' => 'cat_id', 108 'taxonomy' => 'link_category', 109 'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items, 110 'hide_empty' => true, 111 'hierarchical' => 1, 112 'show_count' => 0, 113 'orderby' => 'name', 114 ); 115 116 echo '<label class="screen-reader-text" for="cat_id">' . get_taxonomy( 'link_category' )->labels->filter_by_item . '</label>'; 117 118 wp_dropdown_categories( $dropdown_options ); 119 120 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 121 ?> 122 </div> 123 <?php 124 } 125 126 /** 127 * @return string[] Array of column titles keyed by their column name. 128 */ 129 public function get_columns() { 130 return array( 131 'cb' => '<input type="checkbox" />', 132 'name' => _x( 'Name', 'link name' ), 133 'url' => __( 'URL' ), 134 'categories' => __( 'Categories' ), 135 'rel' => __( 'Relationship' ), 136 'visible' => __( 'Visible' ), 137 'rating' => __( 'Rating' ), 138 ); 139 } 140 141 /** 142 * @return array 143 */ 144 protected function get_sortable_columns() { 145 return array( 146 'name' => array( 'name', false, _x( 'Name', 'link name' ), __( 'Table ordered by Name.' ), 'asc' ), 147 'url' => array( 'url', false, __( 'URL' ), __( 'Table ordered by URL.' ) ), 148 'visible' => array( 'visible', false, __( 'Visible' ), __( 'Table ordered by Visibility.' ) ), 149 'rating' => array( 'rating', false, __( 'Rating' ), __( 'Table ordered by Rating.' ) ), 150 ); 151 } 152 153 /** 154 * Gets the name of the default primary column. 155 * 156 * @since 4.3.0 157 * 158 * @return string Name of the default primary column, in this case, 'name'. 159 */ 160 protected function get_default_primary_column_name() { 161 return 'name'; 162 } 163 164 /** 165 * Handles the checkbox column output. 166 * 167 * @since 4.3.0 168 * @since 5.9.0 Renamed `$link` to `$item` to match parent class for PHP 8 named parameter support. 169 * 170 * @param object $item The current link object. 171 */ 172 public function column_cb( $item ) { 173 // Restores the more descriptive, specific name for use within this method. 174 $link = $item; 175 176 ?> 177 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" /> 178 <label for="cb-select-<?php echo $link->link_id; ?>"> 179 <span class="screen-reader-text"> 180 <?php 181 /* translators: Hidden accessibility text. %s: Link name. */ 182 printf( __( 'Select %s' ), $link->link_name ); 183 ?> 184 </span> 185 </label> 186 <?php 187 } 188 189 /** 190 * Handles the link name column output. 191 * 192 * @since 4.3.0 193 * 194 * @param object $link The current link object. 195 */ 196 public function column_name( $link ) { 197 $edit_link = get_edit_bookmark_link( $link ); 198 printf( 199 '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>', 200 $edit_link, 201 /* translators: %s: Link name. */ 202 esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ), 203 $link->link_name 204 ); 205 } 206 207 /** 208 * Handles the link URL column output. 209 * 210 * @since 4.3.0 211 * 212 * @param object $link The current link object. 213 */ 214 public function column_url( $link ) { 215 $short_url = url_shorten( $link->link_url ); 216 echo "<a href='$link->link_url'>$short_url</a>"; 217 } 218 219 /** 220 * Handles the link categories column output. 221 * 222 * @since 4.3.0 223 * 224 * @global int $cat_id 225 * 226 * @param object $link The current link object. 227 */ 228 public function column_categories( $link ) { 229 global $cat_id; 230 231 $cat_names = array(); 232 foreach ( $link->link_category as $category ) { 233 $cat = get_term( $category, 'link_category', OBJECT, 'display' ); 234 if ( is_wp_error( $cat ) ) { 235 echo $cat->get_error_message(); 236 } 237 $cat_name = $cat->name; 238 if ( (int) $cat_id !== $category ) { 239 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>"; 240 } 241 $cat_names[] = $cat_name; 242 } 243 echo implode( ', ', $cat_names ); 244 } 245 246 /** 247 * Handles the link relation column output. 248 * 249 * @since 4.3.0 250 * 251 * @param object $link The current link object. 252 */ 253 public function column_rel( $link ) { 254 echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; 255 } 256 257 /** 258 * Handles the link visibility column output. 259 * 260 * @since 4.3.0 261 * 262 * @param object $link The current link object. 263 */ 264 public function column_visible( $link ) { 265 if ( 'Y' === $link->link_visible ) { 266 _e( 'Yes' ); 267 } else { 268 _e( 'No' ); 269 } 270 } 271 272 /** 273 * Handles the link rating column output. 274 * 275 * @since 4.3.0 276 * 277 * @param object $link The current link object. 278 */ 279 public function column_rating( $link ) { 280 echo $link->link_rating; 281 } 282 283 /** 284 * Handles the default column output. 285 * 286 * @since 4.3.0 287 * @since 5.9.0 Renamed `$link` to `$item` to match parent class for PHP 8 named parameter support. 288 * 289 * @param object $item Link object. 290 * @param string $column_name Current column name. 291 */ 292 public function column_default( $item, $column_name ) { 293 // Restores the more descriptive, specific name for use within this method. 294 $link = $item; 295 296 /** 297 * Fires for each registered custom link column. 298 * 299 * @since 2.1.0 300 * 301 * @param string $column_name Name of the custom column. 302 * @param int $link_id Link ID. 303 */ 304 do_action( 'manage_link_custom_column', $column_name, $link->link_id ); 305 } 306 307 public function display_rows() { 308 foreach ( $this->items as $link ) { 309 $link = sanitize_bookmark( $link ); 310 $link->link_name = esc_attr( $link->link_name ); 311 $link->link_category = wp_get_link_cats( $link->link_id ); 312 ?> 313 <tr id="link-<?php echo $link->link_id; ?>"> 314 <?php $this->single_row_columns( $link ); ?> 315 </tr> 316 <?php 317 } 318 } 319 320 /** 321 * Generates and displays row action links. 322 * 323 * @since 4.3.0 324 * @since 5.9.0 Renamed `$link` to `$item` to match parent class for PHP 8 named parameter support. 325 * 326 * @param object $item Link being acted upon. 327 * @param string $column_name Current column name. 328 * @param string $primary Primary column name. 329 * @return string Row actions output for links, or an empty string 330 * if the current column is not the primary column. 331 */ 332 protected function handle_row_actions( $item, $column_name, $primary ) { 333 if ( $primary !== $column_name ) { 334 return ''; 335 } 336 337 // Restores the more descriptive, specific name for use within this method. 338 $link = $item; 339 340 $edit_link = get_edit_bookmark_link( $link ); 341 342 $actions = array(); 343 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 344 $actions['delete'] = sprintf( 345 '<a class="submitdelete" href="%s" onclick="return confirm( \'%s\' );">%s</a>', 346 wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ), 347 /* translators: %s: Link name. */ 348 esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), 349 __( 'Delete' ) 350 ); 351 352 return $this->row_actions( $actions ); 353 } 354 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Apr 27 08:20:02 2024 | Cross-referenced by PHPXref |