コード例 #1
0
/**
 * SAVE Boxes meta in Newsletter 
 */
function alo_em_save_newsletter_meta($post_id)
{
    if (@(!wp_verify_nonce($_POST["edit_newsletter"], ALO_EM_PLUGIN_DIR))) {
        return $post_id;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // Check permissions
    if ('newsletter' == $_POST['post_type']) {
        if (!current_user_can('edit_newsletter', $post_id)) {
            return $post_id;
        }
    }
    do_action('alo_easymail_save_newsletter_meta_extra', $post_id);
    // If a previous list exists already: if requested reset, otherwise don't save
    if (alo_em_count_newsletter_recipients($post_id) > 0 || alo_em_is_newsletter_recipients_archived($post_id)) {
        if (isset($_POST['easymail-reset-all-recipients'])) {
            alo_em_delete_newsletter_recipients($post_id);
            alo_em_delete_newsletter_status($post_id);
            alo_em_delete_cache_recipients($post_id);
        } else {
            return $post_id;
            // don't save, exit
        }
    }
    // Save Recipients
    $recipients = array();
    if (isset($_POST['easymail-recipients-all-regusers'])) {
        $recipients['registered'] = "1";
    } else {
        if (isset($_POST['check_role']) && is_array($_POST['check_role'])) {
            foreach ($_POST['check_role'] as $role) {
                $recipients['role'][] = $role;
            }
        }
    }
    if (isset($_POST['easymail-recipients-all-subscribers'])) {
        $recipients['subscribers'] = "1";
    } else {
        if (isset($_POST['check_list']) && is_array($_POST['check_list'])) {
            foreach ($_POST['check_list'] as $list) {
                $recipients['list'][] = $list;
            }
        }
    }
    if (isset($_POST['check_lang']) && is_array($_POST['check_lang'])) {
        foreach ($_POST['check_lang'] as $lang) {
            $recipients['lang'][] = $lang;
        }
    }
    // Save!
    delete_post_meta($post_id, "_easymail_recipients");
    add_post_meta($post_id, "_easymail_recipients", $recipients);
    // If required, create list of recipient now, without ajax
    if (get_option('alo_em_js_rec_list') == "no_ajax_onsavepost" && alo_em_count_recipients_from_meta($post_id) > 0) {
        alo_em_create_cache_recipients($post_id);
        alo_em_add_recipients_from_cache_to_db($post_id, alo_em_count_recipients_from_meta($post_id), false);
    }
}