Set post author in wp-email.php
-
Here’s a patch that will have wp-email.php look up the mail sender’s from address and assign the post to that author if registered.
*** wp-mail.php.orig Mon Jun 21 23:41:28 2004
--- wp-mail.php Fri Jun 18 16:43:50 2004
***************
*** 60,65 ****
--- 60,72 ----
$subject = wp_iso_descrambler($subject);
}
}
+ if (preg_match('/From: /i', $line)) {
+ $from = trim($line);
+ $from = str_replace('From: ', '', $from);
+ if (preg_match('/<(.*)>/', $from, $matches)) {
+ $from = $matches[1];
+ }
+ }
if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
$ddate = trim($line);
$ddate = str_replace('Date: ', '', $ddate);
***************
*** 120,126 ****
$content = preg_replace("|\n([^\n])|", " $1", $content);
$content = addslashes(trim($content));
! $sql = "INSERT INTO $tableposts (post_author, post_date, post_date_gmt, post_content, post_title, post_modified, post_modified_gmt) VALUES ('1', '$post_date', '$post_date_gmt', '$content', '$post_title', '$post_date', '$post_date_gmt')";
$result = $wpdb->query($sql);
$post_ID = $wpdb->insert_id;
--- 127,140 ----
$content = preg_replace("|\n([^\n])|", " $1", $content);
$content = addslashes(trim($content));
! $post_author = $wpdb->get_row("SELECT ID FROM wp_users WHERE user_email = '$from'", "ARRAY_N");
! if ($post_author == '') {
! $post_author = '1';
! } else {
! $post_author = $post_author[0];
! }
!
! $sql = "INSERT INTO $tableposts (post_author, post_date, post_date_gmt, post_content, post_title, post_modified, post_modified_gmt) VALUES ('$post_author', '$post_date', '$post_date_gmt', '$content', '$post_title', '$post_date', '$post_date_gmt')";
$result = $wpdb->query($sql);
$post_ID = $wpdb->insert_id;
***************
*** 134,141 ****
echo "\n<b>Posted author id:</b>
<pre>".$post_author.'</pre>';
echo "\n<b>Posted content:</b>
<pre>".$content.'</pre>';
-
-
if (!$post_categories) $post_categories[] = 1;
foreach ($post_categories as $post_category) :
$post_category = intval($post_category);
--- 148,153 ----
- The topic ‘Set post author in wp-email.php’ is closed to new replies.