Intagrate Pro has filters and actions for developers, so you can change what it imports from Instagram, what it posts, and the posts, media and fields it creates, without editing the plugin. Your changes stay in place when you update Intagrate.
Add the code to your theme’s functions.php, or better, a small plugin of your own or a code snippets plugin, so it survives a theme change. Every hook starts with igp_.
The hooks marked 1.13.0 are new in that version.
The media object
Most hooks are passed the Instagram media being imported or posted as $image, an object with:
image_id: its Instagram media IDmedia_type:image,videoorcarouselcaption,caption_cleanandcaption_clean_no_tags: the caption as it came, cleaned up, and cleaned without its hashtagstags: its hashtags, as a serialized arraylink: the link to the post on Instagramimage_timestamp: when it was posted, as a Unix timestampusername: who posted it
Once its media is saved to the media library:
attachment_id: the main image (for a video, its cover image)video_attachment_id: a video’s file 1.13.0carousel_attachment_ids: a carousel’s images, in ordercarousel_items: a carousel’s images and videos in order, each an array withmedia_typeandattachment_id(0 if it wasn’t saved) 1.13.0
Importing from Instagram
igp_instagram_media_fields 1.13.0
Filters the fields Intagrate asks Instagram for, for each piece of media. Add a field Instagram offers, then read it in igp_media_imported. Don’t remove the fields Intagrate asks for.
$fields(string): comma-separated field names$is_child(bool): whether it’s for an item in a carousel
add_filter( 'igp_instagram_media_fields', function ( $fields, $is_child ) {
return $is_child ? $fields : $fields . ',like_count';
}, 10, 2 );
igp_media_imported 1.13.0
Fires when a piece of media is saved to an account’s media, before it’s posted, with everything Instagram sent. Carousel items fire too, with $data['parent_id'] set.
$row_id(int): its row in Intagrate’s media table$data(array): what Intagrate saved, includingimage_id,media_type,captionandlink$media(object): the media as Instagram sent it, with any fields added withigp_instagram_media_fields$account_id(int): the Intagrate account
// Keep each post's like count, to save on the WordPress post later
add_action( 'igp_media_imported', function ( $row_id, $data, $media, $account_id ) {
if ( isset( $media->like_count ) ) {
update_option( 'my_igp_likes_' . $data['image_id'], (int) $media->like_count, false );
}
}, 10, 4 );
igp_instagram_image_url
Filters the image URL Intagrate downloads, after it has looked for a higher resolution version.
$url(string): the URL it will use$original(string): the URL Instagram gave
Choosing what to post
igp_should_post_media 1.13.0
Filters whether to post a piece of media in this run. It runs after the account’s Media Filter and Hashtags Filter. Return false to leave it out: it stays Pending, so it’s considered again on the next run.
$post(bool): whether to post it$image(object): the media$account_id(int): the Intagrate account
// Don't post sponsored posts
add_filter( 'igp_should_post_media', function ( $post, $image, $account_id ) {
return $post && false === stripos( $image->caption, '#ad' );
}, 10, 3 );
igp_image_posting_limit
Filters how many pieces of media an account posts in one run. The default, false, means all of them.
$limit(int|false)$account_id(int)
igp_stuck_posting_timeout
Filters how long, in seconds, before a run that stopped partway is treated as over: its media goes back to Pending and the account is unlocked. The default is 30 minutes.
$seconds(int)$account_id(int)
A posting run
igp_before_post_account 1.13.0
Fires before an account posts its media, when there’s media to post.
$account_id(int)$images(object[]): the media about to be posted. A carousel’s items are posted with it, not listed separately.
igp_after_post_account 1.13.0
Fires after an account has posted its media, for example to send a notification or clear a cache.
$account_id(int)$images(object[]): the media that was to be posted$post_ids(int[]): the posts created, or the post updated in Same Post mode
add_action( 'igp_after_post_account', function ( $account_id, $images, $post_ids ) {
if ( $post_ids ) {
wp_mail( get_option( 'admin_email' ), 'New Instagram posts', implode( "\n", array_map( 'get_permalink', $post_ids ) ) );
}
}, 10, 3 );
Creating the post
igp_post_args
Filters the arguments the post is created with, before it has its content: post_title, post_author, post_type, post_date and more, as for wp_insert_post(). It’s created as a draft and gets the account’s status later.
$post_args(array)$image(object|null): the media, in Post Per Media mode
igp_post_title
Filters the post title, after the account’s title template and title limit.
$title(string)
igp_image_post_taxonomy_terms
Filters the terms in the account’s Taxonomy setting given to the post. Use the first hashtag as the post’s category shows it in use.
$terms(array): the term IDs chosen on the account$image(object|null): the media, in Post Per Media mode$post_id(int)$taxonomy(string)
igp_image_post_tags
Filters the tags given to the post when Convert Media Hashtags to is set.
$tags(array): the hashtags, plus the account’s default tags$image(object)$post_id(int)
igp_before_publish_post 1.13.0
Fires when the post has its content, terms, media and ACF fields, before it gets the account’s status. Hooks that run on publishing, like social sharing plugins, see anything added here.
$post_id(int)$images(object[]): the media in it, one in Post Per Media mode$account_id(int)
igp_post_created 1.13.0
Fires after a post is created for a piece of media. In Media Grouped and Same Post modes, it fires for each piece of media in the post.
$post_id(int)$image(object): the media, with its attachments$account_id(int)
// Save the like count kept by igp_media_imported on the post
add_action( 'igp_post_created', function ( $post_id, $image, $account_id ) {
$likes = get_option( 'my_igp_likes_' . $image->image_id );
if ( false !== $likes ) {
update_post_meta( $post_id, 'instagram_likes', $likes );
}
}, 10, 3 );
Saving media to the media library
igp_image_filename
Filters the file name an image or video is saved with.
$file_name(string): from the caption, or the Instagram file’s own name when the Image Name as Instagram ID setting is on$file(string): the file’s own name$post_name(string)$post_id(int)
igp_image_caption
Filters the caption saved on the media library item.
$caption(string)
igp_image_alt_text
Filters an image’s alt text. Return '' to save none.
$image_alt(string): the alt text the author wrote on Instagram if there is one, otherwise the caption, cleaned and shortened$alt_text(string): the caption without hashtags, as it came$attachment_id(int)$post_id(int)$instagram_alt_text(string): the alt text the author wrote on Instagram, as it came, or''
Template tags
igp_add_template_tags 1.13.0
Filters the list of template tags, for example to add your own. Each tag is an array with name (used as %%name%%), value, and optionally desc and exclude_from (title or meta, where it can’t be used). Your tag shows in the Template Tags box and the ACF Fields box too.
$tags(array)$media(object|null): the media being posted, ornulloutside posting, such as when the account screen lists the tags
// %%caption-first-line%%: the caption up to its first line break
add_filter( 'igp_add_template_tags', function ( $tags, $media ) {
$tags[] = array(
'name' => 'caption-first-line',
'desc' => 'The first line of the caption.',
'value' => $media ? strtok( (string) $media->caption_clean, "\n" ) : '',
);
return $tags;
}, 10, 2 );
igp_template_{tag}
Filters one template tag’s value. The tag’s name has its hyphens replaced with underscores: %%caption-no-tags%% is igp_template_caption_no_tags. Splitting the caption into the title and content uses it.
$value(string)
igp_tag_sep
Filters what goes between the hashtags in %%tags%%. The default is a space.
$separator(string)
igp_date_format
Filters the date format of %%image-date%%. See changing the date format.
$format(string): defaultM d, Y @ H:i
igp_caption_strip_tags
Filters the caption once its hashtags are taken out, for %%caption-no-tags%% and alt text.
$caption(string)$tags(array): the hashtags taken out
ACF fields
For the ACF Fields box.
igp_acf_field_sources 1.13.0
Filters what an ACF field can be filled with. Add a choice to offer it in the ACF Fields box, including for field types Intagrate doesn’t support, then give it a value with igp_acf_field_value.
$sources(array): choice key => label$field(array): the ACF field
igp_acf_field_value 1.13.0
Filters the value saved to an ACF field. Return null to leave the field alone.
$value(mixed): the value Intagrate would save$field(array): the ACF field$source(string|array): the choice made in the box, or the template for a text field$image(object): the media
// Fill a Group field called "credit" with the username and the link
add_filter( 'igp_acf_field_sources', function ( $sources, $field ) {
if ( 'group' === $field['type'] && 'credit' === $field['name'] ) {
$sources['credit'] = 'Instagram username and link';
}
return $sources;
}, 10, 2 );
add_filter( 'igp_acf_field_value', function ( $value, $field, $source, $image ) {
if ( 'credit' === $source ) {
return array( 'username' => $image->username, 'link' => $image->link );
}
return $value;
}, 10, 4 );
Carousels and maps
igp_carousel_img_html 1.13.0
Filters the HTML of each image in a carousel in the post content. Before 1.13.0 its name ended with a space, 'igp_carousel_img_html '. That name still works.
$html(string): the<img>tag$item(object): the carousel item$parent(object): the carousel
igp_map_link_html
Filters what a map shortcode shows when the site has no Google Maps API key: a “View on Google Maps” link for each location. Return '' to show nothing.
$html(string)$markers(array): each withlat,lngandmarker
igp_google_maps_api_key
Filters your own Google Maps API key, for sites with old map posts. The IGP_GOOGLE_MAPS_API_KEY constant, if defined, is used before the setting.
$key(string)
Admin
igp_allowed_roles
Filters which user roles see the Intagrate menu. The default is administrator.
$roles(string[])
igp_page_capability_settings and igp_page_capability_moderation
Filter the capability needed for the Settings and Moderation screens. The default is manage_options.
$capability(string)
igp_images_moderation_{column}
Filters a column’s value in the Moderation screen’s table, where {column} is image, caption_clean_no_tags, account_id, username or hashtags.
$value(string)$row_id(int)
igp_hide_facebook_api_notice
Filters whether to hide the notice asking you to reconnect accounts after Instagram’s API change. Return anything but false to hide it.
$hide(mixed)
Something you need a hook for that isn’t here? Get in touch: we add them when there’s a use for them.