madmimi = new MadMimi(mal_madmimi_username(), mal_madmimi_api_key() );
$this->set_madmimi_lists();
$this->name = 'madmimi_audience_list';
$this->label = __('MadMimi Audience List');
$this->category = __("Choice",'acf'); // Basic, Content, Choice, etc
$this->defaults = array(
// add default here to merge into your field.
// This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg:
//'preview_size' => 'thumbnail'
);
// do not delete!
parent::__construct();
// settings
$this->settings = array(
'path' => apply_filters('acf/helpers/get_path', __FILE__),
'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
'version' => '1.0.0'
);
}
function set_madmimi_lists() {
$list_array = get_transient( 'mal_audience_lists' );
if( empty( $list_array ) ) {
$lists = $this->madmimi->Lists();
$lists = new SimpleXMLElement( $lists );
$list_array = array();
foreach( $lists as $list ) {
$list = (array) $list;
if( empty( $list['@attributes']['display_name'] ) ) {
$list['@attributes']['display_name'] = $list['@attributes']['name'];
}
$list_array[$list['@attributes']['id']] = $list['@attributes'];
}
set_transient( 'mal_audience_lists', $list_array, HOUR_IN_SECONDS );
}
$this->madmimi_lists = $list_array;
}
/*
* create_options()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like below) to save extra data to the $field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field - an array holding all the field's data
*/
function create_options( $field )
{
// defaults?
/*
$field = array_merge($this->defaults, $field);
*/
// key is needed in the field names to correctly save the data
$key = $field['name'];
// Create Field Options HTML
?>