Skip to content

Instantly share code, notes, and snippets.

@n7studios
Last active May 30, 2023 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n7studios/3e699888abe09c894fc3070e916f0cba to your computer and use it in GitHub Desktop.
Save n7studios/3e699888abe09c894fc3070e916f0cba to your computer and use it in GitHub Desktop.
WordPress to Buffer Pro: Programmatically specify status image(s)
<?php
/**
* Plugin Name: WP to Buffer Pro: Custom Image for Status
* Plugin URI: http://www.wpzinc.com/
* Version: 0.0.1
* Author: WP Zinc
* Author URI: http://www.wpzinc.com
* Description: Define a custom image for a status programmatically
*/
/**
* Define a custom image for a status programmatically, immediately before the status
* is sent to Buffer
*
* @since 0.0.1
*
* @param array $args API standardised arguments
* @param WP_Post $post WordPress Post
* @param string $profile_id Social Media Profile ID
* @param string $service Social Media Service
* @param array $status Parsed Status Message Settings
* @param string $action Action (publish|update|repost|bulk_publish)
* @return array API standardised arguments
*/
function wp_to_buffer_pro_custom_image( $args, $post, $profile_id, $service, $status, $action ) {
// @TODO Any logic here to check whether you want to run this on the given $profile_id,
// $service, $status, $action etc.
// To exit early and not make changes to the status, `return $args`.
// @TODO Fetch the image(s) you want to use from e.g. get_post_meta().
// To use ACF Gallery Images, see https://gist.github.com/n7studios/50d707e0a5bbc7197254b5a3863bd270
// Featured Image.
$args['media'] = array(
'description' => 'description',
'title' => 'title',
'picture' => 'http://example.com/image.jpg', // This is the image sent to social media.
'thumbnail' => 'http://example.com/image-thumbnail.jpg', // @TODO You *must* serve the smallest possible size here to prevent API timeouts. This isn't sent to social media.
);
// Additional Image(s).
$args['extra_media'] = array(
array(
'photo' => 'http://example.com/image2.jpg', // This is the image sent to social media.
'thumbnail' => 'http://example.com/image2-thumbnail.jpg', // @TODO You *must* serve the smallest possible size here to prevent API timeouts. This isn't sent to social media.
),
array(
'photo' => 'http://example.com/image3.jpg', // This is the image sent to social media.
'thumbnail' => 'http://example.com/image3-thumbnail.jpg', // @TODO You *must* serve the smallest possible size here to prevent API timeouts. This isn't sent to social media.
),
array(
'photo' => 'http://example.com/image4.jpg', // This is the image sent to social media.
'thumbnail' => 'http://example.com/image4-thumbnail.jpg', // @TODO You *must* serve the smallest possible size here to prevent API timeouts. This isn't sent to social media.
),
);
// Return
return $args;
}
add_filter( 'wp_to_buffer_pro_publish_build_args', 'wp_to_buffer_pro_custom_image', 10, 6 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment