[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-wp-links-list-table.php (source)

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


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1