| @@ -1,0 +1,41 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\MailPoet\Functions | |
| 6 | + * @since 1.0.0 | |
| 7 | + */ | |
| 8 | +// Exit if accessed directly | |
| 9 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Options callback for lists | |
| 13 | + * | |
| 14 | + * @since 1.0.0 | |
| 15 | + * | |
| 16 | + * @param stdClass $field | |
| 17 | + * | |
| 18 | + * @return array | |
| 19 | + */ | |
| 20 | +function automatorwp_mailpoet_lists_options_cb( $field ) { | |
| 21 | + | |
| 22 | + $none_value = ''; | |
| 23 | + $none_label = __( 'a list', 'automatorwp' ); | |
| 24 | + $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); | |
| 25 | + | |
| 26 | + if ( ! class_exists( '\MailPoet\API\API' ) ) { | |
| 27 | + return $options; | |
| 28 | + } | |
| 29 | + | |
| 30 | + $mailpoet = \MailPoet\API\API::MP( 'v1' ); | |
| 31 | + $lists = $mailpoet->getLists(); | |
| 32 | + | |
| 33 | + if( is_array( $lists ) ) { | |
| 34 | + foreach( $lists as $list ) { | |
| 35 | + $options[$list['id']] = $list['name']; | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + return $options; | |
| 40 | + | |
| 41 | +} | |