From 1578ac3876a19c056ff3b220a3620f5d3dd4588e Mon Sep 17 00:00:00 2001 From: Steven Dufresne Date: Fri, 13 Sep 2024 17:32:02 +0900 Subject: [PATCH] Fix/delete attendee survey (#1368) * Remove camptix-attendee-survey. --- .../wcorg-network-plugin-control.php | 1 - .../camptix-attendee-survey.php | 143 -------- .../includes/admin-page.php | 153 --------- .../camptix-attendee-survey/includes/cron.php | 187 ----------- .../includes/email.php | 101 ------ .../camptix-attendee-survey/includes/page.php | 311 ------------------ 6 files changed, 896 deletions(-) delete mode 100644 public_html/wp-content/plugins/camptix-attendee-survey/camptix-attendee-survey.php delete mode 100644 public_html/wp-content/plugins/camptix-attendee-survey/includes/admin-page.php delete mode 100644 public_html/wp-content/plugins/camptix-attendee-survey/includes/cron.php delete mode 100644 public_html/wp-content/plugins/camptix-attendee-survey/includes/email.php delete mode 100644 public_html/wp-content/plugins/camptix-attendee-survey/includes/page.php diff --git a/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php b/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php index 6adb78181d..fada5e5b1f 100644 --- a/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php +++ b/public_html/wp-content/mu-plugins/wcorg-network-plugin-control.php @@ -91,7 +91,6 @@ function _get_network_plugin_state_list( $state ) { $network_id = get_current_network_id(); if ( EVENTS_NETWORK_ID === $network_id ) { - $network_plugin_state['activated'][] = 'camptix-attendee-survey/camptix-attendee-survey.php'; $network_plugin_state['activated'][] = 'wordcamp-organizer-survey/wordcamp-organizer-survey.php'; } diff --git a/public_html/wp-content/plugins/camptix-attendee-survey/camptix-attendee-survey.php b/public_html/wp-content/plugins/camptix-attendee-survey/camptix-attendee-survey.php deleted file mode 100644 index 2bf070d472..0000000000 --- a/public_html/wp-content/plugins/camptix-attendee-survey/camptix-attendee-survey.php +++ /dev/null @@ -1,143 +0,0 @@ -get_col( - $wpdb->prepare(" - SELECT b.blog_id - FROM $wpdb->blogs AS b - LEFT OUTER JOIN $wpdb->blogmeta AS m - ON b.blog_id = m.blog_id AND m.meta_value = %s - ", - get_feature_id() - ) - ); - - return array_map( 'absint', $blog_ids ); -} - -/** - * Shortcut to the includes directory. - * - * @return string - */ -function get_includes_path() { - return plugin_dir_path( __FILE__ ) . 'includes/'; -} diff --git a/public_html/wp-content/plugins/camptix-attendee-survey/includes/admin-page.php b/public_html/wp-content/plugins/camptix-attendee-survey/includes/admin-page.php deleted file mode 100644 index 263aad6f7b..0000000000 --- a/public_html/wp-content/plugins/camptix-attendee-survey/includes/admin-page.php +++ /dev/null @@ -1,153 +0,0 @@ - string, - * 'admin_url' => string, - * 'email_url' => string, - * 'responses_url' => string, - * 'sent' => string, - * 'responses' => string, - * 'rate' => string, - * ] - */ -function get_feedback_details() { - /* @var CampTix_Plugin $camptix */ - global $camptix; - - $wordcamps = get_posts( array( - 'post_type' => WCPT_POST_TYPE_ID, - 'post_status' => 'wcpt-closed', - 'posts_per_page' => -1, - 'date_query' => array( - array( - 'after' => '2023-05-01', // The feature doesn't exist before this date. - 'inclusive' => true, - ), - ), - ) ); - - $feedback_details = array(); - - foreach ( $wordcamps as $camp ) { - $blog_id = get_wordcamp_site_id( $camp ); - - switch_to_blog( $blog_id ); - - $blog_details = get_blog_details( $blog_id ); - - if ( (int) get_site()->site_id !== EVENTS_NETWORK_ID ) { - continue; - } - - $query = new \WP_Query( array( - 'post_type' => 'feedback', - 'post_parent' => get_page_id(), - 'posts_per_page' => -1, - ) ); - - $sent = (int) $camptix->get_sent_email_count( get_email_id() ); - $responses = (int) $query->found_posts; - - $feedback_details[] = array( - 'title' => $blog_details->blogname, - 'admin_url' => admin_url(), - 'email_url' => get_edit_post_link( get_email_id() ), - 'responses_url' => admin_url( sprintf( 'edit.php?post_type=feedback&jetpack_form_parent_id=%s', get_page_id() ) ), - 'sent' => $sent, - 'responses' => $responses, - 'rate' => 0 !== $sent ? ceil( ( $responses / $sent ) * 100 ) . '%' : '', - ); - - // Restore the original site context. - restore_current_blog(); - } - - // Reset the global post object. - wp_reset_postdata(); - - return $feedback_details; -} - -/** - * Render the menu page. - */ -function render_menu_page() { - ?> -
-

- - - - - - - - - - - - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - - if ( empty( $feedback_details ) ) { - echo ''; - } - - ?> - -
' . esc_html( $feedback_detail['title'] ) . '' . esc_html( $feedback_detail['sent'] ) . '' . esc_html( $feedback_detail['responses'] ) . '' . esc_html( $feedback_detail['rate'] ) . '
' . esc_html__( 'Nothing to report', 'wordcamporg' ) . '
-
- log( $message, $post_id, $data ); -} - -/** - * Add cron jobs to the schedule. - */ -function schedule_jobs() { - if ( ! wp_next_scheduled( 'wc_attendee_survey_email' ) ) { - wp_schedule_event( time(), 'daily', 'wc_attendee_survey_email' ); - } -} - -/** - * Get Wordcamp attendees. - * - * @return int[] - */ -function get_wordcamp_attendees_id() { - return get_posts( array( - 'post_type' => 'tix_attendee', - 'posts_per_page' => -1, - 'post_status' => 'publish', - 'fields' => 'ids', - 'orderby' => 'ID', - 'order' => 'ASC', - 'cache_results' => false, - ) ); -} - -/** - * Associates attendees to emails. - */ -function associate_attendee_to_email( $email_id ) { - $failed_to_add = array(); - $successfully_added = array(); - $recipients = get_wordcamp_attendees_id(); - - if ( empty( $recipients ) ) { - log( 'No valid recipients', $email_id, null ); - return; - } - - // Associate attendee to tix_email as a recipient. - foreach ( $recipients as $recipient_id ) { - $result = add_post_meta( $email_id, 'tix_email_recipient_id', $recipient_id ); - - if ( ! $result ) { - $failed_to_add[] = $recipient_id; - } else { - $successfully_added[] = $recipient_id; - } - } - - if ( ! empty( $failed_to_add ) ) { - log( 'Failed to add recipients:', $email_id, $failed_to_add ); - } - - if ( ! empty( $successfully_added ) ) { - // Copied from camptix.php. - update_post_meta( $email_id, 'tix_email_recipients_backup', $successfully_added ); - - log( 'Successfully added recipients:', $email_id, $successfully_added ); - } -} - -/** - * Returns true if an emailed will be sent or is queued. - * - * @return bool - */ -function is_email_already_sent_or_queued( $email_id ) { - $email = get_post( $email_id ); - return 'publish' === $email->post_status || 'pending' === $email->post_status; -} - -/** - * Returns true if it is time to send the email. - * - * @return bool - */ -function is_time_to_send_email( $email_id ) { - $blog_id = get_current_blog_id(); - $wordcamp_post = get_wordcamp_post( $blog_id ); - - if ( ! $wordcamp_post ) { - log( 'Couldn\'t retrieve wordcamp for blog id:', $email_id, $blog_id ); - return false; - } - - if ( 'wcpt-closed' !== $wordcamp_post->post_status ) { - return false; - } - - $end_date = $wordcamp_post->meta['End Date (YYYY-mm-dd)'][0]; - - if ( empty( $end_date ) ) { - log( 'WordCamp missing end date', $email_id, $wordcamp_post ); - return false; - } - - $send_date = $end_date + ( DAYS_AFTER_TO_SEND * DAY_IN_SECONDS ); - - return gmdate( 'Y-m-d', $send_date ) === current_time( 'Y-m-d', true ); -} - -/** - * Turns off the survey to avoid spam. - */ -function disable_attendee_survey() { - disable_page(); -} - -/** - * Associates recipients to email and changes its status to be picked up - * by the camptix email cron job `tix_scheduled_every_ten_minutes`. - */ -function queue_attendee_survey() { - $email_id = get_email_id(); - - if ( empty( $email_id ) ) { - return; - } - - // check to make sure we didn't already send an email for this wordcamp. - if ( is_email_already_sent_or_queued( $email_id ) ) { - return; - } - - if ( ! is_time_to_send_email( $email_id ) ) { - return; - } - - $page_published = publish_survey_page(); - - if ( is_wp_error( $page_published ) ) { - log( 'Error publishing survey page:', $email_id, $page_published ); - } - - associate_attendee_to_email( $email_id ); - - $email_status = queue_survey_email( $email_id ); - - if ( is_wp_error( $email_status ) ) { - log( 'Failed updating email status', $email_id, $email_status ); - } else { - log( 'Email status change to `pending`.', $email_id ); - } - - if ( ! wp_next_scheduled( 'wc_attendee_disable_survey' ) ) { - $next_time = strtotime( '+2 weeks' . wp_timezone_string() ); - wp_schedule_single_event( $next_time, 'wc_attendee_disable_survey' ); - } - - // Remove the cron job that queues everything. - wp_clear_scheduled_hook( 'wc_attendee_survey_email' ); -} diff --git a/public_html/wp-content/plugins/camptix-attendee-survey/includes/email.php b/public_html/wp-content/plugins/camptix-attendee-survey/includes/email.php deleted file mode 100644 index b5d37f0fc2..0000000000 --- a/public_html/wp-content/plugins/camptix-attendee-survey/includes/email.php +++ /dev/null @@ -1,101 +0,0 @@ -post-event survey and help us to do amazing WordPress events!\r\n", esc_url( $survey_page_url ) ); - $email .= "(If you can't open the link, copy and paste the following URL)\r\n"; - $email .= $survey_page_url . "\r\n\r\n"; - $email .= sprintf( "Please complete the survey by %s.\r\n\r\n", $closing_date ); - $email .= "Please also note that all responses will be kept confidential, and we will not share your personal information with any third parties.\r\n\r\n"; - $email .= "Thank you in advance, we really appreciate your time!\r\n\r\n"; - $email .= "Best regards,\r\n"; - $email .= "Organising Team,\r\n"; - $email .= esc_html( $wordcamp_name ); - - return $email; -} - - -/** - * Adds email to camptix email queue. - */ -function add_email() { - $email_id = get_option( EMAIL_KEY_ID ); - if ( $email_id ) { - return; - } - - $email_id = wp_insert_post( - array( - 'post_title' => __( '[first_name], tell us what you thought: Post-event survey', 'wordcamporg' ), - 'post_content' => get_email_content(), - 'post_status' => 'draft', // Must be 'draft' to avoid processing. - 'post_type' => 'tix_email', - ) - ); - - if ( $email_id > 0 ) { - update_option( EMAIL_KEY_ID, $email_id ); - } -} - -/** - * Turns on the email by changing its status to 'pending'. - * - * The Camptix email queue will send the email. - * - * @return int|WP_Error - */ -function queue_survey_email( $email_id ) { - return wp_update_post( array( - 'ID' => $email_id, - 'post_status' => 'pending', - ) ); -} - -/** - * Delete the email and associated meta data. - */ -function delete_email() { - $post_id = get_email_id(); - wp_delete_post( $post_id, true ); - delete_option( EMAIL_KEY_ID ); - - // Clean up any associated attendees to the email. - delete_post_meta( $post_id, 'tix_email_recipient_id' ); - delete_post_meta( $post_id, 'tix_email_recipients_backup' ); -} diff --git a/public_html/wp-content/plugins/camptix-attendee-survey/includes/page.php b/public_html/wp-content/plugins/camptix-attendee-survey/includes/page.php deleted file mode 100644 index 07d2b16f76..0000000000 --- a/public_html/wp-content/plugins/camptix-attendee-survey/includes/page.php +++ /dev/null @@ -1,311 +0,0 @@ -ID ) { - // Allow it, and delete the option if the page is force-deleted. - if ( $force_delete ) { - delete_option( SURVEY_PAGE_ID ); - return $check; - } - - return false; - } - - return $check; -} - -/** - * Get the content of the survey page. - * - * @return string - */ -function get_page_content() { - return << -

If you recently attended a WordPress event, please take the survey below to help us make them even better in the future.

- - - -
-
-

Part I. Tell us about you!

- - - -
- - - - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - - - -
- - - -
- - - - - - - - - - - -
- - - -
- - - - - - - - - - - - - -
-
- - - -
-

Part II. Tell us about the event you attended!

- - - -
- - - -
- - - - - - - - - -
- - - -
- - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - - - -
- - - -
- - - - - - - - - -
- - - -
-
- - -
- -EOT; -} - -/** - * Turns on the page by changing its status to 'publish'. - * - * @return int|WP_Error - */ -function publish_survey_page() { - return wp_update_post( array( - 'ID' => get_option( SURVEY_PAGE_ID ), - 'post_status' => 'publish', - ) ); -} - -/** - * Generate a link to the front end feedback UI for a particular session. - * - * @return string|bool - */ -function get_survey_page_url() { - return get_permalink( get_option( SURVEY_PAGE_ID ) ); -} - - -/** - * Create the Survey page, save ID into an option. - */ -function add_page() { - $page_id = get_option( SURVEY_PAGE_ID ); - if ( $page_id ) { - return; - } - - $page_id = wp_insert_post( array( - 'post_title' => __( 'Attendee Survey', 'wordcamporg' ), - /* translators: Page slug for the attendee survey. */ - 'post_name' => __( 'attendee survey', 'wordcamporg' ), - 'post_content' => get_page_content(), - 'post_status' => 'draft', - 'post_type' => 'page', - ) ); - - if ( $page_id > 0 ) { - update_option( SURVEY_PAGE_ID, $page_id ); - } -} - -/** - * Turns off the page by changing its status to 'draft'. - */ -function disable_page() { - $page_id = get_option( SURVEY_PAGE_ID ); - - if ( ! $page_id ) { - return; - } - - return wp_update_post( array( - 'ID' => $page_id, - 'post_status' => 'draft', - ) ); -} - -/** - * Delete the Survey page and associated meta data. - */ -function delete_page() { - $page_id = get_option( SURVEY_PAGE_ID ); - wp_delete_post( $page_id, true ); - delete_option( SURVEY_PAGE_ID ); -}