[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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  
 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       *
 170       * @param object $link The current link object.
 171       */
 172  	public function column_cb( $link ) {
 173          ?>
 174          <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>">
 175              <?php
 176              /* translators: %s: Link name. */
 177              printf( __( 'Select %s' ), $link->link_name );
 178              ?>
 179          </label>
 180          <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
 181          <?php
 182      }
 183  
 184      /**
 185       * Handles the link name column output.
 186       *
 187       * @since 4.3.0
 188       *
 189       * @param object $link The current link object.
 190       */
 191  	public function column_name( $link ) {
 192          $edit_link = get_edit_bookmark_link( $link );
 193          printf(
 194              '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',
 195              $edit_link,
 196              /* translators: %s: Link name. */
 197              esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ),
 198              $link->link_name
 199          );
 200      }
 201  
 202      /**
 203       * Handles the link URL column output.
 204       *
 205       * @since 4.3.0
 206       *
 207       * @param object $link The current link object.
 208       */
 209  	public function column_url( $link ) {
 210          $short_url = url_shorten( $link->link_url );
 211          echo "<a href='$link->link_url'>$short_url</a>";
 212      }
 213  
 214      /**
 215       * Handles the link categories column output.
 216       *
 217       * @since 4.3.0
 218       *
 219       * @global int $cat_id
 220       *
 221       * @param object $link The current link object.
 222       */
 223  	public function column_categories( $link ) {
 224          global $cat_id;
 225  
 226          $cat_names = array();
 227          foreach ( $link->link_category as $category ) {
 228              $cat = get_term( $category, 'link_category', OBJECT, 'display' );
 229              if ( is_wp_error( $cat ) ) {
 230                  echo $cat->get_error_message();
 231              }
 232              $cat_name = $cat->name;
 233              if ( (int) $cat_id !== $category ) {
 234                  $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
 235              }
 236              $cat_names[] = $cat_name;
 237          }
 238          echo implode( ', ', $cat_names );
 239      }
 240  
 241      /**
 242       * Handles the link relation column output.
 243       *
 244       * @since 4.3.0
 245       *
 246       * @param object $link The current link object.
 247       */
 248  	public function column_rel( $link ) {
 249          echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
 250      }
 251  
 252      /**
 253       * Handles the link visibility column output.
 254       *
 255       * @since 4.3.0
 256       *
 257       * @param object $link The current link object.
 258       */
 259  	public function column_visible( $link ) {
 260          if ( 'Y' === $link->link_visible ) {
 261              _e( 'Yes' );
 262          } else {
 263              _e( 'No' );
 264          }
 265      }
 266  
 267      /**
 268       * Handles the link rating column output.
 269       *
 270       * @since 4.3.0
 271       *
 272       * @param object $link The current link object.
 273       */
 274  	public function column_rating( $link ) {
 275          echo $link->link_rating;
 276      }
 277  
 278      /**
 279       * Handles the default column output.
 280       *
 281       * @since 4.3.0
 282       *
 283       * @param object $link        Link object.
 284       * @param string $column_name Current column name.
 285       */
 286  	public function column_default( $link, $column_name ) {
 287          /**
 288           * Fires for each registered custom link column.
 289           *
 290           * @since 2.1.0
 291           *
 292           * @param string $column_name Name of the custom column.
 293           * @param int    $link_id     Link ID.
 294           */
 295          do_action( 'manage_link_custom_column', $column_name, $link->link_id );
 296      }
 297  
 298  	public function display_rows() {
 299          foreach ( $this->items as $link ) {
 300              $link                = sanitize_bookmark( $link );
 301              $link->link_name     = esc_attr( $link->link_name );
 302              $link->link_category = wp_get_link_cats( $link->link_id );
 303              ?>
 304          <tr id="link-<?php echo $link->link_id; ?>">
 305              <?php $this->single_row_columns( $link ); ?>
 306          </tr>
 307              <?php
 308          }
 309      }
 310  
 311      /**
 312       * Generates and displays row action links.
 313       *
 314       * @since 4.3.0
 315       *
 316       * @param object $link        Link being acted upon.
 317       * @param string $column_name Current column name.
 318       * @param string $primary     Primary column name.
 319       * @return string Row actions output for links, or an empty string
 320       *                if the current column is not the primary column.
 321       */
 322  	protected function handle_row_actions( $link, $column_name, $primary ) {
 323          if ( $primary !== $column_name ) {
 324              return '';
 325          }
 326  
 327          $edit_link = get_edit_bookmark_link( $link );
 328  
 329          $actions           = array();
 330          $actions['edit']   = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
 331          $actions['delete'] = sprintf(
 332              '<a class="submitdelete" href="%s" onclick="return confirm( \'%s\' );">%s</a>',
 333              wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ),
 334              /* translators: %s: Link name. */
 335              esc_js( sprintf( __( "You are about to delete this link '%s'\n  'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ),
 336              __( 'Delete' )
 337          );
 338  
 339          return $this->row_actions( $actions );
 340      }
 341  }


Generated : Mon Oct 26 08:20:01 2020 Cross-referenced by PHPXref