Пример #1
0
        print '</fieldset>';
    }
    if (class_exists('RegisterPlusReduxPlugin')) {
        print '<p><strong>You are using <a target="_blank" href="http://wordpress.org/extend/plugins/register-plus-redux/">Register Plus Redux</a></strong> which has a known issue preventing first and last name being synchronized with MailChimp. <em>AutoChimp can fix this</em>.</p>';
        print '<fieldset style="margin-left: 20px;">';
        print "<p><input type=CHECKBOX value=\"on_fix_regplusredux\" name=\"on_fix_regplusredux\" ";
        if ('1' === $fixRegPlusRedux) {
            print "checked";
        }
        print '> Patch Register Plus Redux and sync first/last name with your selected mailing list. <em>Recommended <strong>ON</strong></em>. <strong>Note:</strong> You must enable "<em>Require new users enter a password during registration...</em>" in your Register Plus Redux options in order for the AutoChimp patch to work.</p>';
        print '<p><em>News:</em> Sorry to the folks who were hoping that Register Plus Redux version 3.7.0 and up would fix this.  This patch is still required when running Register Plus Redux.  More info can be found <a href="http://radiok.info/blog/conflicts-begone/" target="_blank">here</a>.</p>';
        print '</fieldset>';
    }
    $syncPlugins = new ACSyncPlugins();
    $syncPlugins->ShowPluginSettings();
    $publishPlugins = new ACPublishPlugins();
    $publishPlugins->ShowPluginSettings();
    $contentPlugins = new ACContentPlugins();
    $contentPlugins->ShowPluginSettings();
    ?>
	
	<div class="submit"><input type="submit" name="save_plugin_options" class="button-primary" value="Save Options" /></div>
	
	<div class="clear"></div>
	</div>
	</div>

<?php 
}
// End of all tab-specific code
?>
Пример #2
0
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.
                }
            }
        }
    }
}