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