Ticket #4642: 4642.5.diff
| File 4642.5.diff, 4.1 KB (added by Bobcat, 6 years ago) |
|---|
-
wp-includes/pluggable.php
107 107 } 108 108 endif; 109 109 110 if ( !function_exists('get_user databylogin') ) :111 function get_user databylogin($user_login) {110 if ( !function_exists('get_user_by') ) : 111 function get_user_by($field, $value, $output = OBJECT, $filter = 'raw') { 112 112 global $wpdb; 113 $user_login = sanitize_user( $user_login ); 113 $user_ID = false; 114 if ( 'login' == $field ) { 115 $field = 'user_login'; 116 $value = sanitize_user( $value ); 117 if ( empty($value) ) 118 return false; 119 $user_ID = wp_cache_get($value, 'userlogins'); 120 } else if ( 'email' == $field ) { 121 $field = 'user_email'; 122 $value = sanitize_email( $value ); 123 if ( empty($value) || !is_email( $value ) ) 124 return false; 125 } else { 126 $field = 'ID'; 127 $value = (int) $value; 128 } 114 129 115 if ( empty( $user_login ) ) 116 return false; 130 if ( !$user_ID ) { 131 $user_ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE $field = %s LIMIT 1", $value)); 132 if ( !$user_ID ) 133 return false; 134 } 117 135 118 $user_id = wp_cache_get($user_login, 'userlogins'); 119 $userdata = wp_cache_get($user_id, 'users'); 136 if ( $output == OBJECT ) { 137 return $user_ID; 138 } elseif ( $output == ARRAY_A ) { 139 return get_object_vars($user_ID); 140 } elseif ( $output == ARRAY_N ) { 141 return array_values(get_object_vars($user_ID)); 142 } else { 143 return $user_ID; 144 } 145 } 146 endif; 120 147 121 if ( $userdata ) 122 return $userdata; 123 124 if ( !$user_ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_login = %s", $user_login)))148 if ( !function_exists('get_userdatabylogin') ) : 149 function get_userdatabylogin($user_login) { 150 $user_ID = get_user_by('login',$user_login); 151 if ( !$user_ID ) 125 152 return false; 126 153 127 $user = get_userdata($user_ID); 154 $user = wp_cache_get($user_ID, 'users'); 155 if ( !$user ) 156 $user = get_userdata($user_ID); 157 128 158 return $user; 129 159 } 130 160 endif; -
wp-mail.php
27 27 $content_transfer_encoding = ''; 28 28 $boundary = ''; 29 29 $bodysignal = 0; 30 $post_author = 1; 31 $author_found = false; 30 32 $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); 31 33 foreach ($message as $line) : 32 34 if (strlen($line) < 3) $bodysignal = 1; … … 70 72 $author = sanitize_email($author); 71 73 if ( is_email($author) ) { 72 74 echo "Author = {$author} <p>"; 73 $author = $wpdb->escape($author); 74 $result = $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1"); 75 if (!$result) 75 $user_ID = get_user_by('email',$author); 76 if (!$user_ID) { 76 77 $post_author = 1; 77 else 78 $post_author = $result->ID; 79 } else 78 $author_found = false; 79 } else { 80 $post_author = $user_ID; 81 $author_found = true; 82 } 83 } else { 80 84 $post_author = 1; 85 $author_found = false; 86 } 81 87 } 82 88 83 89 if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37' … … 111 117 } 112 118 endforeach; 113 119 120 // Set $post_status based on $author_found and on author's publish_posts capability 121 if ($author_found) { 122 $user = new WP_User($post_author); 123 if ($user->has_cap('publish_posts')) 124 $post_status = 'publish'; 125 else 126 $post_status = 'pending'; 127 } else { 128 // Author not found in DB, set status to pending. Author already set to admin. 129 $post_status = 'pending'; 130 } 131 114 132 $subject = trim($subject); 115 133 116 134 if ($content_type == 'multipart/alternative') { … … 144 162 145 163 $post_category = $post_categories; 146 164 147 // or maybe we should leave the choice to email drafts? propose a way148 $post_status = 'publish';149 150 165 $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status'); 151 166 $post_data = add_magic_quotes($post_data); 152 167
