LLMS_Forms::get_form_post( string $location, array $args = array() )
Retrieve the WP Post for the form at a given location.
Parameters Parameters
- $location
-
(string) (Required) Form location, one of: "checkout", "registration", or "account".
- $args
-
(array) (Optional) Additional arguments passed to the short-circuit filter.
Default value: array()
Return Return
(WP_Post|false)
Source Source
File: includes/forms/class-llms-forms.php
public function get_form_post( $location, $args = array() ) {
// @todo Add caching. This runs twice on some page loads.
/**
* Skip core lookup of the form for the request location and return a custom form post.
*
* @since 5.0.0
*
* @param null|WP_Post $post Return a WP_Post object to short-circuit default lookup query.
* @param string $location Form location. Either "checkout", "registration", or "account".
* @param array $args Additional custom arguments.
*/
$post = apply_filters( 'llms_get_form_post_pre_query', null, $location, $args );
if ( is_a( $post, 'WP_Post' ) ) {
return $post;
}
$query = new WP_Query(
array(
'post_type' => $this->get_post_type(),
'posts_per_page' => 1,
'no_found_rows' => true,
// Only show published forms to end users but allow admins to "preview" drafts.
'post_status' => current_user_can( $this->get_capability() ) ? array( 'publish', 'draft' ) : 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_llms_form_location',
'value' => $location,
),
array(
'key' => '_llms_form_is_core',
'value' => 'yes',
),
),
)
);
$post = $query->have_posts() ? $query->posts[0] : false;
/**
* Filters the returned `llms_form` post object
*
* @since 5.0.0
*
* @param WP_Post|boolean $post The post object of the form or `false` if no form could be located.
* @param string $location Form location. Either "checkout", "registration", or "account".
* @param array $args Additional custom arguments.
*/
return apply_filters( 'llms_get_form_post', $post, $location, $args );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |