id, array( 'edit-feedback', 'jetpack_page_omnisearch', 'dashboard_page_omnisearch' ) ) ) return; wp_enqueue_script( 'wp-lists' ); ?> id || ( ! empty( $_GET['post_status'] ) && 'spam' == $_GET['post_status'] ) ) return; $spam_text = __( 'Mark Spam', 'jetpack' ); ?> $post_id, 'post_status' => 'spam', ); $akismet_values = get_post_meta( $post_id, '_feedback_akismet_values', true ); wp_update_post( $post ); do_action( 'contact_form_akismet', 'spam', $akismet_values ); } $redirect_url = add_query_arg( 'message', 'marked-spam', wp_get_referer() ); wp_safe_redirect( $redirect_url ); exit; } function grunion_message_bulk_spam() { echo '

' . __( 'Feedback(s) marked as spam', 'jetpack' ) . '

'; } // remove admin UI parts that we don't support in feedback management add_action( 'admin_menu', 'grunion_admin_menu' ); function grunion_admin_menu() { global $menu, $submenu; unset( $submenu['edit.php?post_type=feedback'] ); } add_filter( 'bulk_actions-edit-feedback', 'grunion_admin_bulk_actions' ); function grunion_admin_bulk_actions( $actions ) { global $current_screen; if ( 'edit-feedback' != $current_screen->id ) return $actions; unset( $actions['edit'] ); return $actions; } add_filter( 'views_edit-feedback', 'grunion_admin_view_tabs' ); function grunion_admin_view_tabs( $views ) { global $current_screen; if ( 'edit-feedback' != $current_screen->id ) return $actions; unset( $views['publish'] ); preg_match( '|post_type=feedback\'( class="current")?\>(.*)\ '', 'feedback_from' => __( 'From', 'jetpack' ), 'feedback_message' => __( 'Message', 'jetpack' ), 'feedback_date' => __( 'Date', 'jetpack' ) ); return $cols; } add_action( 'manage_posts_custom_column', 'grunion_manage_post_columns', 10, 2 ); function grunion_manage_post_columns( $col, $post_id ) { global $post; 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_line = ''; if ( !empty( $author_name ) ) { if ( !empty( $author_email ) ) $author_name_line = get_avatar( $author_email, 32 ); $author_name_line .= "{$author_name}
"; } $author_email_line = ''; if ( !empty( $author_email ) ) { $author_email_line = ""; $author_email_line .= "{$author_email}
"; } $author_url_line = ''; if ( !empty( $author_url ) ) { $author_url_line = ""; $author_url_line .= "{$author_url}
"; } echo $author_name_line; echo $author_email_line; echo $author_url_line; echo "{$author_ip}
"; echo "{$form_url}"; break; case 'feedback_message': $post = get_post( $post_id ); $post_type_object = get_post_type_object( $post->post_type ); echo ''; echo esc_html( get_post_meta( $post_id, '_feedback_subject', TRUE ) ); echo '
'; echo sanitize_text_field( get_the_content( '' ) ); echo '
'; $extra_fields = get_post_meta( $post_id, '_feedback_extra_fields', TRUE ); if ( !empty( $extra_fields ) ) { echo '

'; echo '' . "\n"; foreach ( (array) $extra_fields as $k => $v ) { echo "\n"; } echo '
". esc_html( $k ) ."". sanitize_text_field( $v ) ."
'; } echo '
'; if ( $post->post_status == 'trash' ) { echo '' . __( 'Restore', 'jetpack' ) . ' | '; echo " " . __( 'Delete Permanently', 'jetpack' ) . ""; ?> post_status == 'publish' ) { echo 'Spam'; echo ' | '; echo ''; echo '' . __( 'Trash', 'jetpack' ) . ''; ?> post_status == 'spam' ) { echo 'Not Spam'; echo ' | '; echo " " . __( 'Delete Permanently', 'jetpack' ) . ""; ?> '', 'subject' => '', 'fields' => array(), ); foreach ( $grunion->fields as $field ) { $out['fields'][$field->get_attribute( 'id' )] = $field->attributes; } $to = $grunion->get_attribute( 'to' ); $subject = $grunion->get_attribute( 'subject' ); foreach ( array( 'to', 'subject' ) as $attribute ) { $value = $grunion->get_attribute( $attribute ); if ( isset( $grunion->defaults[$attribute] ) && $value == $grunion->defaults[$attribute] ) { $value = ''; } $out[$attribute] = $value; } 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' ); // process row-action spam/not spam clicks add_action( 'wp_ajax_grunion_ajax_spam', 'grunion_ajax_spam' ); function grunion_ajax_spam() { global $wpdb; if ( empty( $_POST['make_it'] ) ) return; $post_id = (int) $_POST['post_id']; check_ajax_referer( 'grunion-post-status-' . $post_id ); if ( !current_user_can("edit_page", $post_id) ) wp_die( __( 'You are not allowed to manage this item.', 'jetpack' ) ); require_once dirname( __FILE__ ) . '/grunion-contact-form.php'; $current_menu = ''; if ( preg_match( '|post_type=feedback|', $_POST['sub_menu'] ) ) { if ( preg_match( '|post_status=spam|', $_POST['sub_menu'] ) ) $current_menu = 'spam'; else if ( preg_match( '|post_status=trash|', $_POST['sub_menu'] ) ) $current_menu = 'trash'; else $current_menu = 'messages'; } $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 ); if ( $_POST['make_it'] == 'spam' ) { $post->post_status = 'spam'; $status = wp_insert_post( $post ); wp_transition_post_status( 'spam', 'publish', $post ); do_action( 'contact_form_akismet', 'spam', $akismet_values ); } elseif ( $_POST['make_it'] == 'ham' ) { $post->post_status = 'publish'; $status = wp_insert_post( $post ); wp_transition_post_status( 'publish', 'spam', $post ); do_action( 'contact_form_akismet', 'spam', $akismet_values ); // resend the original email $email = get_post_meta( $post_id, '_feedback_email', TRUE ); wp_mail( $email['to'], $email['subject'], $email['message'], $email['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' ) ); if ( ! wp_untrash_post($post_id) ) wp_die( __( 'Error in restoring from Trash.', 'jetpack' ) ); } elseif( $_POST['make_it'] == 'trash' ) { if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) wp_die( __( 'You are not allowed to move this item to the Trash.', 'jetpack' ) ); if ( ! wp_trash_post($post_id) ) wp_die( __( 'Error in moving to Trash.', 'jetpack' ) ); } $sql = " SELECT post_status, COUNT( * ) AS post_count FROM `{$wpdb->posts}` WHERE post_type = 'feedback' GROUP BY post_status "; $status_count = (array) $wpdb->get_results( $sql, ARRAY_A ); $status = array(); $status_html = ''; foreach ( $status_count as $i => $row ) { $status[$row['post_status']] = $row['post_count']; } if ( isset( $status['publish'] ) ) { $status_html .= '
  • '; $status_html .= '(' . number_format( $status['publish'] ) . ')'; $status_html .= ' |
  • '; } if ( isset( $status['trash'] ) ) { $status_html .= '
  • '; $status_html .= '(' . number_format( $status['trash'] ) . ')'; $status_html .= ''; if ( isset( $status['spam'] ) ) $status_html .= ' |'; $status_html .= '
  • '; } if ( isset( $status['spam'] ) ) { $status_html .= '
  • '; $status_html .= '(' . number_format( $status['spam'] ) . ')'; $status_html .= '
  • '; } echo $status_html; exit; } add_action( 'omnisearch_add_providers', 'grunion_omnisearch_add_providers' ); function grunion_omnisearch_add_providers() { // Feedback uses capability_type 'page' if ( current_user_can( 'edit_pages' ) ) { require_once( GRUNION_PLUGIN_DIR . '/grunion-omnisearch.php' ); new Jetpack_Omnisearch_Grunion; } }