Skip to content

Commit

Permalink
* Reduced the redundant storage of data. Eliminated _feedback_author,…
Browse files Browse the repository at this point in the history
… _feedback_author_email, _feedback_author_url, _feedback_subject, _feedback_ip, _feedback_contact_form_url, _feedback_all_fields and reduce _feedback_email to just hold just the email message the email recipient(s).

* Added a check for X-akismet-pro-tip header and discard spam when it's recommended, similar to latest version of akismet plugin.

Merges r94591-wpcom.
  • Loading branch information
eoigal authored and cathyjf committed Apr 7, 2014
1 parent cbaf41f commit 2e02580
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 141 deletions.
55 changes: 46 additions & 9 deletions modules/contact-form/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,16 @@ function grunion_post_type_columns_filter( $cols ) {
add_action( 'manage_posts_custom_column', 'grunion_manage_post_columns', 10, 2 );
function grunion_manage_post_columns( $col, $post_id ) {
global $post;

$content_fields = Grunion_Contact_Form_Plugin::parse_fields_from_content( $post_id );

switch ( $col ) {
case 'feedback_from':
$author_name = get_post_meta( $post_id, '_feedback_author', TRUE );
$author_email = get_post_meta( $post_id, '_feedback_author_email', TRUE );
$author_url = get_post_meta( $post_id, '_feedback_author_url', TRUE );
$author_ip = get_post_meta( $post_id, '_feedback_ip', TRUE );
$form_url = get_post_meta( $post_id, '_feedback_contact_form_url', TRUE );
$author_name = $content_fields['_feedback_author'];
$author_email = $content_fields['_feedback_author_email'];
$author_url = $content_fields['_feedback_author_url'];
$author_ip = $content_fields['_feedback_ip'];
$form_url = get_permalink( $post_id );

$author_name_line = '';
if ( !empty( $author_name ) ) {
Expand Down Expand Up @@ -246,7 +248,7 @@ function grunion_manage_post_columns( $col, $post_id ) {
$post = get_post( $post_id );
$post_type_object = get_post_type_object( $post->post_type );
echo '<strong>';
echo esc_html( get_post_meta( $post_id, '_feedback_subject', TRUE ) );
echo esc_html( $content_fields['_feedback_subject'] );
echo '</strong><br />';
echo sanitize_text_field( get_the_content( '' ) );
echo '<br />';
Expand Down Expand Up @@ -515,6 +517,7 @@ function grunion_ajax_shortcode_to_json() {
die( json_encode( $out ) );
}


add_action( 'wp_ajax_grunion_shortcode', 'grunion_ajax_shortcode' );
add_action( 'wp_ajax_grunion_shortcode_to_json', 'grunion_ajax_shortcode_to_json' );

Expand Down Expand Up @@ -547,7 +550,7 @@ function grunion_ajax_spam() {

$post = get_post( $post_id );
$post_type_object = get_post_type_object( $post->post_type );
$akismet_values = get_post_meta( $post_id, '_feedback_akismet_values', TRUE );
$akismet_values = get_post_meta( $post_id, '_feedback_akismet_values', TRUE );
if ( $_POST['make_it'] == 'spam' ) {
$post->post_status = 'spam';
$status = wp_insert_post( $post );
Expand All @@ -558,10 +561,44 @@ function grunion_ajax_spam() {
$status = wp_insert_post( $post );
wp_transition_post_status( 'publish', 'spam', $post );
do_action( 'contact_form_akismet', 'spam', $akismet_values );


$comment_author_email = $reply_to_addr = $message = $to = $headers = false;
$blog_url = parse_url( site_url() );

// resend the original email
$email = get_post_meta( $post_id, '_feedback_email', TRUE );
wp_mail( $email['to'], $email['subject'], $email['message'], $email['headers'] );
$content_fields = Grunion_Contact_Form_Plugin::parse_fields_from_content( $post_id );

if ( !empty( $emails ) && !empty( $content_fields ) ) {
if ( isset( $content_fields['_feedback_author_email'] ) )
$comment_author_email = $content_fields['_feedback_author_email'];

if ( isset( $email['to'] ) )
$to = $email['to'];

if ( isset( $email['message'] ) )
$message = $email['message'];

if ( isset( $email['headers'] ) )
$headers = $email['headers'];
else {
$headers = 'From: "' . $content_fields['_feedback_author'] .'" <wordpress@' . $blog_url['host'] . ">\r\n";

if ( !empty( $comment_author_email ) )
$reply_to_addr = $comment_author_email;
elseif ( is_array( $to ) )
$reply_to_addr = $to[0];

if ( $reply_to_addr )
$headers .= 'Reply-To: "' . $content_fields['_feedback_author'] .'" <' . $reply_to_addr . ">\r\n";

$headers .= "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"";
}

$subject = apply_filters( 'contact_form_subject', $content_fields['_feedback_subject'] );

wp_mail( $to, $subject, $message, $headers );
}
} elseif( $_POST['make_it'] == 'publish' ) {
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
wp_die( __( 'You are not allowed to move this item out of the Trash.', 'jetpack' ) );
Expand Down
Loading

0 comments on commit 2e02580

Please sign in to comment.