Make WordPress Core

Ticket #53658: 53658.4.diff

File 53658.4.diff, 3.8 KB (added by felipeelia, 3 years ago)
  • src/wp-admin/user-edit.php

    diff --git a/src/wp-admin/user-edit.php b/src/wp-admin/user-edit.php
    index 813c5eb5cd..de30bba4cb 100644
    a b endif; 
    733733
    734734        </table>
    735735
     736<?php if ( wp_is_application_passwords_available_for_user( $user_id ) || ! wp_is_application_passwords_supported() ) : ?>
    736737        <div class="application-passwords hide-if-no-js" id="application-passwords-section">
    737738                <h2><?php _e( 'Application Passwords' ); ?></h2>
    738739                <p><?php _e( 'Application passwords allow authentication via non-interactive systems, such as XML-RPC or the REST API, without providing your actual password. Application passwords can be easily revoked. They cannot be used for traditional logins to your website.' ); ?></p>
    endif; 
    797798                        ?>
    798799                </div>
    799800                <?php else : ?>
    800                         <p><?php _e( 'The application password feature requires HTTPS, which is not enabled on this site.' ); ?></p>
     801                        <p><?php _e( 'The application password feature requires HTTPS - which is not enabled on this site - or the environment type set as local.' ); ?></p>
    801802                        <p>
    802803                                <?php
    803804                                printf(
    endif; 
    809810                        </p>
    810811                <?php endif; ?>
    811812        </div>
     813<?php endif; ?>
    812814
    813815                <?php
    814816                if ( IS_PROFILE_PAGE ) {
  • src/wp-includes/user.php

    diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
    index 3604d94389..5b4624bc0a 100644
    a b function wp_get_user_request( $request_id ) { 
    46574657        return new WP_User_Request( $post );
    46584658}
    46594659
     4660/**
     4661 * Checks if Application Passwords is supported.
     4662 *
     4663 * Application Passwords is supported only by sites using SSL or local environments
     4664 * but may be made available using the {@see 'wp_is_application_passwords_available'} filter.
     4665 *
     4666 * @since 5.9.0
     4667 *
     4668 * @return bool
     4669 */
     4670function wp_is_application_passwords_supported() {
     4671        return is_ssl() || 'local' === wp_get_environment_type();
     4672}
     4673
    46604674/**
    46614675 * Checks if Application Passwords is globally available.
    46624676 *
    46634677 * By default, Application Passwords is available to all sites using SSL or to local environments.
    4664  * Use {@see 'wp_is_application_passwords_available'} to adjust its availability.
     4678 * Use the {@see 'wp_is_application_passwords_available'} filter to adjust its availability.
    46654679 *
    46664680 * @since 5.6.0
    46674681 *
    46684682 * @return bool
    46694683 */
    46704684function wp_is_application_passwords_available() {
    4671         $available = is_ssl() || 'local' === wp_get_environment_type();
    4672 
    46734685        /**
    46744686         * Filters whether Application Passwords is available.
    46754687         *
    function wp_is_application_passwords_available() { 
    46774689         *
    46784690         * @param bool $available True if available, false otherwise.
    46794691         */
    4680         return apply_filters( 'wp_is_application_passwords_available', $available );
     4692        return apply_filters( 'wp_is_application_passwords_available', wp_is_application_passwords_supported() );
    46814693}
    46824694
    46834695/**
  • tests/phpunit/tests/rest-api/rest-application-passwords-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
    index cbfe965fa1..aff7a20d64 100644
    a b class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control 
    946946                $this->assertErrorResponse( 'rest_application_password_not_found', $response, 500 );
    947947        }
    948948
     949        /**
     950         * @ticket 53658
     951         */
     952        public function test_supported_vs_available() {
     953                wp_set_current_user( self::$admin );
     954
     955                $_SERVER['HTTPS'] = 'on';
     956
     957                $this->assertTrue( wp_is_application_passwords_supported() );
     958
     959                unset( $_SERVER['HTTPS'] );
     960                define( 'WP_ENVIRONMENT_TYPE', 'production' );
     961
     962                $this->assertFalse( wp_is_application_passwords_supported() );
     963                $this->assertTrue( wp_is_application_passwords_available() );
     964        }
     965
    949966        /**
    950967         * Sets up a REST API request to be authenticated using an App Password.
    951968         *