Run your own code when a Content Calendar content item is saved or deleted
Four actions, all ( array $item, string $context ): benecaster_content_calendar_before_save_item, benecaster_content_calendar_after_save_item, benecaster_content_calendar_before_delete_item and benecaster_content_calendar_after_delete_item.
$item is a content item: { id, show_id, type, type_name, title, publish_date, publish_time, due_date, due_time, status, cancel_reason, content, reference_url, attachment_id, promotion_notes, call_to_action, notes, episode_id, source_uid, created_by, created_at, updated_at }.
typeis the key of one of the show’s content types (see Read or change a show’s Content Calendar content types): a built-intweet,truth,blog_post,newsletterorother, or a podcaster’s owncustom_….type_nameholds the name typed for an Other item,''otherwise.- The dates (
YYYY-MM-DD) and times (HH:MM, null for all day) are the site’s day and wall-clock time, never UTC.due_dateis null for none and never later thanpublish_date. statusisdraft,planned,posted,deleted(it went out and was later taken down) orcanceled(cancel_reasonis then set).contentis''for a type without content text.attachment_idandepisode_idare null for none.source_uidis theUIDof the calendar event the item was imported from (see Import an .ics file into a show’s Content Calendar over REST), null for one made on the screen.created_atandupdated_atare UTCY-m-d H:i:s.
Save $context is one of:
create: made on the Calendar screen or over the REST API (before the write,idis 0).import: made by an iCal import (see Import an .ics file into a show’s Content Calendar over REST); before the write,idis 0.promote: made from an idea on the Ideas board (see Read, write, rearrange and promote a show’s Content Calendar ideas over REST); before the write,idis 0.update.episode_move: the linked episode moved to another show and the item went with it;show_idis the new show.
Delete $context is delete or episode_deleted (the linked episode was deleted for good; moving it to the Trash deletes nothing). An after hook fires only when the write succeeded. The two episode contexts fire even while Content Calendar is off for every show.
Code
<?php
add_action( 'benecaster_content_calendar_after_save_item', function ( array $item, string $context ): void {
if ( 'posted' === $item['status'] && 'tweet' === $item['type'] ) {
my_social_log( $item['show_id'], $item['title'], $item['reference_url'] );
}
}, 10, 2 );
Hooks Used
Need this built rather than just documented? See our services →