ERE post_status IN ( $post_statuses ) AND post_type IN ( $post_types ) ) AS ids
INNER JOIN $wpdb->posts as p ON ids.ID = p.ID
WHERE p.post_content REGEXP '\\\[wpforms|wpforms/form-selector'"
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
return array_map( 'intval', $ids );
}
/**
* Filters the SELECT clause of the query.
* Get a minimal set of fields from the post record.
*
* @since 1.7.4
*
* @param string $fields The SELECT clause of the query.
* @param WP_Query $query The WP_Query instance (passed by reference).
*
* @return string
*
* @noinspection PhpUnusedParameterInspection
*/
public function posts_fields_filter( $fields, $query ) {
global $wpdb;
$fields_arr = [ 'ID', 'post_title', 'post_status', 'post_type', 'post_content', 'post_name' ];
$fields_arr = array_map(
static function ( $field ) use ( $wpdb ) {
return "$wpdb->posts." . $field;
},
$fields_arr
);
return implode( ', ', $fields_arr );
}
/**
* Get form locations.
*
* @since 1.7.4
*
* @param int[] $post_ids Post IDs.
*
* @return array
*/
private function get_form_locations( $post_ids ) { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
/**
* Block caching here, as caching produces unneeded db requests in
* update_object_term_cache() and update_postmeta_cache().
*/
$query_args = [
'post_type' => $this->locator->get_post_types(),
'post_status' => $this->locator->get_post_statuses(),
'post__in' => $post_ids,
'no_found_rows' => true,
'posts_per_page' => - 1,
'cache_results' => false,
];
// Get form locations by chunks to prevent out of memory issue.
$post_id_chunks = array_chunk( $post_ids, self::CHUNK_SIZE );
$locations = [];
add_filter( 'posts_fields', [ $this, 'posts_fields_filter' ], 10, 2 );
foreach ( $post_id_chunks as $post_id_chunk ) {
$query_args['post__in'] = $post_id_chunk;
$query = new WP_Query( $query_args );
$locations = $this->get_form_locations_from_posts( $query->posts, $locations );
}
remove_filter( 'posts_fields', [ $this, 'posts_fields_filter' ] );
return $locations;
}
/**
* Get locations from posts.
*
* @since 1.7.4
*
* @param WP_Post[] $posts Posts.
* @param array $locations Locations.
*
* @return array
*/
private function get_form_locations_from_posts( $posts, $locations = [] ) {
$home_url = home_url();
foreach ( $posts as $post ) {
$form_ids = $this->locator->get_form_ids( $post->post_content );
if ( ! $form_ids ) {
continue;
}
$url = get_permalink( $post );
$url = ( $url === false || is_wp_error( $url ) ) ? '' : $url;
$url = str_replace( $home_url, '', $url );
foreach ( $form_ids as $form_id ) {
$locations[] = [
'type' => $post->post_type,
'title' => $post->post_title,
'form_id' => $form_id,
'id' => $post->ID,
'status' => $post->post_status,
'url' => $url,
];
}
}
return $locations;
}
/**
* Search in standalone forms.
*
* @since 1.8.7
*
* @return array
*/
private function search_in_standalone_forms(): array {
global $wpdb;
$location_types = [];
foreach ( Locator::STANDALONE_LOCATION_TYPES as $location_type ) {
$location_types[] = '"' . $location_type . '_enable":"1"';
}
$regexp = implode( '|', $location_types );
$post_statuses = wpforms_wpdb_prepare_in( $this->locator->get_post_statuses() );
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$standalone_forms = $wpdb->get_results(
"SELECT ID, post_content, post_status
FROM $wpdb->posts
WHERE post_status IN ( $post_statuses ) AND
post_type = 'wpforms' AND
post_content REGEXP '$regexp';"
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$locations = [];
foreach ( $standalone_forms as $standalone_form ) {
$form_data = json_decode( $standalone_form->post_content, true );
$locations[] = $this->locator->build_standalone_location(
(int) $standalone_form->ID,
$form_data,
$standalone_form->post_status
);
}
return $locations;
}
/**
* Get form location metas.
*
* @param array $locations Locations.
*
* @since 1.7.4
*
* @return array
*/
private function get_form_location_metas( $locations ) {
$metas = [];
foreach ( $locations as $location ) {
if ( empty( $location['form_id'] ) ) {
continue;
}
$metas[ $location['form_id'] ][] = $location;
}
return $metas;
}
}
Fatal error: Uncaught Error: Class 'WPForms\Tasks\Actions\FormsLocatorScanTask' not found in /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Forms/Locator.php:180
Stack trace:
#0 /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/WPForms.php(415): WPForms\Forms\Locator->init()
#1 /home/yoldasm2/public_html/wp-includes/class-wp-hook.php(324): WPForms\WPForms->WPForms\{closure}('')
#2 /home/yoldasm2/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#3 /home/yoldasm2/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#4 /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/WPForms.php(328): do_action('wpforms_loaded')
#5 /home/yoldasm2/public_html/wp-includes/class-wp-hook.php(324): WPForms\WPForms->objects('')
#6 /home/yoldasm2/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#7 /home/yoldasm2/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#8 /home/yoldasm2/public_html/wp-settings.php( in /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Forms/Locator.php on line 180