| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 '—'; 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 '—'; 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 '—'; 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 * @phpstan-param 'top'|'bottom' $which 152 */ 153 protected function display_tablenav( $which ) { 154 ?> 155 <div class="tablenav <?php echo esc_attr( $which ); ?>"> 156 <?php if ( 'bottom' === $which ) : ?> 157 <div class="alignright"> 158 <button type="button" name="revoke-all-application-passwords" id="revoke-all-application-passwords" class="button delete"><?php _e( 'Revoke all application passwords' ); ?></button> 159 </div> 160 <?php endif; ?> 161 <div class="alignleft actions bulkactions"> 162 <?php $this->bulk_actions( $which ); ?> 163 </div> 164 <?php 165 $this->extra_tablenav( $which ); 166 $this->pagination( $which ); 167 ?> 168 <br class="clear" /> 169 </div> 170 <?php 171 } 172 173 /** 174 * Generates content for a single row of the table. 175 * 176 * @since 5.6.0 177 * 178 * @param array $item The current item. 179 */ 180 public function single_row( $item ) { 181 echo '<tr data-uuid="' . esc_attr( $item['uuid'] ) . '">'; 182 $this->single_row_columns( $item ); 183 echo '</tr>'; 184 } 185 186 /** 187 * Gets the name of the default primary column. 188 * 189 * @since 5.6.0 190 * 191 * @return string Name of the default primary column, in this case, 'name'. 192 */ 193 protected function get_default_primary_column_name() { 194 return 'name'; 195 } 196 197 /** 198 * Prints the JavaScript template for the new row item. 199 * 200 * @since 5.6.0 201 */ 202 public function print_js_template_row() { 203 list( $columns, $hidden, , $primary ) = $this->get_column_info(); 204 205 echo '<tr data-uuid="{{ data.uuid }}">'; 206 207 foreach ( $columns as $column_name => $display_name ) { 208 $is_primary = $primary === $column_name; 209 $classes = "{$column_name} column-{$column_name}"; 210 211 if ( $is_primary ) { 212 $classes .= ' has-row-actions column-primary'; 213 } 214 215 if ( in_array( $column_name, $hidden, true ) ) { 216 $classes .= ' hidden'; 217 } 218 219 // The primary column is a `<th scope="row">` row header, matching the 220 // server-rendered markup in WP_List_Table::single_row_columns(). 221 $tag = $is_primary ? 'th' : 'td'; 222 $scope = $is_primary ? ' scope="row"' : ''; 223 224 printf( '<%1$s class="%2$s" data-colname="%3$s"%4$s>', $tag, esc_attr( $classes ), esc_attr( wp_strip_all_tags( $display_name ) ), $scope ); 225 226 switch ( $column_name ) { 227 case 'name': 228 echo '{{ data.name }}'; 229 break; 230 case 'created': 231 // JSON encoding automatically doubles backslashes to ensure they don't get lost when printing the inline JS. 232 echo '<# print( wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ', data.created ) ) #>'; 233 break; 234 case 'last_used': 235 echo '<# print( data.last_used !== null ? wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ", data.last_used ) : '—' ) #>"; 236 break; 237 case 'last_ip': 238 echo "{{ data.last_ip || '—' }}"; 239 break; 240 case 'revoke': 241 printf( 242 '<button type="button" class="button delete" aria-label="%1$s">%2$s</button>', 243 /* translators: %s: the application password's given name. */ 244 esc_attr( sprintf( __( 'Revoke "%s"' ), '{{ data.name }}' ) ), 245 esc_html__( 'Revoke' ) 246 ); 247 break; 248 default: 249 /** 250 * Fires in the JavaScript row template for each custom column in the Application Passwords list table. 251 * 252 * Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter. 253 * 254 * @since 5.6.0 255 * 256 * @param string $column_name Name of the custom column. 257 */ 258 do_action( "manage_{$this->screen->id}_custom_column_js_template", $column_name ); 259 break; 260 } 261 262 if ( $is_primary ) { 263 echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . 264 /* translators: Hidden accessibility text. */ 265 __( 'Show more details' ) . 266 '</span></button>'; 267 } 268 269 echo "</{$tag}>"; 270 } 271 272 echo '</tr>'; 273 } 274 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Oct 19 08:20:34 2026 | Cross-referenced by PHPXref |