| @@ -1,0 +1,90 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\MyCred\Functions | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Get point types from MyCred | |
| 14 | + * | |
| 15 | + * @since 1.0.0 | |
| 16 | + * | |
| 17 | + * @return array | |
| 18 | + */ | |
| 19 | +function automatorwp_mycred_get_point_types( ) { | |
| 20 | + | |
| 21 | + $options = array(); | |
| 22 | + | |
| 23 | + $point_types = mycred_get_types(); | |
| 24 | + | |
| 25 | + foreach ( $point_types as $point_type => $label ){ | |
| 26 | + | |
| 27 | + $options[] = array( | |
| 28 | + 'id' => $point_type, | |
| 29 | + 'name' => $label, | |
| 30 | + ); | |
| 31 | + | |
| 32 | + } | |
| 33 | + | |
| 34 | + return $options; | |
| 35 | + | |
| 36 | +} | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * Get point type from MyCred | |
| 40 | + * | |
| 41 | + * @since 1.0.0 | |
| 42 | + * | |
| 43 | + * @param stdClass $field | |
| 44 | + * | |
| 45 | + * @return array | |
| 46 | + */ | |
| 47 | +function automatorwp_mycred_options_cb_point_type( $field ) { | |
| 48 | + | |
| 49 | + // Setup vars | |
| 50 | + $value = $field->escaped_value; | |
| 51 | + $none_value = 'any'; | |
| 52 | + $none_label = __( 'any point type', 'automatorwp-pro' ); | |
| 53 | + $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); | |
| 54 | + | |
| 55 | + if( ! empty( $value ) ) { | |
| 56 | + if( ! is_array( $value ) ) { | |
| 57 | + $value = array( $value ); | |
| 58 | + } | |
| 59 | + | |
| 60 | + foreach( $value as $point_type_id ) { | |
| 61 | + | |
| 62 | + // Skip option none | |
| 63 | + if( $point_type_id === $none_value ) { | |
| 64 | + continue; | |
| 65 | + } | |
| 66 | + | |
| 67 | + $options[$point_type_id] = automatorwp_mycred_get_point_type_name( $point_type_id ); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + return $options; | |
| 72 | + | |
| 73 | +} | |
| 74 | + | |
| 75 | +/** | |
| 76 | +* Get the point type name | |
| 77 | +* | |
| 78 | +* @since 1.0.0 | |
| 79 | +* | |
| 80 | +* @param string $point_type_id | |
| 81 | +* | |
| 82 | +* @return array | |
| 83 | +*/ | |
| 84 | +function automatorwp_mycred_get_point_type_name( $point_type_id ) { | |
| 85 | + | |
| 86 | + $point_type = mycred_get_point_type( $point_type_id ); | |
| 87 | + | |
| 88 | + return $point_type->singular; | |
| 89 | + | |
| 90 | +} | |