[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * List Table API: WP_Application_Passwords_List_Table class
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   * @since 5.6.0
   8   */
   9  
  10  /**
  11   * Class for displaying the list of application password items.
  12   *
  13   * @since 5.6.0
  14   * @access private
  15   *
  16   * @see WP_List_Table
  17   */
  18  class WP_Application_Passwords_List_Table extends WP_List_Table {
  19  
  20      /**
  21       * Gets the list of columns.
  22       *
  23       * @since 5.6.0
  24       *
  25       * @return array
  26       */
  27  	public function get_columns() {
  28          return array(
  29              'name'      => __( 'Name' ),
  30              'created'   => __( 'Created' ),
  31              'last_used' => __( 'Last Used' ),
  32              'last_ip'   => __( 'Last IP' ),
  33              'revoke'    => __( 'Revoke' ),
  34          );
  35      }
  36  
  37      /**
  38       * Prepares the list of items for displaying.
  39       *
  40       * @since 5.6.0
  41       *
  42       * @global int $user_id User ID.
  43       */
  44  	public function prepare_items() {
  45          global $user_id;
  46          $this->items = array_reverse( WP_Application_Passwords::get_user_application_passwords( $user_id ) );
  47      }
  48  
  49      /**
  50       * Handles the name column output.
  51       *
  52       * @since 5.6.0
  53       *
  54       * @param array $item The current application password item.
  55       */
  56  	public function column_name( $item ) {
  57          echo esc_html( $item['name'] );
  58      }
  59  
  60      /**
  61       * Handles the created column output.
  62       *
  63       * @since 5.6.0
  64       *
  65       * @param array $item The current application password item.
  66       */
  67  	public function column_created( $item ) {
  68          if ( empty( $item['created'] ) ) {
  69              echo '&mdash;';
  70          } else {
  71              echo gmdate( get_option( 'date_format', 'r' ), $item['created'] );
  72          }
  73      }
  74  
  75      /**
  76       * Handles the last used column output.
  77       *
  78       * @since 5.6.0
  79       *
  80       * @param array $item The current application password item.
  81       */
  82  	public function column_last_used( $item ) {
  83          if ( empty( $item['last_used'] ) ) {
  84              echo '&mdash;';
  85          } else {
  86              echo gmdate( get_option( 'date_format', 'r' ), $item['last_used'] );
  87          }
  88      }
  89  
  90      /**
  91       * Handles the last ip column output.
  92       *
  93       * @since 5.6.0
  94       *
  95       * @param array $item The current application password item.
  96       */
  97  	public function column_last_ip( $item ) {
  98          if ( empty( $item['last_ip'] ) ) {
  99              echo '&mdash;';
 100          } else {
 101              echo $item['last_ip'];
 102          }
 103      }
 104  
 105      /**
 106       * Handles the revoke column output.
 107       *
 108       * @since 5.6.0
 109       *
 110       * @param array $item The current application password item.
 111       */
 112  	public function column_revoke( $item ) {
 113          submit_button(
 114              __( 'Revoke' ),
 115              'delete',
 116              'revoke-application-password-' . $item['uuid'],
 117              false,
 118              array(
 119                  /* translators: %s: the application password's given name. */
 120                  'aria-label' => sprintf( __( 'Revoke "%s"' ), $item['name'] ),
 121              )
 122          );
 123      }
 124  
 125      /**
 126       * Generates content for a single row of the table
 127       *
 128       * @since 5.6.0
 129       *
 130       * @param array  $item        The current item.
 131       * @param string $column_name The current column name.
 132       */
 133  	protected function column_default( $item, $column_name ) {
 134          /**
 135           * Fires for each custom column in the Application Passwords list table.
 136           *
 137           * Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter.
 138           *
 139           * @since 5.6.0
 140           *
 141           * @param string $column_name Name of the custom column.
 142           * @param array  $item        The application password item.
 143           */
 144          do_action( "manage_{$this->screen->id}_custom_column", $column_name, $item );
 145      }
 146  
 147      /**
 148       * Generates custom table navigation to prevent conflicting nonces.
 149       *
 150       * @since 5.6.0
 151       *
 152       * @param string $which The location of the bulk actions: 'top' or 'bottom'.
 153       */
 154  	protected function display_tablenav( $which ) {
 155          ?>
 156          <div class="tablenav <?php echo esc_attr( $which ); ?>">
 157              <?php if ( 'bottom' === $which ) : ?>
 158                  <div class="alignright">
 159                      <?php submit_button( __( 'Revoke all application passwords' ), 'delete', 'revoke-all-application-passwords', false ); ?>
 160                  </div>
 161              <?php endif; ?>
 162              <div class="alignleft actions bulkactions">
 163                  <?php $this->bulk_actions( $which ); ?>
 164              </div>
 165              <?php
 166              $this->extra_tablenav( $which );
 167              $this->pagination( $which );
 168              ?>
 169              <br class="clear" />
 170          </div>
 171          <?php
 172      }
 173  
 174      /**
 175       * Generates content for a single row of the table.
 176       *
 177       * @since 5.6.0
 178       *
 179       * @param array $item The current item.
 180       */
 181  	public function single_row( $item ) {
 182          echo '<tr data-uuid="' . esc_attr( $item['uuid'] ) . '">';
 183          $this->single_row_columns( $item );
 184          echo '</tr>';
 185      }
 186  
 187      /**
 188       * Gets the name of the default primary column.
 189       *
 190       * @since 5.6.0
 191       *
 192       * @return string Name of the default primary column, in this case, 'name'.
 193       */
 194  	protected function get_default_primary_column_name() {
 195          return 'name';
 196      }
 197  
 198      /**
 199       * Prints the JavaScript template for the new row item.
 200       *
 201       * @since 5.6.0
 202       */
 203  	public function print_js_template_row() {
 204          list( $columns, $hidden, , $primary ) = $this->get_column_info();
 205  
 206          echo '<tr data-uuid="{{ data.uuid }}">';
 207  
 208          foreach ( $columns as $column_name => $display_name ) {
 209              $is_primary = $primary === $column_name;
 210              $classes    = "{$column_name} column-{$column_name}";
 211  
 212              if ( $is_primary ) {
 213                  $classes .= ' has-row-actions column-primary';
 214              }
 215  
 216              if ( in_array( $column_name, $hidden, true ) ) {
 217                  $classes .= ' hidden';
 218              }
 219  
 220              printf( '<td class="%s" data-colname="%s">', esc_attr( $classes ), esc_attr( wp_strip_all_tags( $display_name ) ) );
 221  
 222              switch ( $column_name ) {
 223                  case 'name':
 224                      echo '{{ data.name }}';
 225                      break;
 226                  case 'created':
 227                      echo "<# print( wp.date.dateI18n( '" . esc_js( get_option( 'date_format' ) ) . "', data.created ) ) #>";
 228                      break;
 229                  case 'last_used':
 230                      echo "<# print( data.last_used !== null ? wp.date.dateI18n( '" . esc_js( get_option( 'date_format' ) ) . "', data.last_used ) : '—' ) #>";
 231                      break;
 232                  case 'last_ip':
 233                      echo "{{ data.last_ip || '—' }}";
 234                      break;
 235                  case 'revoke':
 236                      printf(
 237                          '<input type="submit" class="button delete" value="%1$s" aria-label="%2$s">',
 238                          esc_attr( __( 'Revoke' ) ),
 239                          /* translators: %s: the application password's given name. */
 240                          esc_attr( sprintf( __( 'Revoke "%s"' ), '{{ data.name }}' ) )
 241                      );
 242                      break;
 243                  default:
 244                      /**
 245                       * Fires in the JavaScript row template for each custom column in the Application Passwords list table.
 246                       *
 247                       * Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter.
 248                       *
 249                       * @since 5.6.0
 250                       *
 251                       * @param string $column_name Name of the custom column.
 252                       */
 253                      do_action( "manage_{$this->screen->id}_custom_column_js_template", $column_name );
 254                      break;
 255              }
 256  
 257              if ( $is_primary ) {
 258                  echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
 259              }
 260  
 261              echo '</td>';
 262          }
 263  
 264          echo '</tr>';
 265      }
 266  }


Generated: Thu Dec 3 01:00:04 2020 Cross-referenced by PHPXref 0.7.1