LLMS_Forms::create( string $location_id, bool $recreate = false )
Create a form for a given location with the provided data.
Parameters Parameters
- $location_id
-
(string) (Required) Location id.
- $recreate
-
(bool) (Optional) If
trueand the form already exists, will recreate the existing form using the existing form's id.Default value: false
Return Return
(int|false) Returns the created/update form post ID on success. If the location doesn't exist, returns false. If the form already exists and $recreate is false will return false.
Source Source
File: includes/forms/class-llms-forms.php
public function create( $location_id, $recreate = false ) {
if ( ! $this->is_location_valid( $location_id ) ) {
return false;
}
$locs = $this->get_locations();
$data = $locs[ $location_id ];
$existing = $this->get_form_post( $location_id );
// Form already exists and we haven't requested an update.
if ( false !== $existing && ! $recreate ) {
return false;
}
$args = array(
'ID' => $existing ? $existing->ID : 0,
'post_content' => LLMS_Form_Templates::get_template( $location_id ),
'post_status' => 'publish',
'post_title' => $data['title'],
'post_type' => $this->get_post_type(),
'meta_input' => $data['meta'],
'post_author' => $existing ? $existing->post_author : LLMS_Install::get_can_install_user_id(),
);
/**
* Filter arguments used to install a new form.
*
* @since 5.0.0
*
* @param array $args Array of arguments to be passed to wp_insert_post
* @param string $location_id Location ID/name.
* @param array $data Array of location information from LLMS_Forms::get_locations().
*/
$args = apply_filters( 'llms_forms_install_post_args', $args, $location_id, $data );
return wp_insert_post( $args );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |