- Timestamp:
- 12/04/2020 09:42:52 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/authorize-application.php
r49617 r49752 86 86 __( 'The Authorize Application request is not allowed.' ) . ' ' . implode( ' ', $is_valid->get_error_messages() ), 87 87 __( 'Cannot Authorize Application' ) 88 ); 89 } 90 91 if ( ! empty( $_SERVER['PHP_AUTH_USER'] ) || ! empty( $_SERVER['PHP_AUTH_PW'] ) ) { 92 wp_die( 93 __( 'Your website appears to use Basic Authentication, which is not currently compatible with Application Passwords.' ), 94 __( 'Cannot Authorize Application' ), 95 array( 96 'response' => 501, 97 'link_text' => __( 'Go Back' ), 98 'link_url' => $reject_url ? add_query_arg( 'error', 'disabled', $reject_url ) : admin_url(), 99 ) 88 100 ); 89 101 } -
trunk/src/wp-admin/includes/upgrade.php
r49744 r49752 875 875 } 876 876 877 if ( $wp_current_db_version < 497 35) {877 if ( $wp_current_db_version < 49752 ) { 878 878 upgrade_560(); 879 879 } … … 2279 2279 delete_transient( 'dirsize_cache' ); 2280 2280 } 2281 2282 if ( $wp_current_db_version < 49752 ) { 2283 $results = $wpdb->get_results( 2284 $wpdb->prepare( 2285 "SELECT 1 FROM {$wpdb->usermeta} WHERE meta_key = %s LIMIT 1", 2286 WP_Application_Passwords::USERMETA_KEY_APPLICATION_PASSWORDS 2287 ) 2288 ); 2289 2290 if ( ! empty( $results ) ) { 2291 update_site_option( WP_Application_Passwords::OPTION_KEY_IN_USE, 1 ); 2292 } 2293 } 2281 2294 } 2282 2295 -
trunk/src/wp-admin/user-edit.php
r49573 r49752 739 739 } 740 740 } 741 ?> 742 <div class="create-application-password form-wrap"> 743 <div class="form-field"> 744 <label for="new_application_password_name"><?php _e( 'New Application Password Name' ); ?></label> 745 <input type="text" size="30" id="new_application_password_name" name="new_application_password_name" placeholder="<?php esc_attr_e( 'WordPress App on My Phone' ); ?>" class="input" aria-required="true" aria-describedby="new_application_password_name_desc" /> 746 <p class="description" id="new_application_password_name_desc"><?php _e( 'Required to create an Application Password, but not to update the user.' ); ?></p> 741 742 if ( empty( $_SERVER['PHP_AUTH_USER'] ) && empty( $_SERVER['PHP_AUTH_PW'] ) ) { 743 ?> 744 <div class="create-application-password form-wrap"> 745 <div class="form-field"> 746 <label for="new_application_password_name"><?php _e( 'New Application Password Name' ); ?></label> 747 <input type="text" size="30" id="new_application_password_name" name="new_application_password_name" placeholder="<?php esc_attr_e( 'WordPress App on My Phone' ); ?>" class="input" aria-required="true" aria-describedby="new_application_password_name_desc" /> 748 <p class="description" id="new_application_password_name_desc"><?php _e( 'Required to create an Application Password, but not to update the user.' ); ?></p> 749 </div> 750 751 <?php 752 /** 753 * Fires in the create Application Passwords form. 754 * 755 * @since 5.6.0 756 * 757 * @param WP_User $profileuser The current WP_User object. 758 */ 759 do_action( 'wp_create_application_password_form', $profileuser ); 760 ?> 761 762 <?php submit_button( __( 'Add New Application Password' ), 'secondary', 'do_new_application_password' ); ?> 747 763 </div> 748 749 <?php 750 /** 751 * Fires in the create Application Passwords form. 752 * 753 * @since 5.6.0 754 * 755 * @param WP_User $profileuser The current WP_User object. 756 */ 757 do_action( 'wp_create_application_password_form', $profileuser ); 758 ?> 759 760 <?php submit_button( __( 'Add New Application Password' ), 'secondary', 'do_new_application_password' ); ?> 761 </div> 764 <?php } else { ?> 765 <div class="notice notice-error inline"> 766 <p><?php _e( 'Your website appears to use Basic Authentication, which is not currently compatible with Application Passwords.' ); ?></p> 767 </div> 768 <?php } ?> 762 769 763 770 <div class="application-passwords-list-table-wrapper"> -
trunk/src/wp-includes/class-wp-application-passwords.php
r49739 r49752 24 24 25 25 /** 26 * The option name used to store whether application passwords is in use. 27 * 28 * @since 5.6.0 29 * 30 * @type string 31 */ 32 const OPTION_KEY_IN_USE = 'using_application_passwords'; 33 34 /** 26 35 * The generated application password length. 27 36 * … … 31 40 */ 32 41 const PW_LENGTH = 24; 42 43 /** 44 * Checks if Application Passwords are being used by the site. 45 * 46 * This returns true if at least one App Password has ever been created. 47 * 48 * @since 5.6.0 49 * 50 * @return bool 51 */ 52 public static function is_in_use() { 53 return (bool) get_site_option( self::OPTION_KEY_IN_USE ); 54 } 33 55 34 56 /** … … 66 88 if ( ! $saved ) { 67 89 return new WP_Error( 'db_error', __( 'Could not save application password.' ) ); 90 } 91 92 if ( ! get_site_option( self::OPTION_KEY_IN_USE ) ) { 93 update_site_option( self::OPTION_KEY_IN_USE, true ); 68 94 } 69 95 -
trunk/src/wp-includes/user.php
r49693 r49752 311 311 function wp_authenticate_application_password( $input_user, $username, $password ) { 312 312 if ( $input_user instanceof WP_User ) { 313 return $input_user; 314 } 315 316 if ( ! WP_Application_Passwords::is_in_use() ) { 313 317 return $input_user; 314 318 } -
trunk/src/wp-includes/version.php
r49744 r49752 21 21 * @global int $wp_db_version 22 22 */ 23 $wp_db_version = 497 35;23 $wp_db_version = 49752; 24 24 25 25 /** -
trunk/tests/phpunit/tests/auth.php
r49617 r49752 38 38 $this->user = clone self::$_user; 39 39 wp_set_current_user( self::$user_id ); 40 update_site_option( 'using_application_passwords', 1 ); 40 41 } 41 42 … … 605 606 $this->assertSame( self::$user_id, $user->ID ); 606 607 } 608 609 /** 610 * @ticket 51939 611 */ 612 public function test_authenticate_application_password_returns_null_if_not_in_use() { 613 delete_site_option( 'using_application_passwords' ); 614 615 $authenticated = wp_authenticate_application_password( null, 'idonotexist', 'password' ); 616 $this->assertNull( $authenticated ); 617 } 607 618 } -
trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
r49617 r49752 406 406 407 407 /** 408 * @ticket 51939 409 */ 410 public function test_create_item_records_app_passwords_in_use() { 411 wp_set_current_user( self::$admin ); 412 413 $this->assertFalse( WP_Application_Passwords::is_in_use() ); 414 415 $request = new WP_REST_Request( 'POST', '/wp/v2/users/me/application-passwords' ); 416 $request->set_body_params( array( 'name' => 'App' ) ); 417 $response = rest_do_request( $request ); 418 419 $this->assertSame( 201, $response->get_status() ); 420 $this->assertTrue( WP_Application_Passwords::is_in_use() ); 421 } 422 423 /** 408 424 * @ticket 42790 409 425 */
Note: See TracChangeset
for help on using the changeset viewer.