0) { foreach ($fields as $field_data) { mailerlite_wp_create_custom_field($field_data); } } } return true; } /** * Get integration custom fields * * @return array */ function woo_ml_get_integration_custom_fields($api_type) { if ($api_type !== ApiType::CURRENT) { return [ 'woo_orders_count' => [ 'title' => 'Woo Orders Count', 'type' => 'NUMBER' ], 'woo_total_spent' => [ 'title' => 'Woo Total Spent', 'type' => 'NUMBER' ], 'woo_last_order' => [ 'title' => 'Woo Last Order', 'type' => 'DATE' ], 'woo_last_order_id' => [ 'title' => 'Woo Last Order ID', 'type' => 'NUMBER' ], ]; } else { $shopUrl = home_url(); $shopKey = preg_replace('/[^A-Za-z0-9 ]/', '', $shopUrl); $shop_name = get_bloginfo('name'); if (empty($shop_name)) { $shop_name = $shopUrl; } return [ $shopKey . '_total_spent' => [ 'key' => $shopKey, 'name' => $shop_name, 'title' => 'Total spent', 'type' => 'number', ], $shopKey . '_orders_count' => [ 'key' => $shopKey, 'name' => $shop_name, 'title' => 'Orders count', 'type' => 'number', ], $shopKey . '_accepts_marketing' => [ 'key' => $shopKey, 'name' => $shop_name, 'title' => 'Accepts marketing', 'type' => 'number', ], ]; } } function woo_ml_old_integration() { return ! get_option('new_plugin_enabled'); } function woo_ml_shop_not_active() { return get_option('ml_shop_not_active'); } /** * Get subscriber additional fields * * @return array */ function woo_ml_get_additional_fields() { return [ 'subscriber_language' => [ 'title' => 'Subscriber Language', 'type' => 'text', ], ]; } function woo_ml_setup_additional_sub_fields() { $mailerliteClient = new PlatformAPI(MAILERLITE_WP_API_KEY); $ml_fields = $mailerliteClient->getFields(); $sub_fields = woo_ml_get_additional_fields(); if (is_array($ml_fields)) { foreach ($ml_fields as $ml_field) { $ml_field = (array)$ml_field; if (isset($ml_field['key']) && isset($sub_fields[$ml_field['key']])) { unset($sub_fields[$ml_field['key']]); } } if (sizeof($sub_fields) > 0) { foreach ($sub_fields as $field_data) { woo_ml_create_additional_sub_fields($field_data); } } } } function woo_ml_create_additional_sub_fields($field_data) { if ( ! ApiSettings::getInstance()->wpApiKeyExists()) { return false; } if ( ! isset($field_data['title']) || ! isset($field_data['type'])) { return false; } try { $mailerliteClient = new PlatformAPI(MAILERLITE_WP_API_KEY); return $mailerliteClient->createField($field_data['title'], $field_data['type']); } catch (Exception $e) { return false; } }