Skip to main content

Run your own code when a Content Calendar content item is saved or deleted

Premium Intermediate Content Calendar

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 }.

  • type is the key of one of the show’s content types (see Read or change a show’s Content Calendar content types): a built-in tweet, truth, blog_post, newsletter or other, or a podcaster’s own custom_…. type_name holds 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_date is null for none and never later than publish_date.
  • status is draft, planned, posted, deleted (it went out and was later taken down) or canceled (cancel_reason is then set).
  • content is '' for a type without content text. attachment_id and episode_id are null for none. source_uid is the UID of 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_at and updated_at are UTC Y-m-d H:i:s.

Save $context is one of:

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 );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →