types
4 years ago
base-form-action.php
4 years ago
form-actions-manager.php
4 years ago
get-form-data.php
4 years ago
import-form-trait.php
4 years ago
import-form-trait.php
34 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Form_Actions; |
| 5 | |
| 6 | |
| 7 | trait Import_Form_Trait { |
| 8 | |
| 9 | /** |
| 10 | * Import form by data |
| 11 | * |
| 12 | * @param array $form_data [description] |
| 13 | * @return [type] [description] |
| 14 | */ |
| 15 | public function import_form( $form_data = array() ) { |
| 16 | |
| 17 | $form_data = wp_parse_args( $form_data, array( |
| 18 | 'post_title' => 'New form', |
| 19 | 'post_status' => 'publish', |
| 20 | ) ); |
| 21 | |
| 22 | $post_id = wp_insert_post( array_merge( $form_data, array( |
| 23 | 'post_type' => $this->post_type() |
| 24 | ) ) ); |
| 25 | |
| 26 | if ( is_wp_error( $post_id ) ) { |
| 27 | wp_die( $post_id->get_error_message(), 'Error' ); |
| 28 | } |
| 29 | |
| 30 | return $post_id; |
| 31 | |
| 32 | } |
| 33 | |
| 34 | } |