| [ 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 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 // The primary column is a `<th scope="row">` row header, matching the 218 // server-rendered markup in WP_List_Table::single_row_columns(). 219 $tag = $is_primary ? 'th' : 'td'; 220 $scope = $is_primary ? ' scope="row"' : ''; 221 222 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 ); 223 224 switch ( $column_name ) { 225 case 'name': 226 echo '{{ data.name }}'; 227 break; 228 case 'created': 229 // JSON encoding automatically doubles backslashes to ensure they don't get lost when printing the inline JS. 230 echo '<# print( wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ', data.created ) ) #>'; 231 break; 232 case 'last_used': 233 echo '<# print( data.last_used !== null ? wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ", data.last_used ) : '—' ) #>"; 234 break; 235 case 'last_ip': 236 echo "{{ data.last_ip || '—' }}"; 237 break; 238 case 'revoke': 239 printf( 240 '<button type="button" class="button delete" aria-label="%1$s">%2$s</button>', 241 /* translators: %s: the application password's given name. */ 242 esc_attr( sprintf( __( 'Revoke "%s"' ), '{{ data.name }}' ) ), 243 esc_html__( 'Revoke' ) 244 ); 245 break; 246 default: 247 /** 248 * Fires in the JavaScript row template for each custom column in the Application Passwords list table. 249 * 250 * Custom columns are registered using the {@see 'manage_application-passwords-user_columns'} filter. 251 * 252 * @since 5.6.0 253 * 254 * @param string $column_name Name of the custom column. 255 */ 256 do_action( "manage_{$this->screen->id}_custom_column_js_template", $column_name ); 257 break; 258 } 259 260 if ( $is_primary ) { 261 echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . 262 /* translators: Hidden accessibility text. */ 263 __( 'Show more details' ) . 264 '</span></button>'; 265 } 266 267 echo "</{$tag}>"; 268 } 269 270 echo '</tr>'; 271 } 272 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Sep 19 08:20:30 2026 | Cross-referenced by PHPXref |