2

I'm trying to auto-post from my blog to Facebook using Buffer and this plugin (https://straightupcraft.com/craft-plugins/buffer). The addon requires me to create a plugin to do the actual posting to Buffer. This is my first foray into plugins at all. I used his example and got something that works.

However, the question I have is somewhat general. How do I pull an asset from an entry that has been saved to be able to post to the plugin?

This is the relevant portion of the plugin:

$picture = craft()->request->getUrl($entry->blogImage);

craft()->buffer_utils->queueBufferUpdate($updateString, true, $link, $picture, $thumbnail);

Obviously, my asset field name is blogImage.

Also, and let me know if I need to create a new question for this, how does onBeforeSaveEntry affect scheduled content? Does/will the plugin run when it's actually saved or when it becomes "live"? If so, is there a workaround for that?

Thanks.

edit: I did reach out directly to the developer but have not had any luck yet and was hoping the question was general enough that someone else might be able to help!

1

To get the URL of an asset in a plugin, you use a similar technique as you do in twig, so this will fetch the URL of the first image in the blogImage field:

$picture = $entry->blogImage->first()->url;

To answer you second question, onBeforeSaveEntry is run just before the entry is actually saved, not just before it is published live on the site if it has been saved with a post date in the future.

Craft doesn't fire any events just before an entry becomes 'live' on the site, so if you want the post to Buffer to go out at the same time as the entry goes live using this technique, you will need to actually create and save the entry when you want to publish it live on your site.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.