kylephillips / favorites

Simple and flexible favorite buttons for any WordPress post type.
https://favoriteposts.com
224 stars 85 forks source link

FavoritesArray is loading on each page load without user logged-in #127

Open jimi008 opened 5 years ago

jimi008 commented 5 years ago

Current Behavior: With settings Anonymous user disabled FavoritesArray is still loading on each page load and hit admin-ajax.php without any user authentication.

{"status":"success","favorites":[{"groups":[{"group_id":1,"site_id":1,"group_name":"Default List","posts":[]}],"posts":[],"site_id":1}]}

Expected Behavior: FavoritesArray ( array of user's favorited posts) should be loaded when the user is logged in with settings for " Anonymous user" disabled.

To Reproduce this bug simply install the Favorites version 2.3.1 and check the browser console and XHR requests.

10-9-2019 6-48-52 PM 10-9-2019 8-55-30 PM

Similar Issue: https://github.com/kylephillips/favorites/issues/118

https://github.com/kylephillips/favorites/issues/118

jimi008 commented 5 years ago

Duplicate of #118

This seems to be an issue and previously it's hooked on favorites-nonce-generated

https://github.com/kylephillips/favorites/blob/c067229fbb043c9b6e05b8b6612983eeeb3ec72a/assets/js/favorites.js#L220-L223

Currently, it can be fixed by replacing it with previous code snippet until the fix provided by the author

https://github.com/kylephillips/favorites/blob/3a992b99624ecd74f8c7d4a583c7e18bb8024b0b/assets/js/favorites.js#L275-L278

Slamik commented 5 years ago

Thank you for your fix.

Another bottleneck is here. https://github.com/kylephillips/favorites/blob/c067229fbb043c9b6e05b8b6612983eeeb3ec72a/app/Entities/User/UserFavorites.php#L48-L61

$this->removeInvalidFavorites($favorites)

Every id from FavoritesArray is checked for existence calling to get_post($id);

https://github.com/kylephillips/favorites/issues/116