Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Meitar

    (@meitar)

    IIUC, the plugin already does this starting all the way back in version 0.7.2. From the changelog:

    • Feature: Save a given post’s reblog key when importing that post with the “Sync posts from Tumblr” feature. Theme authors can then use the tumblr_reblog_key custom field to create a link on the WordPress post that lets a user reblog the original post on Tumblr. For instance:
    • <a href="http://www.tumblr.com/reblog/<?php echo get_post_meta($post->ID, 'tumblr_post_id', true);?>/<?php echo get_post_meta($post->ID, 'tumblr_reblog_key', true);?>?redirect_to=<?php echo esc_url(get_permalink());?>">
    Thread Starter wob

    (@wob)

    Yeah, I saw that, but thought it just was for imported posts from Tumblr. I’m mean posts created from WordPress and sent to Tumblr, and from what I can see they only get the tumblr_post_id meta.

    Plugin Author Meitar

    (@meitar)

    Oh. Huh.

    Well, to the best of my knowledge, reblog_key is only available after a post has been created and unless I missed something it seems the Tumblr API only provides this when retrieving published posts, not when creating a new post.

    This means it would require a second HTTP request to get a reblog_key for the post after creating it. That’s potentially a heavier load on your WordPress site that might slow things down a lot more than waiting for the Tumblr API already does.

    Mind if I ask why you’re looking to have this in the plugin? It’s the first request of this kind I’ve seen. Maybe what you’re trying to do can be accomplished in a more lightweight way?

    Thread Starter wob

    (@wob)

    If you had the reblog key tied to the post, you could for example implement a like and/or reblog button for your WordPress site.

    That would let you like and reblog Tumblr stuff directly on your blog. That’s why I’m looking it to it.

    Plugin Author Meitar

    (@meitar)

    Oh, I see what you’re saying now. Okay, I’ve implemented a new action hook in the latest version 0.7.18, released today, called tumblr_crosspostr_reblog_key that prints a post’s reblog_key, or fetches and saves it upon viewing the post if we don’t already know it. This means you can use the following code inside your theme files during The Loop like a template tag to print the reblog key:

    <?php do_action('tumblr_crosspostr_reblog_key');?>

    To make a reblog link like the one above, do this inside The Loop:

    <a href="http://www.tumblr.com/reblog/<?php echo get_post_meta($post->ID, 'tumblr_post_id', true);?>/<?php do_action('tumblr_crosspostr_reblog_key');?>?redirect_to=<?php echo esc_url(get_permalink());?>">

    The reason I suggest using do_action() instead of calling the template tag directly (tumblr_reblog_key()) is because if you ever choose to deactivate Tumblr Crosspostr but forget to remove the call to its custom template tag in your theme, your site will encounter a PHP fatal error.

    Hope this helps. Let me know if you have any trouble.

    Thread Starter wob

    (@wob)

    Thanks Meitar! That’s great! I’m almost exclusively fetching posts with some sort of javascript framework (atleast ajax) when I do WordPress sites. Not sure if I can trigger this with JS?

    Maybe a solution for me could be to run a curl script upon posting that runs this?

    Plugin Author Meitar

    (@meitar)

    To trigger this, you just need to have the action called from your theme as described above and then load the page in your browser. When WordPress constructs the HTML for a post, it will ask Tumblr Crosspostr for the reblog key information from Tumblr. If Tumblr Crosspostr doesn’t already know it, it’ll ask Tumblr for that information and pass it back to the WordPress theme. Since JavaScript can load a page same as any user can, you can trigger this with JavaScript, too. 😉

    Obviously, if your WordPress theme requires JavaScript to get individual posts to the browser in the first place, then you probably have another problem, which is outside the scope of this support forum. 😉

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Get reblog key from created post’ is closed to new replies.