WordPress.org

Ready to get started?Download WordPress

Forums

WP Favorite Posts
[resolved] major bug getting user favourites? (2 posts)

  1. spectrus
    Member
    Posted 2 years ago #

    Hi,

    Just noticed this while testing. Here's how I reproduce.

    1. Change the plugin setting to allow non-logged-in users to save favourites.
    2. Log out, favourite a post without logging in. This will create a cookie.
    3. Log in, go to the page with your favourites.

    I get favourites listed from the non-logged-in user cookie alongside with the logged-in user stuff. Or, if the logged-in user had zero, they now have favourites listed from the cookie.

    Here's the code in question (wp-favorite-posts.php:173):

    if (is_user_logged_in()):
        $favorite_post_ids = wpfp_get_user_meta();
    endif;
    
    if (wpfp_get_cookie()):
        foreach (wpfp_get_cookie() as $post_id => $post_title) {
            array_push($favorite_post_ids, $post_id);
        }
    endif;

    Seems like the code will get favourites from the database first, then push all the favourites from the cookie onto the same array. Here's my quick dirty fix:

    if (is_user_logged_in()):
        $favorite_post_ids = wpfp_get_user_meta();
    else:
        if(wpfp_get_cookie()):
            foreach (wpfp_get_cookie() as $post_id => $post_title) {
                array_push($favorite_post_ids, $post_id);
            }
        endif;
    endif;

    http://wordpress.org/extend/plugins/wp-favorite-posts/

  2. Huseyin Berberoglu
    Member
    Plugin Author

    Posted 2 years ago #

    Ok this bug fixed. version bumped to 1.5.4

    Thanks for your help :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic