| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions |
| 4 |
* |
| 5 |
* @package AutomatorWP\WP_Simple_Pay\Includes\Functions |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
// Exit if accessed directly |
| 9 |
if( !defined( 'ABSPATH' ) ) exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* Get forms from WP Simple Pay |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
* |
| 16 |
* @param stdClass $field |
| 17 |
* |
| 18 |
* @return array |
| 19 |
*/ |
| 20 |
function automatorwp_simple_pay_options_cb_form( $field ) { |
| 21 |
|
| 22 |
// Setup vars |
| 23 |
$value = $field->escaped_value; |
| 24 |
$none_value = 'any'; |
| 25 |
$none_label = __( 'any form', 'automatorwp-wp-simple-pay' ); |
| 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_simple_pay_get_form_name( $form_id ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
return $options; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get WP Simple Pay forms |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* |
| 53 |
* @return array|false |
| 54 |
*/ |
| 55 |
function automatorwp_simple_pay_get_forms() { |
| 56 |
|
| 57 |
$forms = array(); |
| 58 |
|
| 59 |
$args = array( |
| 60 |
'numberposts' => -1, |
| 61 |
'post_type' => 'simple-pay', |
| 62 |
); |
| 63 |
|
| 64 |
$wp_simple_pay_posts = get_posts( $args ); |
| 65 |
|
| 66 |
foreach ( $wp_simple_pay_posts as $post ){ |
| 67 |
|
| 68 |
$forms[] = array( |
| 69 |
'id' => $post->ID, |
| 70 |
'name' => get_post_meta( $post->ID, '_company_name', true ), |
| 71 |
); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
return $forms; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Get WP Simple Pay form name |
| 81 |
* |
| 82 |
* @since 1.0.0 |
| 83 |
* |
| 84 |
* @param int $form_id ID form |
| 85 |
* |
| 86 |
*/ |
| 87 |
function automatorwp_simple_pay_get_form_name( $form_id ) { |
| 88 |
|
| 89 |
return get_post_meta( $form_id, '_company_name', true ); |
| 90 |
|
| 91 |
} |