OS : Linux
PHP Version : 7.4.33
Software :
id ) {
return;
}
wp_enqueue_script( 'wp-lists' );
?>
id ) {
return;
}
// When viewing spam we want to be able to be able to bulk delete
// When viewing anything we want to be able to bulk move to spam
if ( isset( $_GET['post_status'] ) && 'spam' == $_GET['post_status'] ) {
// Create Delete Permanently bulk item
$option_val = 'delete';
$option_txt = __( 'Delete Permanently', 'jetpack' );
$pseudo_selector = 'last-child';
} else {
// Create Mark Spam bulk item
$option_val = 'spam';
$option_txt = __( 'Mark as Spam', 'jetpack' );
$pseudo_selector = 'first-child';
}
?>
id
|| empty( $_GET['post_status'] )
|| 'spam' !== $_GET['post_status'] ) {
return;
}
// Get HTML for the button
$button_html = wp_nonce_field( 'bulk-destroy', '_destroy_nonce', true, false );
$button_html .= get_submit_button( __( 'Empty Spam', 'jetpack' ), 'apply', 'delete_all', false );
// Add the button next to the filter button via js
?>
$post_id,
'post_status' => 'spam',
);
$akismet_values = get_post_meta( $post_id, '_feedback_akismet_values', true );
wp_update_post( $post );
/**
* Fires after a comment has been marked by Akismet.
*
* Typically this means the comment is spam.
*
* @module contact-form
*
* @since 2.2.0
*
* @param string $comment_status Usually is 'spam', otherwise 'ham'.
* @param array $akismet_values From '_feedback_akismet_values' in comment meta
*/
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 $views;
}
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;
/**
* Only call parse_fields_from_content if we're dealing with a Grunion custom column.
*/
if ( ! in_array( $col, array( 'feedback_date', 'feedback_from', 'feedback_message' ) ) ) {
return;
}
$content_fields = Grunion_Contact_Form_Plugin::parse_fields_from_content( $post_id );
switch ( $col ) {
case 'feedback_from':
$author_name = isset( $content_fields['_feedback_author'] ) ? $content_fields['_feedback_author'] : '';
$author_email = isset( $content_fields['_feedback_author_email'] ) ? $content_fields['_feedback_author_email'] : '';
$author_url = isset( $content_fields['_feedback_author_url'] ) ? $content_fields['_feedback_author_url'] : '';
$author_ip = isset( $content_fields['_feedback_ip'] ) ? $content_fields['_feedback_ip'] : '';
$form_url = isset( $post->post_parent ) ? get_permalink( $post->post_parent ) : null;
$author_name_line = '';
if ( ! empty( $author_name ) ) {
if ( ! empty( $author_email ) ) {
$author_name_line = get_avatar( $author_email, 32 );
}
$author_name_line .= sprintf( '%s
', esc_html( $author_name ) );
}
$author_email_line = '';
if ( ! empty( $author_email ) ) {
$author_email_line = sprintf( "%2\$s
", esc_url( 'mailto:' . $author_email ), esc_html( $author_email ) );
}
$author_url_line = '';
if ( ! empty( $author_url ) ) {
$author_url_line = sprintf( "%1\$s
", esc_url( $author_url ) );
}
echo $author_name_line;
echo $author_email_line;
echo $author_url_line;
echo "" . esc_html( $author_ip ) . '
';
if ( $form_url ) {
echo '' . esc_html( $form_url ) . '';
}
break;
case 'feedback_message':
$post_type_object = get_post_type_object( $post->post_type );
if ( isset( $content_fields['_feedback_subject'] ) ) {
echo '';
echo esc_html( $content_fields['_feedback_subject'] );
echo '';
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 ) {
// Remove prefix from exta fields
echo "| " . esc_html( preg_replace( '#^\d+_#', '', $k ) ) . ' | ' . sanitize_text_field( $v ) . " |
\n";
}
echo '
';
}
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 ( isset( $_POST['sub_menu'] ) && preg_match( '|post_type=feedback|', $_POST['sub_menu'] ) ) {
if ( preg_match( '|post_status=spam|', $_POST['sub_menu'] ) ) {
$current_menu = 'spam';
} elseif ( 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 );
/** This action is already documented in modules/contact-form/admin.php */
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 );
/** This action is already documented in modules/contact-form/admin.php */
do_action( 'contact_form_akismet', 'ham', $akismet_values );
$comment_author_email = $reply_to_addr = $message = $to = $headers = false;
$blog_url = wp_parse_url( site_url() );
// resend the original email
$email = get_post_meta( $post_id, '_feedback_email', true );
$content_fields = Grunion_Contact_Form_Plugin::parse_fields_from_content( $post_id );
if ( ! empty( $email ) && ! 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'] . '"
\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' ) . '"';
}
/**
* Filters the subject of the email sent after a contact form submission.
*
* @module contact-form
*
* @since 3.0.0
*
* @param string $content_fields['_feedback_subject'] Feedback's subject line.
* @param array $content_fields['_feedback_all_fields'] Feedback's data from old fields.
*/
$subject = apply_filters( 'contact_form_subject', $content_fields['_feedback_subject'], $content_fields['_feedback_all_fields'] );
Grunion_Contact_Form::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' ) );
}
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 the scripts that will add the "Check for Spam" button to the Feedbacks dashboard page.
*/
function grunion_enable_spam_recheck() {
if ( ! defined( 'AKISMET_VERSION' ) ) {
return;
}
$screen = get_current_screen();
// Only add to feedback, only to non-spam view
if ( 'edit-feedback' != $screen->id || ( ! empty( $_GET['post_status'] ) && 'spam' == $_GET['post_status'] ) ) {
return;
}
// Add the scripts that handle the spam check event.
wp_register_script(
'grunion-admin',
Assets::get_file_url_for_environment(
'_inc/build/contact-form/js/grunion-admin.min.js',
'modules/contact-form/js/grunion-admin.js'
),
array( 'jquery' )
);
wp_enqueue_script( 'grunion-admin' );
wp_enqueue_style( 'grunion.css' );
// Add the actual "Check for Spam" button.
add_action( 'admin_head', 'grunion_check_for_spam_button' );
}
add_action( 'admin_enqueue_scripts', 'grunion_enable_spam_recheck' );
/**
* Add the "Check for Spam" button to the Feedbacks dashboard page.
*/
function grunion_check_for_spam_button() {
// Get HTML for the button
$button_html = get_submit_button(
__( 'Check for Spam', 'jetpack' ),
'secondary',
'jetpack-check-feedback-spam',
false,
array( 'class' => 'jetpack-check-feedback-spam' )
);
$button_html .= '';
// Add the button next to the filter button via js
?>
ID, '_feedback_akismet_values', true );
/**
* Filter whether the submitted feedback is considered as spam.
*
* @module contact-form
*
* @since 3.4.0
*
* @param bool false Is the submitted feedback spam? Default to false.
* @param array $meta Feedack values returned by the Akismet plugin.
*/
$is_spam = apply_filters( 'jetpack_contact_form_is_spam', false, $meta );
if ( $is_spam ) {
wp_update_post(
array(
'ID' => $feedback->ID,
'post_status' => 'spam',
)
);
/** This action is already documented in modules/contact-form/admin.php */
do_action( 'contact_form_akismet', 'spam', $meta );
}
}
wp_send_json(
array(
'processed' => count( $approved_feedbacks ),
)
);
}
add_action( 'wp_ajax_grunion_recheck_queue', 'grunion_recheck_queue' );