| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions |
| 4 |
* |
| 5 |
* @package AutomatorWP\Thrive_Leads\Functions |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
// Exit if accessed directly |
| 9 |
if( !defined( 'ABSPATH' ) ) exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* Options callback for select2 fields assigned to forms |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
* |
| 16 |
* @param stdClass $field |
| 17 |
* |
| 18 |
* @return array |
| 19 |
*/ |
| 20 |
function automatorwp_thrive_leads_options_cb_form( $field ) { |
| 21 |
|
| 22 |
// Setup vars |
| 23 |
$value = $field->escaped_value; |
| 24 |
$none_value = 'any'; |
| 25 |
$none_label = __( 'any form', 'automatorwp' ); |
| 26 |
$options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); |
| 27 |
|
| 28 |
if( ! empty( $value ) ) { |
| 29 |
if( ! is_array( $value ) ) { |
| 30 |
$value = array( $value ); |
| 31 |
} |
| 32 |
|
| 33 |
foreach( $value as $form_id ) { |
| 34 |
|
| 35 |
// Skip option none |
| 36 |
if( $form_id === $none_value ) { |
| 37 |
continue; |
| 38 |
} |
| 39 |
|
| 40 |
$options[$form_id] = automatorwp_thrive_leads_get_form_title( $form_id ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
return $options; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get the form title |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* |
| 53 |
* @return string|null |
| 54 |
*/ |
| 55 |
function automatorwp_thrive_leads_get_forms( ) { |
| 56 |
|
| 57 |
$type_forms = get_posts( |
| 58 |
array( |
| 59 |
'post_type' => 'tve_form_type', |
| 60 |
'posts_per_page' => -1, |
| 61 |
'post_status' => 'any', |
| 62 |
) |
| 63 |
); |
| 64 |
|
| 65 |
$all_forms = array(); |
| 66 |
|
| 67 |
foreach ( $type_forms as $parent ) { |
| 68 |
$forms = tve_leads_get_form_variations( $parent->ID ); |
| 69 |
|
| 70 |
foreach ( $forms as $form ) { |
| 71 |
$all_forms[ ] = array( |
| 72 |
'id' => $form['key'], |
| 73 |
'name' => $form['post_title'] |
| 74 |
); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return $all_forms; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Get the form title |
| 83 |
* |
| 84 |
* @since 1.0.0 |
| 85 |
* |
| 86 |
* @param int $form_id |
| 87 |
* |
| 88 |
* @return string|null |
| 89 |
*/ |
| 90 |
function automatorwp_thrive_leads_get_form_title( $form_id ) { |
| 91 |
|
| 92 |
// Empty title if no ID provided |
| 93 |
if( absint( $form_id ) === 0 ) { |
| 94 |
return ''; |
| 95 |
} |
| 96 |
|
| 97 |
$form = tve_leads_get_form_variation( null, $form_id ); |
| 98 |
|
| 99 |
return $form['post_title']; |
| 100 |
|
| 101 |
} |
| 102 |
|