WordPress.org

Make WordPress Core

Changeset 21910


Ignore:
Timestamp:
09/19/2012 01:27:21 AM (6 years ago)
Author:
nacin
Message:

XML-RPC: Have the deprecated login_pass_ok() method wrap login(). Move it below login() so the proper method is found first. see #21907.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r21896 r21910  
    163163
    164164    /**
    165      * Check user's credentials.
    166      *
    167      * @since 1.5.0
    168      *
    169      * @param string $user_login User's username.
    170      * @param string $user_pass User's password.
    171      * @return bool Whether authentication passed.
    172      * @deprecated use wp_xmlrpc_server::login
    173      * @see wp_xmlrpc_server::login
    174      */
    175     function login_pass_ok($user_login, $user_pass) {
    176 
     165     * Log user in.
     166     *
     167     * @since 2.8.0
     168     *
     169     * @param string $username User's username.
     170     * @param string $password User's password.
     171     * @return mixed WP_User object if authentication passed, false otherwise
     172     */
     173    function login( $username, $password ) {
    177174        // Respect any old filters against get_option() for 'enable_xmlrpc'.
    178175        $enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); // Deprecated
     
    188185        }
    189186
    190         if (!user_pass_ok($user_login, $user_pass)) {
    191             $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
     187        $user = wp_authenticate($username, $password);
     188
     189        if (is_wp_error($user)) {
     190            $this->error = new IXR_Error( 403, __('Bad login/pass combination.' ) );
    192191            return false;
    193192        }
    194         return true;
    195     }
    196 
    197     /**
    198      * Log user in.
    199      *
    200      * @since 2.8
     193
     194        wp_set_current_user( $user->ID );
     195        return $user;
     196    }
     197
     198    /**
     199     * Check user's credentials. Deprecated.
     200     *
     201     * @since 1.5.0
     202     * @deprecated 2.8.0
     203     * @deprecated use wp_xmlrpc_server::login
     204     * @see wp_xmlrpc_server::login
    201205     *
    202206     * @param string $username User's username.
    203207     * @param string $password User's password.
    204      * @return mixed WP_User object if authentication passed, false otherwise
    205      */
    206     function login($username, $password) {
    207         // Respect any old filters against get_option() for 'enable_xmlrpc'.
    208         $enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); // Deprecated
    209         if ( false === $enabled )
    210             $enabled = apply_filters( 'option_enable_xmlrpc', true ); // Deprecated
    211 
    212         // Proper filter for turning off XML-RPC. It is on by default.
    213         $enabled = apply_filters( 'xmlrpc_enabled', $enabled );
    214 
    215         if ( ! $enabled ) {
    216             $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) );
    217             return false;
    218         }
    219 
    220         $user = wp_authenticate($username, $password);
    221 
    222         if (is_wp_error($user)) {
    223             $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
    224             return false;
    225         }
    226 
    227         wp_set_current_user( $user->ID );
    228         return $user;
     208     * @return bool Whether authentication passed.
     209     */
     210    function login_pass_ok( $username, $password ) {
     211        return (bool) $this->login( $username, $password );
    229212    }
    230213
Note: See TracChangeset for help on using the changeset viewer.