[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref