grunion_ajax_spam

The Jetpack by WordPress.com grunion ajax spam function.

Description

grunion_ajax_spam(); 

Usage

  1. if ( !function_exists( 'grunion_ajax_spam' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/contact-form/admin.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = grunion_ajax_spam(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/modules/contact-form/admin.php  
  1. function grunion_ajax_spam() { 
  2. global $wpdb; 
  3.  
  4. if ( empty( $_POST['make_it'] ) ) { 
  5. return; 
  6.  
  7. $post_id = (int) $_POST['post_id']; 
  8. check_ajax_referer( 'grunion-post-status-' . $post_id ); 
  9. if ( ! current_user_can( "edit_page", $post_id ) ) { 
  10. wp_die( __( 'You are not allowed to manage this item.', jetpack ) ); 
  11.  
  12. require_once dirname( __FILE__ ) . '/grunion-contact-form.php'; 
  13.  
  14. $current_menu = ''; 
  15. if ( isset( $_POST['sub_menu'] ) && preg_match( '|post_type=feedback|', $_POST['sub_menu'] ) ) { 
  16. if ( preg_match( '|post_status=spam|', $_POST['sub_menu'] ) ) { 
  17. $current_menu = 'spam'; 
  18. elseif ( preg_match( '|post_status=trash|', $_POST['sub_menu'] ) ) { 
  19. $current_menu = 'trash'; 
  20. else { 
  21. $current_menu = 'messages'; 
  22.  
  23.  
  24. $post = get_post( $post_id ); 
  25. $post_type_object = get_post_type_object( $post->post_type ); 
  26. $akismet_values = get_post_meta( $post_id, '_feedback_akismet_values', TRUE ); 
  27. if ( $_POST['make_it'] == 'spam' ) { 
  28. $post->post_status = 'spam'; 
  29. $status = wp_insert_post( $post ); 
  30. wp_transition_post_status( 'spam', 'publish', $post ); 
  31.  
  32. /** This action is already documented in modules/contact-form/admin.php */ 
  33. do_action( 'contact_form_akismet', 'spam', $akismet_values ); 
  34. } elseif ( $_POST['make_it'] == 'ham' ) { 
  35. $post->post_status = 'publish'; 
  36. $status = wp_insert_post( $post ); 
  37. wp_transition_post_status( 'publish', 'spam', $post ); 
  38.  
  39. /** This action is already documented in modules/contact-form/admin.php */ 
  40. do_action( 'contact_form_akismet', 'ham', $akismet_values ); 
  41.  
  42. $comment_author_email = $reply_to_addr = $message = $to = $headers = false; 
  43. $blog_url = parse_url( site_url() ); 
  44.  
  45. // resend the original email 
  46. $email = get_post_meta( $post_id, '_feedback_email', TRUE ); 
  47. $content_fields = Grunion_Contact_Form_Plugin::parse_fields_from_content( $post_id ); 
  48.  
  49. if ( ! empty( $email ) && !empty( $content_fields ) ) { 
  50. if ( isset( $content_fields['_feedback_author_email'] ) ) { 
  51. $comment_author_email = $content_fields['_feedback_author_email']; 
  52.  
  53. if ( isset( $email['to'] ) ) { 
  54. $to = $email['to']; 
  55.  
  56. if ( isset( $email['message'] ) ) { 
  57. $message = $email['message']; 
  58.  
  59. if ( isset( $email['headers'] ) ) { 
  60. $headers = $email['headers']; 
  61. else { 
  62. $headers = 'From: "' . $content_fields['_feedback_author'] .'" <wordpress@' . $blog_url['host'] . ">\r\n"; 
  63.  
  64. if ( ! empty( $comment_author_email ) ) { 
  65. $reply_to_addr = $comment_author_email; 
  66. elseif ( is_array( $to ) ) { 
  67. $reply_to_addr = $to[0]; 
  68.  
  69. if ( $reply_to_addr ) { 
  70. $headers .= 'Reply-To: "' . $content_fields['_feedback_author'] .'" <' . $reply_to_addr . ">\r\n"; 
  71.  
  72. $headers .= "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\""; 
  73.  
  74. /** 
  75. * Filters the subject of the email sent after a contact form submission. 
  76. * @module contact-form 
  77. * @since 3.0.0 
  78. * @param string $content_fields['_feedback_subject'] Feedback's subject line. 
  79. * @param array $content_fields['_feedback_all_fields'] Feedback's data from old fields. 
  80. */ 
  81. $subject = apply_filters( 'contact_form_subject', $content_fields['_feedback_subject'], $content_fields['_feedback_all_fields'] ); 
  82.  
  83. wp_mail( $to, $subject, $message, $headers ); 
  84. } elseif( $_POST['make_it'] == 'publish' ) { 
  85. if ( ! current_user_can($post_type_object->cap->delete_post, $post_id) ) { 
  86. wp_die( __( 'You are not allowed to move this item out of the Trash.', jetpack ) ); 
  87.  
  88. if ( ! wp_untrash_post($post_id) ) { 
  89. wp_die( __( 'Error in restoring from Trash.', jetpack ) ); 
  90.  
  91. } elseif( $_POST['make_it'] == 'trash' ) { 
  92. if ( ! current_user_can($post_type_object->cap->delete_post, $post_id) ) { 
  93. wp_die( __( 'You are not allowed to move this item to the Trash.', jetpack ) ); 
  94.  
  95. if ( ! wp_trash_post($post_id) ) { 
  96. wp_die( __( 'Error in moving to Trash.', jetpack ) ); 
  97.  
  98.  
  99. $sql = " 
  100. SELECT post_status,  
  101. COUNT( * ) AS post_count 
  102. FROM `{$wpdb->posts}` 
  103. WHERE post_type = 'feedback' 
  104. GROUP BY post_status 
  105. "; 
  106. $status_count = (array) $wpdb->get_results( $sql, ARRAY_A ); 
  107.  
  108. $status = array(); 
  109. $status_html = ''; 
  110. foreach ( $status_count as $i => $row ) { 
  111. $status[$row['post_status']] = $row['post_count']; 
  112.  
  113. if ( isset( $status['publish'] ) ) { 
  114. $status_html .= '<li><a href="edit.php?post_type=feedback"'; 
  115. if ( $current_menu == 'messages' ) { 
  116. $status_html .= ' class="current"'; 
  117.  
  118. $status_html .= '>' . __( 'Messages', jetpack ) . ' <span class="count">'; 
  119. $status_html .= '(' . number_format( $status['publish'] ) . ')'; 
  120. $status_html .= '</span></a> |</li>'; 
  121.  
  122. if ( isset( $status['trash'] ) ) { 
  123. $status_html .= '<li><a href="edit.php?post_status=trash&post_type=feedback"'; 
  124. if ( $current_menu == 'trash' ) 
  125. $status_html .= ' class="current"'; 
  126.  
  127. $status_html .= '>' . __( 'Trash', jetpack ) . ' <span class="count">'; 
  128. $status_html .= '(' . number_format( $status['trash'] ) . ')'; 
  129. $status_html .= '</span></a>'; 
  130. if ( isset( $status['spam'] ) ) 
  131. $status_html .= ' |'; 
  132. $status_html .= '</li>'; 
  133.  
  134. if ( isset( $status['spam'] ) ) { 
  135. $status_html .= '<li><a href="edit.php?post_status=spam&post_type=feedback"'; 
  136. if ( $current_menu == 'spam' ) 
  137. $status_html .= ' class="current"'; 
  138.  
  139. $status_html .= '>' . __( 'Spam', jetpack ) . ' <span class="count">'; 
  140. $status_html .= '(' . number_format( $status['spam'] ) . ')'; 
  141. $status_html .= '</span></a></li>'; 
  142.  
  143. echo $status_html; 
  144. exit;