/**
 * Delete Wish List
 *
 * @since 1.0
*/
function edd_wl_delete_list()
{
    check_ajax_referer('edd_wl_ajax_nonce', 'nonce');
    if (!isset($_POST['post_id'])) {
        return;
    }
    $list_id = intval($_POST['post_id']);
    if (wp_delete_post($list_id) === false) {
        $return['msg'] = 'failed';
    } else {
        $messages = edd_wl_messages();
        edd_wl_set_message('list_deleted', $messages['list_deleted']);
        $return['msg'] = 'success';
    }
    echo json_encode($return);
    edd_die();
}
/**
 * Processes the form requests
 *
 * @since 1.0
*/
function edd_wl_process_form_requests()
{
    $messages = edd_wl_messages();
    // create and update forms
    if (isset($_POST['submitted']) && isset($_POST['list_nonce_field']) && wp_verify_nonce($_POST['list_nonce_field'], 'list_nonce')) {
        // list title
        if (trim($_POST['list-title']) === '') {
            edd_wl_set_message('list_title_required', $messages['list_title_required']);
            $has_error = true;
        }
        // only process the form if there are no errors
        if (!isset($has_error)) {
            // edit form
            if (isset($_GET['created']) && $_GET['created'] == true) {
                $args = array('post_title' => isset($_POST['list-title']) ? wp_strip_all_tags($_POST['list-title']) : '', 'post_content' => isset($_POST['list-description']) ? $_POST['list-description'] : '', 'post_status' => $_POST['privacy'], 'post_type' => 'edd_wish_list');
                $post_id = wp_insert_post($args);
                // redirect to success page if successful
                if ($post_id) {
                    // create token for logged user user and store against list
                    edd_wl_create_token($post_id);
                    // redirect to newly created list
                    wp_redirect(add_query_arg('list', 'created', get_permalink($post_id)));
                    exit;
                }
            } elseif (isset($_GET['updated']) && $_GET['updated'] == true) {
                $wish_list = get_post(get_query_var('edit'));
                // get wish list
                $post_id = $wish_list->ID;
                $args = array('ID' => $post_id, 'post_title' => esc_attr(strip_tags($_POST['list-title'])), 'post_content' => esc_attr(strip_tags($_POST['list-description'])), 'post_type' => 'edd_wish_list', 'post_status' => $_POST['privacy']);
                $updated_post_id = wp_update_post($args);
                //  redirect to success page
                if ($updated_post_id) {
                    $messages = edd_wl_messages();
                    // redirect user back to list they just updated
                    wp_redirect(add_query_arg('list', 'updated', get_permalink($updated_post_id)));
                    exit;
                }
            }
            // end edit form process
        }
        // end has error
    }
}
Example #3
0
/**
 * Set various messages
 *
 * @since 1.0
 * @todo  provide better filtering of messages
*/
function edd_wl_set_messages()
{
    // get array of messages
    $messages = edd_wl_messages();
    /**
     * wish-lists.php
     */
    // no lists if no posts
    if (!edd_wl_get_query() && edd_wl_is_page('wish-lists')) {
        edd_wl_set_message('no_lists', $messages['no_lists']);
    }
    /**
     * wish-list-create.php
     */
    // must login
    if (edd_wl_is_page('create') && !edd_wl_allow_guest_creation()) {
        edd_wl_set_message('must_login', $messages['must_login']);
    }
    /**
     * wish-list-view.php
     */
    if (edd_wl_is_page('view')) {
        $downloads = edd_wl_get_list_id() ? edd_wl_get_wish_list(edd_wl_get_list_id()) : array();
        // list updated
        if (isset($_GET['list']) && $_GET['list'] == 'updated') {
            edd_wl_set_message('list_updated', $messages['list_updated']);
        }
        // list created
        if (isset($_GET['list']) && $_GET['list'] == 'created') {
            if (is_user_logged_in()) {
                edd_wl_set_message('list_created', $messages['list_created']);
            } else {
                edd_wl_set_message('list_created', $messages['list_created_guest']);
            }
        }
        // no downloads
        if (empty($downloads)) {
            edd_wl_set_message('no_downloads', $messages['no_downloads']);
        }
    }
}