| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Prepares a form object for export. |
| 5 |
* |
| 6 |
* @since 1.7.0 |
| 7 |
* |
| 8 |
*/ |
| 9 |
function af_export_form( $form ) { |
| 10 |
unset( $form['post_id'] ); |
| 11 |
return $form; |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
/** |
| 16 |
* Imports a form object to a form post. |
| 17 |
* A new post will be generated if none exists with the specific key. |
| 18 |
* |
| 19 |
* @since 1.7.0 |
| 20 |
* |
| 21 |
*/ |
| 22 |
function af_import_form( $form ) { |
| 23 |
$post = af_form_post_from_key( $form['key'] ); |
| 24 |
|
| 25 |
$post_id = NULL; |
| 26 |
if ( ! $post ) { |
| 27 |
$post_id = wp_insert_post(array( |
| 28 |
'post_title' => '', |
| 29 |
'post_type' => 'af_form', |
| 30 |
'post_status' => 'publish', |
| 31 |
)); |
| 32 |
|
| 33 |
if ( is_wp_error( $post_id ) ) { |
| 34 |
return false; |
| 35 |
} |
| 36 |
} else { |
| 37 |
$post_id = $post->ID; |
| 38 |
} |
| 39 |
|
| 40 |
return af_form_to_post( $form, $post_id ); |
| 41 |
} |