function AC_AutoChimpOptions() { // Stop the user if they don't have permission if (!current_user_can('add_users')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // If the upload_files POST option is set, then files are being uploaded if (isset($_POST['save_api_key'])) { // Security check check_admin_referer('mailchimpz-nonce'); $newAPIKey = $_POST['api_key']; // Update the database (save the key, but also clean out other stuff) update_option(WP88_MC_APIKEY, $newAPIKey); update_option(WP88_MC_LAST_MAIL_LIST_ERROR, ''); update_option(WP88_MC_LAST_CAMPAIGN_ERROR, ''); // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your API Key!</p></div>'; } // Save off the mailing list options here if (isset($_POST['save_mailing_list_options'])) { // Security check check_admin_referer('mailchimpz-nonce'); // Step 1: Save the mailing lists that the user wants to affect // Declare an empty string...add stuff later $selectionOption = ''; // Go through here and generate the option - a list of mailing list IDs separated by commas foreach ($_POST as $postVar) { $pos = strpos($postVar, WP88_SEARCHABLE_PREFIX); if (false === $pos) { } else { $selectionOption .= $postVar . ','; } } // Update the database update_option(WP88_MC_LISTS, $selectionOption); // Step 2: Save when the user wants to update the list AC_SetBooleanOption('on_add_subscriber', WP88_MC_ADD); AC_SetBooleanOption('on_bypass_opt_in', WP88_MC_BYPASS_OPT_IN); AC_SetBooleanOption('on_delete_subscriber', WP88_MC_DELETE); AC_SetBooleanOption('on_update_subscriber', WP88_MC_UPDATE); AC_SetBooleanOption('on_delete_member', WP88_MC_PERMANENTLY_DELETE_MEMBERS); AC_SetBooleanOption('on_send_goodbye', WP88_MC_SEND_GOODBYE); AC_SetBooleanOption('on_send_notify', WP88_MC_SEND_ADMIN_NOTIFICATION); // Step 3: Save the extra WordPress fields that the user wants to sync. global $wpUserDataArray; foreach ($wpUserDataArray as $userField) { // Encode the name of the field $fieldName = AC_EncodeUserOptionName(WP88_WORDPRESS_FIELD_MAPPING, $userField); // Now dereference the selection $fieldData = $_POST[$fieldName]; // Save the selection update_option($fieldName, $fieldData); } // Now save the special static field and the mapping $staticText = $_POST['static_select']; update_option(WP88_MC_STATIC_TEXT, $staticText); update_option(WP88_MC_STATIC_FIELD, $_POST[WP88_MC_STATIC_FIELD]); // Step 4: Save the plugin mappings. Uses the _POST hash. // This hidden field allows the user to save their mappings even when the // sync button isn't checked //if ( isset( $_POST['buddypress_running'] ) ) //if ( isset( $_POST['cimy_running'] ) ) $syncPlugins = new ACSyncPlugins(); $syncPlugins->SaveMappings(); // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your AutoChimp mailing list options.</p></div>'; } if (isset($_POST['save_campaign_options'])) { // Save off the mappings of categories to campaigns. AC_SaveCampaignCategoryMappings(WP88_CATEGORY_MAPPING_PREFIX); // Now save off the plugin mappings. $publishPlugins = new ACPublishPlugins(); $publishPlugins->SaveMappings(); // The rest is easy... AC_SetBooleanOption('on_excerpt_only', WP88_MC_CAMPAIGN_EXCERPT_ONLY); AC_SetBooleanOption('on_send_now', WP88_MC_SEND_NOW); AC_SetBooleanOption('on_create_once', WP88_MC_CREATE_CAMPAIGN_ONCE); // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your AutoChimp campaign options.</p></div>'; } // Deleting campaign rows is a little more sophisticated. Have to loop through // looking for rows that may have been deleted. Only one may be deleted at a // time. foreach ($_POST as $key => $value) { // If a match was found, then the row to delete is in $value and the // first part of the $key will determine the name of the DB field. // Following this naming convention, there's no need to forward the // call to a plugin. if (FALSE !== strpos($key, WP88_DELETE_MAPPING_SUFFIX)) { // The value will hold the beginning of the name of the DB option. // Just tack on the suffix and delete. Done. delete_option($value . WP88_CATEGORY_SUFFIX); delete_option($value . WP88_LIST_SUFFIX); delete_option($value . WP88_GROUP_SUFFIX); delete_option($value . WP88_TEMPLATE_SUFFIX); break; } } if (isset($_POST['save_plugin_options'])) { // These are hardcoded as part of AutoChimp AC_SetBooleanOption('on_fix_regplus', WP88_MC_FIX_REGPLUS); AC_SetBooleanOption('on_fix_regplusredux', WP88_MC_FIX_REGPLUSREDUX); // Plugins for AutoChimp are handled here. $plugins = new ACSyncPlugins(); $plugins->SavePluginSettings(); $plugins = new ACContentPlugins(); $plugins->SavePluginSettings(); $plugins = new ACPublishPlugins(); $plugins->SavePluginSettings(); // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your AutoChimp plugin options.</p></div>'; } // The file that will handle uploads is this one (see the "if" above) $action_url = $_SERVER['REQUEST_URI']; require_once 'autochimp-settings.php'; }
public function SaveMappings() { AC_Log('Attempting to save mappings for Events Manager campaigns...'); AC_SaveCampaignCategoryMappings(EVENTS_MANAGER_MAPPING_PREFIX); }
function AC_AutoChimpOptions() { // Stop the user if they don't have permission if (!current_user_can('add_users')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // If the upload_files POST option is set, then files are being uploaded if (isset($_POST['save_api_key'])) { // Security check check_admin_referer('mailchimpz-nonce'); $newAPIKey = $_POST['api_key']; // Update the database (save the key, but also clean out other stuff) update_option(WP88_MC_APIKEY, $newAPIKey); update_option(WP88_MC_LAST_MAIL_LIST_ERROR, ''); update_option(WP88_MC_LAST_CAMPAIGN_ERROR, ''); // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your API Key!</p></div>'; } // Save off the mailing list options here if (isset($_POST['save_mailing_list_options'])) { // Security check check_admin_referer('mailchimpz-nonce'); // Step 1: Save the mailing lists that the user wants to affect // Declare an empty string...add stuff later $selectionOption = ''; // Go through here and generate the option - a list of mailing list IDs separated by commas foreach ($_POST as $postVar) { $pos = strpos($postVar, WP88_SEARCHABLE_PREFIX); if (false === $pos) { } else { $selectionOption .= $postVar . ','; } } // Update the database update_option(WP88_MC_LISTS, $selectionOption); // Step 2: Save when the user wants to update the list AC_SetBooleanOption('on_add_subscriber', WP88_MC_ADD); AC_SetBooleanOption('on_bypass_opt_in', WP88_MC_BYPASS_OPT_IN); AC_SetBooleanOption('on_delete_subscriber', WP88_MC_DELETE); AC_SetBooleanOption('on_update_subscriber', WP88_MC_UPDATE); AC_SetBooleanOption('on_delete_member', WP88_MC_PERMANENTLY_DELETE_MEMBERS); AC_SetBooleanOption('on_send_goodbye', WP88_MC_SEND_GOODBYE); AC_SetBooleanOption('on_send_notify', WP88_MC_SEND_ADMIN_NOTIFICATION); // Step 3: Save the extra WordPress fields that the user wants to sync. global $wpUserDataArray; foreach ($wpUserDataArray as $userField) { // Encode the name of the field $fieldName = AC_EncodeUserOptionName(WP88_WORDPRESS_FIELD_MAPPING, $userField); // Now dereference the selection $fieldData = $_POST[$fieldName]; // Save the selection update_option($fieldName, $fieldData); } // Now save the special static field and the mapping $staticText = $_POST['static_select']; update_option(WP88_MC_STATIC_TEXT, $staticText); update_option(WP88_MC_STATIC_FIELD, $_POST[WP88_MC_STATIC_FIELD]); // Step 4: // This hidden field allows the user to save their mappings even when the // sync button isn't checked if (isset($_POST['buddypress_running'])) { // Save the mappings of BuddyPress XProfile fields to MailChimp Merge Vars. // Uses the $_POST array. AC_SaveBuddyPressMappings(); } // Step 5: // Another hidden field for Cimy. if (isset($_POST['cimy_running'])) { require_once 'cimy_integration.php'; // Save Cimy settings - uses the $_POST array. AC_SaveCimyMappings(); } // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your AutoChimp mailing list options.</p></div>'; } if (isset($_POST['save_campaign_options'])) { // Save off the mappings of categories to campaigns. AC_SaveCampaignCategoryMappings(); // The rest is easy... AC_SetBooleanOption('on_excerpt_only', WP88_MC_CAMPAIGN_EXCERPT_ONLY); AC_SetBooleanOption('on_send_now', WP88_MC_SEND_NOW); AC_SetBooleanOption('on_create_once', WP88_MC_CREATE_CAMPAIGN_ONCE); // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your AutoChimp campaign options.</p></div>'; } if (isset($_POST['save_plugin_options'])) { AC_SetBooleanOption('on_fix_regplus', WP88_MC_FIX_REGPLUS); AC_SetBooleanOption('on_fix_regplusredux', WP88_MC_FIX_REGPLUSREDUX); AC_SetBooleanOption('on_sync_buddypress', WP88_MC_SYNC_BUDDYPRESS); AC_SetBooleanOption('on_sync_cimy', WP88_MC_SYNC_CIMY); AC_SetBooleanOption('on_integrate_viper', WP88_MC_INTEGRATE_VIPER); AC_SetBooleanOption('on_show_title', WP88_MC_VIDEO_SHOW_TITLE); AC_SetBooleanOption('on_show_border', WP88_MC_VIDEO_SHOW_BORDER); AC_SetBooleanOption('on_trim_border', WP88_MC_VIDEO_TRIM_BORDER); AC_SetBooleanOption('on_show_ratings', WP88_MC_VIDEO_SHOW_RATINGS); AC_SetBooleanOption('on_show_num_views', WP88_MC_VIDEO_SHOW_NUM_VIEWS); // Tell the user print '<div id="message" class="updated fade"><p>Successfully saved your AutoChimp plugin options.</p></div>'; } // The file that will handle uploads is this one (see the "if" above) $action_url = $_SERVER['REQUEST_URI']; require_once '88-autochimp-settings.php'; }