| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions |
| 4 |
* |
| 5 |
* @package AutomatorWP\JetEngine\Functions |
| 6 |
* @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Get JetEngine post type |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @return array |
| 18 |
*/ |
| 19 |
function automatorwp_jetengine_options_cb_post_type( $field ) { |
| 20 |
|
| 21 |
// Setup vars |
| 22 |
$value = $field->escaped_value; |
| 23 |
$none_value = 'any'; |
| 24 |
$none_label = __( 'any type', 'automatorwp' ); |
| 25 |
$options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); |
| 26 |
|
| 27 |
$post_types_obj = jet_engine()->cpt; |
| 28 |
$post_types = $post_types_obj->get_items(); |
| 29 |
|
| 30 |
foreach ( $post_types as $post_type ) { |
| 31 |
|
| 32 |
if ( ! empty( $post_type['id'] ) && ! empty( $post_type['slug'] ) ) { |
| 33 |
|
| 34 |
$options[$post_type['slug']] = $post_type['labels']['name']; |
| 35 |
|
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
return $options; |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Check JetEngine post type |
| 45 |
* |
| 46 |
* @since 1.0.0 |
| 47 |
* |
| 48 |
* @param object $post Post data |
| 49 |
* |
| 50 |
* @return bool |
| 51 |
*/ |
| 52 |
function automatorwp_jetengine_check_type( $post ) { |
| 53 |
|
| 54 |
$array_types = array(); |
| 55 |
|
| 56 |
// Get JetEngine post types |
| 57 |
$post_types_obj = jet_engine()->cpt; |
| 58 |
$post_types = $post_types_obj->get_items(); |
| 59 |
|
| 60 |
foreach( $post_types as $post_type ) { |
| 61 |
$array_types[] = $post_type['slug']; |
| 62 |
} |
| 63 |
|
| 64 |
// Bail if the post is not a JetEngine type |
| 65 |
if ( !in_array( $post->post_type, $array_types ) ){ |
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
return true; |
| 70 |
} |