[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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_Tsble
  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">' . __( 'Filter by category' ) . '</label>';
 118              wp_dropdown_categories( $dropdown_options );
 119              submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
 120          ?>
 121          </div>
 122          <?php
 123      }
 124  
 125      /**
 126       * @return array
 127       */
 128  	public function get_columns() {
 129          return array(
 130              'cb'         => '<input type="checkbox" />',
 131              'name'       => _x( 'Name', 'link name' ),
 132              'url'        => __( 'URL' ),
 133              'categories' => __( 'Categories' ),
 134              'rel'        => __( 'Relationship' ),
 135              'visible'    => __( 'Visible' ),
 136              'rating'     => __( 'Rating' ),
 137          );
 138      }
 139  
 140      /**
 141       * @return array
 142       */
 143  	protected function get_sortable_columns() {
 144          return array(
 145              'name'    => 'name',
 146              'url'     => 'url',
 147              'visible' => 'visible',
 148              'rating'  => 'rating',
 149          );
 150      }
 151  
 152      /**
 153       * Get the name of the default primary column.
 154       *
 155       * @since 4.3.0
 156       *
 157       * @return string Name of the default primary column, in this case, 'name'.
 158       */
 159  	protected function get_default_primary_column_name() {
 160          return 'name';
 161      }
 162  
 163      /**
 164       * Handles the checkbox column output.
 165       *
 166       * @since 4.3.0
 167       *
 168       * @param object $link The current link object.
 169       */
 170  	public function column_cb( $link ) {
 171          ?>
 172          <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>">
 173              <?php
 174              /* translators: %s: Link name. */
 175              printf( __( 'Select %s' ), $link->link_name );
 176              ?>
 177          </label>
 178          <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
 179          <?php
 180      }
 181  
 182      /**
 183       * Handles the link name column output.
 184       *
 185       * @since 4.3.0
 186       *
 187       * @param object $link The current link object.
 188       */
 189  	public function column_name( $link ) {
 190          $edit_link = get_edit_bookmark_link( $link );
 191          printf(
 192              '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',
 193              $edit_link,
 194              /* translators: %s: Link name. */
 195              esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ),
 196              $link->link_name
 197          );
 198      }
 199  
 200      /**
 201       * Handles the link URL column output.
 202       *
 203       * @since 4.3.0
 204       *
 205       * @param object $link The current link object.
 206       */
 207  	public function column_url( $link ) {
 208          $short_url = url_shorten( $link->link_url );
 209          echo "<a href='$link->link_url'>$short_url</a>";
 210      }
 211  
 212      /**
 213       * Handles the link categories column output.
 214       *
 215       * @since 4.3.0
 216       *
 217       * @global int $cat_id
 218       *
 219       * @param object $link The current link object.
 220       */
 221  	public function column_categories( $link ) {
 222          global $cat_id;
 223  
 224          $cat_names = array();
 225          foreach ( $link->link_category as $category ) {
 226              $cat = get_term( $category, 'link_category', OBJECT, 'display' );
 227              if ( is_wp_error( $cat ) ) {
 228                  echo $cat->get_error_message();
 229              }
 230              $cat_name = $cat->name;
 231              if ( (int) $cat_id !== $category ) {
 232                  $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
 233              }
 234              $cat_names[] = $cat_name;
 235          }
 236          echo implode( ', ', $cat_names );
 237      }
 238  
 239      /**
 240       * Handles the link relation column output.
 241       *
 242       * @since 4.3.0
 243       *
 244       * @param object $link The current link object.
 245       */
 246  	public function column_rel( $link ) {
 247          echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
 248      }
 249  
 250      /**
 251       * Handles the link visibility column output.
 252       *
 253       * @since 4.3.0
 254       *
 255       * @param object $link The current link object.
 256       */
 257  	public function column_visible( $link ) {
 258          if ( 'Y' === $link->link_visible ) {
 259              _e( 'Yes' );
 260          } else {
 261              _e( 'No' );
 262          }
 263      }
 264  
 265      /**
 266       * Handles the link rating column output.
 267       *
 268       * @since 4.3.0
 269       *
 270       * @param object $link The current link object.
 271       */
 272  	public function column_rating( $link ) {
 273          echo $link->link_rating;
 274      }
 275  
 276      /**
 277       * Handles the default column output.
 278       *
 279       * @since 4.3.0
 280       *
 281       * @param object $link        Link object.
 282       * @param string $column_name Current column name.
 283       */
 284  	public function column_default( $link, $column_name ) {
 285          /**
 286           * Fires for each registered custom link column.
 287           *
 288           * @since 2.1.0
 289           *
 290           * @param string $column_name Name of the custom column.
 291           * @param int    $link_id     Link ID.
 292           */
 293          do_action( 'manage_link_custom_column', $column_name, $link->link_id );
 294      }
 295  
 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 );
 301              ?>
 302          <tr id="link-<?php echo $link->link_id; ?>">
 303              <?php $this->single_row_columns( $link ); ?>
 304          </tr>
 305              <?php
 306          }
 307      }
 308  
 309      /**
 310       * Generates and displays row action links.
 311       *
 312       * @since 4.3.0
 313       *
 314       * @param object $link        Link being acted upon.
 315       * @param string $column_name Current column name.
 316       * @param string $primary     Primary column name.
 317       * @return string Row action output for links.
 318       */
 319  	protected function handle_row_actions( $link, $column_name, $primary ) {
 320          if ( $primary !== $column_name ) {
 321              return '';
 322          }
 323  
 324          $edit_link = get_edit_bookmark_link( $link );
 325  
 326          $actions           = array();
 327          $actions['edit']   = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
 328          $actions['delete'] = sprintf(
 329              '<a class="submitdelete" href="%s" onclick="return confirm( \'%s\' );">%s</a>',
 330              wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ),
 331              /* translators: %s: Link name. */
 332              esc_js( sprintf( __( "You are about to delete this link '%s'\n  'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ),
 333              __( 'Delete' )
 334          );
 335  
 336          return $this->row_actions( $actions );
 337      }
 338  }


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7