kylephillips / favorites

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

The nonce could not be verified #104

Open lasagnapuppy opened 5 years ago

lasagnapuppy commented 5 years ago

I am receiving this message on the console. Wordpress 4.9.8. So far no problems with any other plugin. Site is in a vagrant box, while develping. Plugin version 2.2.0. I am trying to apply this to a custom post type. Here is how i am calling the function:

<?php the_favorites_button(get_the_ID(), NULL, "games"); ?>

EDIT: The error i am receiving is: The favorite was successfully saved. favorites.js:635:6 Object { status: "error", message: "The nonce could not be verified." }

What can be the problem? Thanks in advance.

gfargo commented 5 years ago

Hey @lasagnapuppy, the third parameter you are passing to the_favorites_button is not used to designate post type.

https://github.com/kylephillips/favorites/blob/2fa284d4e3e8292d30d606c369c59a502c54c437/app/API/functions.php#L31-L40

It's used to pass along a site_id, not target post type. If i'm not mistaken, by default the_favorites_button should support custom post types.

Let me know if you're still experiencing this issue.

nicksource commented 5 years ago

@GFargo I have a related issue where I can't get favourites to work with a custom post type. It works fine for standard posts but with custom post types I get:

The favorite was successfully saved. favorites
Object { status: "error", message: "Invalid post." }

Simply using the below, where $id is my post, I checked the HTML and it is inserting the correct data. (for example data-postid="175") but it won't work. <?php the_favorites_button($id,NULL);?>

If I use a post ID that is not a custom post type, it works.

EDIT: SOLVED! In the favorites settings I didn't enable the custom post type.