Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Forms::get_core_forms( string $return = 'posts',  $use_cache = true )

Retrieves only core forms.


Description Description

When there are multiple forms for a location, the core form is identified as the one with the lowest ID.


Top ↑

Parameters Parameters

$return

(string) (Optional) What to return: 'posts', for an array of WP_Post; 'ids' for an array of WP_Post ids.

Default value: 'posts'


Top ↑

Return Return

(WP_Post[]|int[])


Top ↑

Source Source

File: includes/forms/class-llms-forms.php

	private function get_core_forms( $return = 'posts', $use_cache = true ) {

		global $wpdb;

		$forms_cache_key = 'posts' === $return ? 'llms_core_forms' : 'llms_core_form_ids';
		$forms           = $use_cache ? wp_cache_get( $forms_cache_key ) : false;

		if ( false !== $forms ) {
			return $forms;
		}

		$locations              = array_keys( $this->get_locations() );
		$locations_placeholders = implode( ',', array_fill( 0, count( $locations ), '%s' ) );
		$prepare_values         = array_merge( array( $this->get_post_type() ), $locations );

		$query = "
SELECT MIN({$wpdb->posts}.ID) AS ID
FROM $wpdb->posts
INNER JOIN {$wpdb->postmeta} AS locations ON {$wpdb->posts}.ID = locations.post_id AND locations.meta_key='_llms_form_location'
INNER JOIN {$wpdb->postmeta} AS is_cores ON {$wpdb->posts}.ID = is_cores.post_id AND is_cores.meta_key='_llms_form_is_core'
WHERE {$wpdb->posts}.post_type = %s
AND locations.meta_value IN ({$locations_placeholders})
AND is_cores.meta_value = 'yes'
GROUP BY locations.meta_value";

		$form_ids = $wpdb->get_col(
			$wpdb->prepare(
				$query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- It is prepared.
				$prepare_values
			)
		);

		$form_ids = array_map( 'absint', $form_ids );
		$forms    = 'post' === $return ? array_map( 'get_post', $form_ids ) : $form_ids;

		wp_cache_set( $forms_cache_key, $forms );

		return $forms;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.