| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions |
| 4 |
* |
| 5 |
* @package AutomatorWP\Gravity_Kit\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_gravity_kit_options_cb_form( $field ) { |
| 21 |
|
| 22 |
// Setup vars |
| 23 |
$value = $field->escaped_value; |
| 24 |
$none_value = 'any'; |
| 25 |
$none_label = __( 'any form', 'automatorwp-gravity-kit' ); |
| 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_gravity_kit_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 |
* @param int $form_id |
| 54 |
* |
| 55 |
* @return string|null |
| 56 |
*/ |
| 57 |
function automatorwp_gravity_kit_get_form_title( $form_id ) { |
| 58 |
|
| 59 |
// Empty title if no ID provided |
| 60 |
if( absint( $form_id ) === 0 ) { |
| 61 |
return ''; |
| 62 |
} |
| 63 |
|
| 64 |
$form = RGFormsModel::get_form( $form_id ); |
| 65 |
|
| 66 |
return $form->title; |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Get entry form |
| 72 |
* |
| 73 |
* @since 1.0.0 |
| 74 |
* |
| 75 |
* @param int $entry_id The entry ID |
| 76 |
* |
| 77 |
* @return int |
| 78 |
*/ |
| 79 |
function automatorwp_gravity_kit_get_entry_form ( $entry_id ) { |
| 80 |
|
| 81 |
global $wpdb; |
| 82 |
|
| 83 |
$form_id = $wpdb->get_var( $wpdb->prepare( "SELECT form_id from {$wpdb->prefix}gf_entry WHERE id=%d", $entry_id ) ); |
| 84 |
|
| 85 |
return $form_id; |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Get entry user |
| 91 |
* |
| 92 |
* @since 1.0.0 |
| 93 |
* |
| 94 |
* @param int $entry_id The entry ID |
| 95 |
* |
| 96 |
* @return int|NULL |
| 97 |
*/ |
| 98 |
function automatorwp_gravity_kit_get_entry_user ( $entry_id ) { |
| 99 |
|
| 100 |
global $wpdb; |
| 101 |
|
| 102 |
$user_id = $wpdb->get_var( $wpdb->prepare( "SELECT created_by from {$wpdb->prefix}gf_entry WHERE id=%d", $entry_id ) ); |
| 103 |
|
| 104 |
return $user_id; |
| 105 |
|
| 106 |
} |