); $data_defaults = array( '_feedback_author' => '', '_feedback_author_email' => '', '_feedback_author_url' => '', '_feedback_all_fields' => array(), '_feedback_ip' => '', '_feedback_subject' => '', ); $responses = array_map( function ( $response ) use ( $base_fields, $data_defaults ) { $data = array_merge( $data_defaults, \Automattic\Jetpack\Forms\ContactForm\Contact_Form_Plugin::parse_fields_from_content( $response->ID ) ); $all_fields = array_merge( $base_fields, $data['_feedback_all_fields'] ); return array( 'id' => $response->ID, 'uid' => $all_fields['feedback_id'], 'date' => get_the_date( 'c', $response ), 'author_name' => $data['_feedback_author'], 'author_email' => $data['_feedback_author_email'], 'author_url' => $data['_feedback_author_url'], 'author_avatar' => empty( $data['_feedback_author_email'] ) ? '' : get_avatar_url( $data['_feedback_author_email'] ), 'email_marketing_consent' => $all_fields['email_marketing_consent'], 'ip' => $data['_feedback_ip'], 'entry_title' => $all_fields['entry_title'], 'entry_permalink' => $all_fields['entry_permalink'], 'subject' => $data['_feedback_subject'], 'fields' => array_diff_key( $all_fields, $base_fields ), ); }, $query[ $current_query ]->posts ); return rest_ensure_response( array( 'responses' => $responses, 'totals' => array_map( function ( $subquery ) { return $subquery->found_posts; }, $query ), 'filters_available' => array( 'month' => $this->get_months_filter_for_query( $filter_args ), 'source' => array_map( function ( $post_id ) { return array( 'id' => $post_id, 'title' => get_the_title( $post_id ), 'url' => get_permalink( $post_id ), ); }, $source_ids ), ), ) ); } /** * Returns a list of months which can be used to filter the given query. * * @param array $query Query. * * @return array List of months. */ private function get_months_filter_for_query( $query ) { global $wpdb; $filters = ''; if ( isset( $query['post_parent'] ) ) { $filters = $wpdb->prepare( 'AND post_parent = %d ', $query['post_parent'] ); } // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared $months = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = 'feedback' $filters ORDER BY post_date DESC" ) ); // phpcs:enable return array_map( function ( $row ) { return array( 'month' => intval( $row->month ), 'year' => intval( $row->year ), ); }, $months ); } /** * Handles bulk actions for Jetpack Forms responses. * * @param WP_REST_Request $request The request sent to the WP REST API. * * @return WP_REST_Response A response object.. */ public function bulk_actions( $request ) { $action = $request->get_param( 'action' ); $post_ids = $request->get_param( 'post_ids' ); if ( $action && ! is_array( $post_ids ) ) { return new $this->error_response( __( 'Bad request', 'jetpack-forms' ), 400 ); } switch ( $action ) { case 'mark_as_spam': return $this->bulk_action_mark_as_spam( $post_ids ); case 'mark_as_not_spam': return $this->bulk_action_mark_as_not_spam( $post_ids ); case 'trash': return $this->bulk_action_trash( $post_ids ); case 'untrash': return $this->bulk_action_untrash( $post_ids ); case 'delete': return $this->bulk_action_delete_forever( $post_ids ); default: return $this->error_response( __( 'Bad request', 'jetpack-forms' ), 400 ); } } /** * Verifies that the current user has the requird capability for viewing form responses. * * @return true|WP_Error Returns true if the user has the required capability, else a WP_Error object. */ public function get_responses_permission_check() { $site_id = Manager::get_site_id(); if ( is_wp_error( $site_id ) ) { return $site_id; } if ( ! current_user_can( 'edit_pages' ) ) { return new WP_Error( 'invalid_user_permission_jetpack_form_responses', 'unauthorized', array( 'status' => rest_authorization_required_code() ) ); } return true; } /** * Marks all feedback posts matchin the given IDs as spam. * * @param array $post_ids Array of post IDs. * @return WP_REST_Response */ private function bulk_action_mark_as_spam( $post_ids ) { foreach ( $post_ids as $post_id ) { $post = get_post( $post_id ); if ( $post->post_type !== 'feedback' ) { continue; } $status = wp_update_post( array( 'ID' => $post_id, 'post_status' => 'spam', ), false, false ); if ( ! $status || is_wp_error( $status ) ) { return $this->error_response( sprintf( /* translators: %s: Post ID */ __( 'Failed to mark post as spam. Post ID: %d.', 'jetpack-forms' ), $post_id ), 500 ); } /** This action is documented in \Automattic\Jetpack\Forms\ContactForm\Admin */ do_action( 'contact_form_akismet', 'spam', get_post_meta( $post_id, '_feedback_akismet_values', true ) ); } return new WP_REST_Response( array(), 200 ); } /** * Marks all feedback posts matchin the given IDs as not spam. * * @param array $post_ids Array of post IDs. * @return WP_REST_Response */ private function bulk_action_mark_as_not_spam( $post_ids ) { foreach ( $post_ids as $post_id ) { $post = get_post( $post_id ); if ( $post->post_type !== 'feedback' ) { continue; } $status = wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish', ), false, false ); if ( ! $status || is_wp_error( $status ) ) { return $this->error_response( sprintf( /* translators: %s: Post ID */ __( 'Failed to mark post as not-spam. Post ID: %d.', 'jetpack-forms' ), $post_id ), 500 ); } /** This action is documented in \Automattic\Jetpack\Forms\ContactForm\Admin */ do_action( 'contact_form_akismet', 'ham', get_post_meta( $post_id, '_feedback_akismet_values', true ) ); } return new WP_REST_Response( array(), 200 ); } /** * Moves all feedback posts matchin the given IDs to trash. * * @param array $post_ids Array of post IDs. * @return WP_REST_Response */ private function bulk_action_trash( $post_ids ) { foreach ( $post_ids as $post_id ) { if ( ! wp_trash_post( $post_id ) ) { return $this->error_response( sprintf( /* translators: %s: Post ID */ __( 'Failed to move post to trash. Post ID: %d.', 'jetpack-forms' ), $post_id ), 500 ); } } return new WP_REST_Response( array(), 200 ); } /** * Removes all feedback posts matchin the given IDs from trash. * * @param array $post_ids Array of post IDs. * @return WP_REST_Response */ private function bulk_action_untrash( $post_ids ) { foreach ( $post_ids as $post_id ) { if ( ! wp_untrash_post( $post_id ) ) { return $this->error_response( sprintf( /* translators: %s: Post ID */ __( 'Failed to remove post from trash. Post ID: %d.', 'jetpack-forms' ), $post_id ), 500 ); } } return new WP_REST_Response( array(), 200 ); } /** * Deletes all feedback posts matchin the given IDs. * * @param array $post_ids Array of post IDs. * @return WP_REST_Response */ private function bulk_action_delete_forever( $post_ids ) { foreach ( $post_ids as $post_id ) { if ( ! wp_delete_post( $post_id ) ) { return $this->error_response( sprintf( /* translators: %s: Post ID */ __( 'Failed to delete post. Post ID: %d.', 'jetpack-forms' ), $post_id ), 500 ); } } return new WP_REST_Response( array(), 200 ); } /** * Returns a WP_REST_Response containing the given error message and code. * * @param string $message Error message. * @param int $code Error code. * @return WP_REST_Response */ private function error_response( $message, $code ) { return new WP_REST_Response( array( 'error' => $message ), $code ); } } if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { wpcom_rest_api_v2_load_plugin( 'Automattic\Jetpack\Forms\WPCOM_REST_API_V2_Endpoint_Forms' ); }
Fatal error: Uncaught Error: Class "Automattic\Jetpack\Forms\WPCOM_REST_API_V2_Endpoint_Forms" not found in /htdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-forms/src/class-jetpack-forms.php:39 Stack trace: #0 /htdocs/wp-content/plugins/jetpack/modules/contact-form.php(26): Automattic\Jetpack\Forms\Jetpack_Forms::load_contact_form() #1 /htdocs/wp-content/plugins/jetpack/class.jetpack.php(1834): include_once('/htdocs/wp-cont...') #2 /htdocs/wp-includes/class-wp-hook.php(324): Jetpack::load_modules('') #3 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #4 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #5 /htdocs/wp-settings.php(559): do_action('plugins_loaded') #6 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #7 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #8 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #9 /htdocs/index.php(17): require('/htdocs/wp-blog...') #10 {main} thrown in /htdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-forms/src/class-jetpack-forms.php on line 39