• Hi Viktor,

    I think the plugin sends scrape info to Facebook even when the post status is Draft. I use the Redirection plugin, which shows me 404s coming from Facebook for post ids that are still in draft status. Is there any way you can make sure the status is published before sending the scrape info to Facebook?

    Thanks!

    https://wordpress.org/plugins/facebook-open-graph-scraper/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Julie

    (@habannah)

    Hi again @viktor Fröberg,

    I’ve figured out that this is happening because of the save_post action hook being used to trigger rescraping. It runs whenever a post/page/CPT is created or updated, including auto-save drafts and revisions.

    Thanks to this article, I thought that something like the following could be helpful:

    function __construct(){
    	if( ! wp_is_post_revision( $post_id ) && ! wp_is_post_autosave( $post_id ) ) {
    		add_action( 'save_post', array($this, 'post_scraper'), 90, 2);
    	}
    }

    However, there are still some issues with this solution:

    • I’m not sure if this works for taxonomy terms
    • Rescraping still occurs on other undesirable post statuses (future, pending, draft, private…)

    Ideally, the scraper would only run when a piece of content is first published (and the published status is “public”), and then afterwards whenever it is saved by pressing the Update button (and not for every auto-save, for which I believe the default interval is 1 minute, though I may be wrong since I’ve customized my setup).

    So then I thought perhaps something like this:

    function __construct(){
    	if( get_post_status ( $ID ) == 'publish' ) {
    		add_action( 'save_post', array($this, 'post_scraper'), 90, 2);
    	}
    }

    But I still don’t know if this would work for taxonomy terms. Moreover, I don’t know how this would handle the status transition from draft to published.

    I’m fairly new at PHP, so I’d really appreciate if you could help me figure this out! Thanks 🙂

    Plugin Author Viktor Fröberg

    (@viktorfroberg)

    Hi!
    Sorry for the late answer!
    Great work!
    I’m note sure you’ll get the right post status outside of the save_post hook. So I think the best thing is to add a check at the beginning of the post_scraper function, since we have the $post object there, and it contains the post status 🙂

    I’ll try to implement this and release a fix this week, before my vacation 🙂

    Btw, the plugin is open source and available on github, pull requests are always welcome!

    / Viktor

    Thread Starter Julie

    (@habannah)

    Thanks for looking into this, Victor! I appreciate the help 🙂 I don’t know much php so I really had no clue what the next step should be, or even how to test my changes…

    I can submit a pull request if you want me to, but I’ve never done that before, so perhaps you wouldn’t mind guiding me through the process?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Sends Draft Post Data to Facebook’ is closed to new replies.