| @@ -1,0 +1,105 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\Mail_Mint\Functions | |
| 6 | + * @author AutomatorWP <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | + | |
| 10 | +// Exit if accessed directly | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) exit; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Options callback for select2 fields assigned to tags | |
| 15 | + * | |
| 16 | + * @since 1.0.0 | |
| 17 | + * | |
| 18 | + * @param stdClass $field | |
| 19 | + * | |
| 20 | + * @return array | |
| 21 | + */ | |
| 22 | +function automatorwp_mail_mint_options_cb_tag( $field ) { | |
| 23 | + | |
| 24 | + // Setup vars | |
| 25 | + $value = $field->escaped_value; | |
| 26 | + $none_value = 'any'; | |
| 27 | + $none_label = __( 'any tag', 'automatorwp' ); | |
| 28 | + $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); | |
| 29 | + | |
| 30 | + if( ! empty( $value ) ) { | |
| 31 | + if( ! is_array( $value ) ) { | |
| 32 | + $value = array( $value ); | |
| 33 | + } | |
| 34 | + | |
| 35 | + foreach( $value as $tag_id ) { | |
| 36 | + | |
| 37 | + // Skip option none | |
| 38 | + if( $tag_id === $none_value ) { | |
| 39 | + continue; | |
| 40 | + } | |
| 41 | + | |
| 42 | + $options[$tag_id] = automatorwp_mail_mint_get_tag_name( $tag_id ); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + return $options; | |
| 47 | + | |
| 48 | +} | |
| 49 | + | |
| 50 | +/** | |
| 51 | + * Get all Mail Mint tags | |
| 52 | + * | |
| 53 | + * @since 1.0.0 | |
| 54 | + * | |
| 55 | + * @return array | |
| 56 | + */ | |
| 57 | +function automatorwp_mail_mint_get_tags() { | |
| 58 | + | |
| 59 | + $tags = array(); | |
| 60 | + | |
| 61 | + // Bail if class does not exist | |
| 62 | + if( ! class_exists ( 'Mint\MRM\DataBase\Models\ContactGroupModel' ) ) | |
| 63 | + return; | |
| 64 | + | |
| 65 | + //Type: lists or tags | |
| 66 | + $all_tags = Mint\MRM\DataBase\Models\ContactGroupModel::get_all_lists_or_tags( 'tags' ); | |
| 67 | + | |
| 68 | + foreach ( $all_tags as $tag ) { | |
| 69 | + $tags[] = array( | |
| 70 | + 'id' => $tag['id'], | |
| 71 | + 'name' => $tag['title'], | |
| 72 | + ); | |
| 73 | + } | |
| 74 | + | |
| 75 | + return $tags; | |
| 76 | + | |
| 77 | +} | |
| 78 | + | |
| 79 | +/** | |
| 80 | +* Get the tag name | |
| 81 | +* | |
| 82 | +* @since 1.0.0 | |
| 83 | +* | |
| 84 | +* @param string $list_id | |
| 85 | +* | |
| 86 | +* @return array | |
| 87 | +*/ | |
| 88 | +function automatorwp_mail_mint_get_tag_name( $tag_id ) { | |
| 89 | + | |
| 90 | + // Empty title if no ID provided | |
| 91 | + if( absint( $tag_id ) === 0 ) { | |
| 92 | + return ''; | |
| 93 | + } | |
| 94 | + | |
| 95 | + // Bail if class does not exist | |
| 96 | + if( ! class_exists ( 'Mint\MRM\DataBase\Models\ContactGroupModel' ) || ! class_exists ( 'MRM\Common\MrmCommon' ) ) | |
| 97 | + return; | |
| 98 | + | |
| 99 | + $all_tags = Mint\MRM\DataBase\Models\ContactGroupModel::get_all_lists_or_tags( 'tags' ); | |
| 100 | + | |
| 101 | + $tag = MRM\Common\MrmCommon::search_for_id( $tag_id, $all_tags ); | |
| 102 | + | |
| 103 | + return $tag['title']; | |
| 104 | + | |
| 105 | +} | |