diff --git a/inc/admin/profile/namespace.php b/inc/admin/profile/namespace.php index 34f65cf..f097d3f 100644 --- a/inc/admin/profile/namespace.php +++ b/inc/admin/profile/namespace.php @@ -12,7 +12,8 @@ * Bootstrap actions for the profile screen. */ function bootstrap() { - add_action( 'personal_options', __NAMESPACE__ . '\\render_profile_section', 50 ); + add_action( 'show_user_profile', __NAMESPACE__ . '\\render_profile_section' ); + add_action( 'edit_user_profile', __NAMESPACE__ . '\\render_profile_section' ); add_action( 'all_admin_notices', __NAMESPACE__ . '\\output_profile_messages' ); add_action( 'personal_options_update', __NAMESPACE__ . '\\handle_revocation', 10, 1 ); add_action( 'edit_user_profile_update', __NAMESPACE__ . '\\handle_revocation', 10, 1 ); @@ -26,40 +27,87 @@ function bootstrap() { function render_profile_section( WP_User $user ) { $tokens = Access_Token::get_for_user( $user ); ?> - - +

+ +
+ - - + + + + +
- - - - - - - - - - - get_client(); - ?> - - - - - - -
get_name() ?> -
- -

- -
+ +

+ + get_client(); + + $creation_time = $token->get_creation_time(); + $details = [ + sprintf( + /* translators: %1$s: formatted date, %2$s: formatted time */ + esc_html__( 'Authorized %1$s at %2$s', 'oauth2' ), + date( get_option( 'date_format' ), $creation_time ), + date( get_option( 'time_format' ), $creation_time ) + ), + ]; + + /** + * Filter details shown for an access token on the profile screen. + * + * @param string[] $details List of HTML snippets to render in table. + * @param Access_Token $token Token being displayed. + * @param WP_User $user User whose profile is being rendered. + */ + $details = apply_filters( 'oauth2.admin.profile.render_token_row.details', $details, $token, $user ); + + // Build actions. + $button_title = sprintf( + /* translators: %s: app name */ + __( 'Revoke access for "%s"', 'oauth2' ), + $client->get_name() + ); + $actions = [ + sprintf( + '', + $button_title, + esc_attr( $token->get_key() ), + esc_html__( 'Revoke', 'oauth2' ) + ), + ]; + + /** + * Filter actions shown for an access token on the profile screen. + * + * @param string[] $actions List of HTML snippets to render in table. + * @param Access_Token $token Token being displayed. + * @param WP_User $user User whose profile is being rendered. + */ + $actions = apply_filters( 'oauth2.admin.profile.render_token_row.actions', $actions, $token, $user ); + ?> + + +

get_name() ?>

+

+ + + + + value['client'] ); } + /** + * Get creation time for the token. + * + * @return int Creation timestamp. + */ + public function get_creation_time() { + return $this->value['created']; + } + /** * Revoke the token. * @@ -116,7 +125,8 @@ public static function create( Client $client, WP_User $user ) { } $data = array( - 'client' => $client->get_id(), + 'client' => $client->get_id(), + 'created' => time(), ); $key = wp_generate_password( static::KEY_LENGTH, false ); $meta_key = static::META_PREFIX . $key;