public static function OnPublishEventsManagerPostType($postID) { AC_Log("A custom post type from Events Manager was published with ID {$postID}. Forwarding to AC_OnPublishPost()."); AC_OnPublishPost($postID); }
public function SyncData(&$merge_vars, $userID) { $syncPlugins = $this->GetPluginClasses($this->GetType()); foreach ($syncPlugins as $plugin) { if ($plugin::GetInstalled() && $plugin::GetUsePlugin()) { $sync = new $plugin(); AC_Log("About to sync data for the {$plugin} plugin."); $data = $sync->FetchMappedData($userID); AC_AddUserFieldsToMergeArray($merge_vars, $data); } } }
function AC_UpdateCampaignCategoryMappings() { // Need to query data in the BuddyPress extended profile table global $wpdb; // Get this site's categories $categories = get_categories('hide_empty=0&orderby=name'); // Data counter $counter = 1; $newIndex = 0; // Pull all of the mappings from the DB and update the option name. There // will be only one row for each category, so an index of 0 is safe. $options_table_name = $wpdb->prefix . 'options'; $sql = "SELECT option_name,option_value FROM {$options_table_name} WHERE option_name LIKE '" . WP88_CATEGORY_LIST_MAPPING . "%' ORDER BY option_name"; $fields = $wpdb->get_results($sql); if ($fields) { foreach ($fields as $field) { $data = AC_DecodeUserOptionName(WP88_CATEGORY_LIST_MAPPING, $field->option_name); $catInfo = explode('&', $data); // Set a suffix. Will be either "list", "group", or "template". The // original mapping didn't include "list". $suffix = '_list'; if (isset($catInfo[1])) { $suffix = "_{$catInfo['1']}"; } // Inefficient, but done once. This is necessary because AutoChimp // foolishly used to store the category name instead of slug in the // option_name. So, this code looks up the category by name and // finds the slug and writes that. foreach ($categories as $category) { // Look for a match. if (0 === strcmp($catInfo[0], $category->name)) { // Generate the new name and save it. $newName = AC_EncodeUserOptionName(WP88_CATEGORY_MAPPING_PREFIX, $newIndex . $suffix); update_option($newName, $field->option_value); AC_Log("Migrated {$field->option_value} from {$field->option_name} to {$newName}."); // Note that in 2.02 and earlier, there were three rows per // mapping. This needs to be translated into the new four // rows per mapping. So, when "_list" is encountered, just // take the time to write out "_category" too. if (0 === strcmp($suffix, '_list')) { $newName = AC_EncodeUserOptionName(WP88_CATEGORY_MAPPING_PREFIX, $newIndex . '_category'); update_option($newName, $category->slug); AC_Log("Migrated {$category->slug} from {$field->option_name} to {$newName}."); } } } // Update this every three passes. if (0 == $counter % 3) { $newIndex++; } $counter++; } } // Now delete the old rows. $sql = "DELETE FROM {$options_table_name} WHERE option_name LIKE '" . WP88_CATEGORY_LIST_MAPPING . "%'"; AC_Log("About to delete rows with this statement: {$sql}"); $numRows = $wpdb->query($sql); if (0 < $numRows) { AC_Log("Deleted {$numRows} from the {$options_table_name} table."); } else { AC_Log("No rows were found. Nothing deleted."); } }
public function FetchMappedData($userID) { // User data array $dataArray = array(); // Need to query data in the Wordpress options table global $wpdb; // Generate table names $optionTable = $wpdb->prefix . 'options'; // Now, see which custom fields the user wants to sync. $sql = "SELECT option_name,option_value FROM {$optionTable} WHERE option_name LIKE '" . AUTOCHIMP_WISHLIST_MEMBER_DB_FIELD_MAPPING . "%' AND option_value != '" . WP88_IGNORE_FIELD_TEXT . "'"; $fieldNames = $wpdb->get_results($sql, ARRAY_A); // Get the stored data and unserialize it $optionTable = $wpdb->prefix . 'wlm_user_options'; $sql = "SELECT option_value FROM {$optionTable} WHERE user_id={$userID} AND option_name='wpm_useraddress'"; $unserialized = $wpdb->get_var($sql); $data = unserialize($unserialized); // And finally, get the user data for each field name. foreach ($fieldNames as $field) { if ($this->FilterUnusedFields($field['option_name'])) { continue; } $optionName = AC_DecodeUserOptionName(AUTOCHIMP_WISHLIST_MEMBER_DB_FIELD_MAPPING, $field['option_name']); $value = $data[$optionName]; $dataArray[] = array("name" => $optionName, "tag" => $field['option_value'], "value" => $value); } AC_Log($dataArray); return $dataArray; }
function AC_OnPublishPost($postID) { // Get the info on this post $post = get_post($postID); $categories = AC_AssembleTermsArray(get_the_category($postID)); // Potentially several categories // Need to have the "Any" category for the big foreach below to work. Add it // here. $categories['Any'] = 'any'; if (empty($categories)) { AC_Log("There is no standard category for post {$postID}. Searching for a third-party plugin category."); // Now, search for custom categories (actually taxonomy terms) in the // various Publish plugins. $publishPlugins = new ACPublishPlugins(); $pluginCollection = $publishPlugins->GetPluginClasses($publishPlugins->GetType()); foreach ($pluginCollection as $plugin) { if ($plugin::GetInstalled() && $plugin::GetUsePlugin()) { $newTerms = AC_AssembleTermsArray($plugin::GetTerms($postID)); foreach ($newTerms as $name => $slum) { $categories[$name] = $slum; } } // If a category was found, break out. if (!empty($categories)) { AC_Log("Found additional categories through the plugin {$plugin}."); } } } AC_Log("Attempting to create a campaign for post ID {$postID}."); if (!empty($categories)) { AC_Log($categories); } // If it matches the user's category choice or is "Any" category, then // do the work. This needs to be a loop because a post can belong to // multiple categories. global $wpdb; foreach ($categories as $categoryName => $categorySlug) { // Do a SQL lookup of all category rows that match this category slug. NOTE that // the option for the "Any" category is in this SQL string. $options_table_name = $wpdb->prefix . 'options'; $sql = "SELECT option_name,option_value FROM {$options_table_name} WHERE option_name LIKE 'wp88_mc_%' AND (option_value = '{$categorySlug}' OR option_value = '" . WP88_ANY . "')"; $fields = $wpdb->get_results($sql); if ($fields) { foreach ($fields as $field) { // NOTE: This approach currently does have the problem that if a category // and a plugin's term have the same slug, then campaigns could go to the // wrong place. This is fairly unlikely, but this leak needs to be plugged // with an improved architecture here. // // This can happen because the above SQL statement does not discriminate // between categories or terms. The prefix part of the string and the index // can easily differ while the category slug is the same. // Split the results into an array which contains info about this mapping $info = explode('_', $field->option_name); // The last part of $info should contain the word "category". It's possible // that other rows will be picked up (like when the option value is "Any", // the "group" option will be picked up too since it can have an "Any" value) // so skip those here. if (0 !== strcmp($info[4], 'category')) { continue; } // Yank off the "category" from the tail of each string and replace it with the // other values, then query them. $categoryMailingList = get_option(str_replace(WP88_CATEGORY_SUFFIX, WP88_LIST_SUFFIX, $field->option_name)); $categoryGroupName = get_option(str_replace(WP88_CATEGORY_SUFFIX, WP88_GROUP_SUFFIX, $field->option_name)); $categoryTemplateID = get_option(str_replace(WP88_CATEGORY_SUFFIX, WP88_TEMPLATE_SUFFIX, $field->option_name)); AC_Log("For the {$categorySlug} category: The mailing list is: {$categoryMailingList}. The group is: {$categoryGroupName}. The template ID is: {$categoryTemplateID}."); // If the mailing list is NOT "None" then create a campaign. if (0 != strcmp($categoryMailingList, WP88_NONE)) { // Create an instance of the MailChimp API $apiKey = get_option(WP88_MC_APIKEY); $api = new MCAPI_13($apiKey); // Do the work $id = AC_CreateCampaignFromPost($api, $postID, $categoryMailingList, $categoryGroupName, $categoryTemplateID); AC_Log("Created a campaign with ID {$id} in category {$categoryName}."); // Does the user want to send the campaigns right away? $sendNow = get_option(WP88_MC_SEND_NOW); // Send it, if necessary (if user wants it), and the $id is // sufficiently long (just picking longer than 3 for fun). if ('1' == $sendNow && strlen($id) > 3) { $api->campaignSendNow($id); } // Not breaking anymore. Now, if you assign multiple categories to // create campaigns, then each will be created. } } } } }
public function ConvertShortcode($content) { // Supported video types $tagnames = array('vimeo', 'youtube'); $tagregexp = $tagregexp = join('|', array_map('preg_quote', $tagnames)); // WARNING! Do not change this regex. I can barely understand it. $pattern = '\\[' . '(\\[?)' . "({$tagregexp})" . '\\b' . '(' . '[^\\]\\/]*' . '(?:' . '\\/(?!\\])' . '[^\\]\\/]*' . ')*?' . ')' . '(?:' . '(\\/)' . '\\]' . '|' . '\\]' . '(?:' . '(' . '[^\\[]*+' . '(?:' . '\\[(?!\\/\\2\\])' . '[^\\[]*+' . ')*+' . ')' . '\\[\\/\\2\\]' . ')?' . ')' . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] // Callback function for each video tag instance. $updatedContent = preg_replace_callback("/{$pattern}/s", 'VVQT_SwitchViperVideoTags', $content); AC_Log("ContentVipersVideoQuicktags has altered shortcode to this: {$updatedContent}"); return $updatedContent; }