Example #1
0
/**
 * When user registers and has guest lists, remove token meta key so their lists are saved indefinately
 *
 * @since 1.0
 * @param  int $user_id newly created user id
 * @return void
 */
function edd_wl_new_user_registration($user_id)
{
    // get user's token if present
    $lists = edd_wl_get_guest_lists(edd_wl_get_list_token());
    // attribute posts to new author
    if ($lists) {
        // loop throgh each list and assign the new user ID to their list
        foreach ($lists as $key => $list) {
            $args = array('ID' => $list->ID, 'post_author' => $user_id);
            wp_update_post($args);
            // delete token one each list
            delete_post_meta($list->ID, 'edd_wl_token', edd_wl_get_list_token());
        }
        // remove cookie
        setcookie('edd_wl_token', '', time() - 3600, COOKIEPATH, COOKIE_DOMAIN);
    }
}
Example #2
0
/**
 * The query to return the posts on the main wish lists page
 * retrieves ids of lists for either logged in user or logged out
 *
 * @since 1.0
*/
function edd_wl_get_query($status = array('publish', 'private'))
{
    global $current_user;
    get_currentuserinfo();
    if ('public' == $status) {
        $status = 'publish';
    }
    // return if user is logged out and they don't have a token
    if (!is_user_logged_in() && !edd_wl_get_list_token()) {
        return null;
    }
    // initial query
    $query = array('post_type' => 'edd_wish_list', 'posts_per_page' => '-1', 'post_status' => $status);
    // get lists that belong to the currently logged in user
    if (is_user_logged_in()) {
        $query['author'] = $current_user->ID;
    }
    // get token from cookie and lookup lists with that token
    if (!is_user_logged_in()) {
        $query['meta_query'][] = array('key' => 'edd_wl_token', 'value' => edd_wl_get_list_token());
    }
    $posts = new WP_Query($query);
    $ids = array();
    if ($posts->have_posts()) {
        while ($posts->have_posts()) {
            $posts->the_post();
            $ids[] = get_the_ID();
        }
        wp_reset_postdata();
    }
    if ($ids) {
        return $ids;
    }
    return false;
}