Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-app.php

    r8399 r8267  
    207207                                // authenticate regardless of the operation and set the current
    208208                                // user. each handler will decide if auth is required or not.
    209                                 if(!$this->authenticate()) {
     209                                $this->authenticate();
     210                                $u = wp_get_current_user();
     211                                if(!isset($u) || $u->ID == 0) {
    210212                                        if ($always_authenticate) {
    211213                                                $this->auth_required('Credentials required.');
    … …  
    393395
    394396                $publish = (isset($parsed->draft) && trim($parsed->draft) == 'yes') ? false : true;
    395                 $post_status = ($publish) ? 'publish' : 'draft';
    396397
    397398                extract($entry);
    … …  
    406407                $post_modified = $pubtimes[0];
    407408                $post_modified_gmt = $pubtimes[1];
     409
     410                // let's not go backwards and make something draft again.
     411                if(!$publish && $post_status == 'draft') {
     412                        $post_status = ($publish) ? 'publish' : 'draft';
     413                } elseif($publish) {
     414                        $post_status = 'publish';
     415                }
    408416
    409417                $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt');
    … …  
    10631071         */
    10641072        function authenticate() {
     1073                $login_data = array();
     1074                $already_md5 = false;
     1075
    10651076                log_app("authenticate()",print_r($_ENV, true));
    10661077
    … …  
    10741085                // If Basic Auth is working...
    10751086                if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
    1076                         log_app("Basic Auth",$_SERVER['PHP_AUTH_USER']);
    1077                         $user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
    1078                         if ( $user && !is_wp_error($user) ) {
    1079                                 wp_set_current_user($user->ID);
    1080                                 log_app("authenticate()", $_SERVER['PHP_AUTH_USER']);
    1081                                 return true;
     1087                        $login_data = array('login' => $_SERVER['PHP_AUTH_USER'],       'password' => $_SERVER['PHP_AUTH_PW']);
     1088                        log_app("Basic Auth",$login_data['login']);
     1089                } else {
     1090                        // else, do cookie-based authentication
     1091                        if (function_exists('wp_get_cookie_login')) {
     1092                                $login_data = wp_get_cookie_login();
     1093                                $already_md5 = true;
    10821094                        }
    10831095                }
    10841096
    1085                 return false;
     1097                // call wp_login and set current user
     1098                if (!empty($login_data) && wp_login($login_data['login'], $login_data['password'], $already_md5)) {
     1099                         $current_user = new WP_User(0, $login_data['login']);
     1100                         wp_set_current_user($current_user->ID);
     1101                        log_app("authenticate()",$login_data['login']);
     1102                }
    10861103        }
    10871104
Note: See TracChangeset for help on using the changeset viewer.