|null $publication Publication the import used. * @param bool $global_export Whether the request came through a global export route. */ public static function write( int $post_id, StoryPayload $payload, ?array $publication, bool $global_export = false ): void { if ( $post_id <= 0 ) { return; } $description = $payload->description( $global_export ); if ( '' !== $description ) { // Kordiam sends it HTML-encoded; store plain text and escape on output. update_post_meta( $post_id, MetaKeys::STORY_DESCRIPTION, html_entity_decode( $description, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) ); } $story_id = $payload->story_id(); if ( $story_id > 0 ) { update_post_meta( $post_id, MetaKeys::STORY_ID, $story_id ); } $status_name = PublicationResolver::status_name( $publication ); if ( '' !== $status_name ) { update_post_meta( $post_id, MetaKeys::STATUS_NAME, $status_name ); } $status_id = PublicationResolver::status_id( $publication ); if ( $status_id > 0 ) { update_post_meta( $post_id, MetaKeys::STATUS_ID, $status_id ); } $publication_id = isset( $publication['id'] ) && is_numeric( $publication['id'] ) ? (int) $publication['id'] : 0; if ( $publication_id > 0 ) { update_post_meta( $post_id, MetaKeys::PUBLICATION_ID, $publication_id ); } $category_id = PublicationResolver::category_id( $publication ); if ( $category_id > 0 ) { update_post_meta( $post_id, MetaKeys::CATEGORY_ID, $category_id ); } } /** * Marking a post as removed on the Kordiam side. * * @param int $post_id Post ID. */ public static function mark_removed( int $post_id ): void { if ( $post_id > 0 ) { update_post_meta( $post_id, MetaKeys::REMOVE_STATUS, MetaKeys::REMOVED_FLAG ); } } /** * Clearing the removed marker, for a story restored in Kordiam. * * @param int $post_id Post ID. */ public static function clear_removed( int $post_id ): void { if ( $post_id > 0 ) { delete_post_meta( $post_id, MetaKeys::REMOVE_STATUS ); } } /** * Checking whether a post's story was removed in Kordiam. * * @param int $post_id Post ID. * * @return bool Whether the story is gone on the Kordiam side. */ public static function is_removed( int $post_id ): bool { if ( $post_id <= 0 ) { return false; } if ( MetaKeys::REMOVED_FLAG === get_post_meta( $post_id, MetaKeys::REMOVE_STATUS, true ) ) { return true; } $legacy_key = MetaKeys::legacy_post_meta()[ MetaKeys::REMOVE_STATUS ]; return MetaKeys::REMOVED_FLAG === get_post_meta( $post_id, $legacy_key, true ); } /** * Reading the Kordiam story ID recorded against a post. * * @param int $post_id Post ID. * * @return int Story ID, or 0 when the post is not linked to one. */ public static function story_id_for( int $post_id ): int { if ( $post_id <= 0 ) { return 0; } $story_id = get_post_meta( $post_id, MetaKeys::STORY_ID, true ); if ( is_numeric( $story_id ) && (int) $story_id > 0 ) { return (int) $story_id; } $legacy = get_post_meta( $post_id, MetaKeys::legacy_post_meta()[ MetaKeys::STORY_ID ], true ); return is_numeric( $legacy ) ? (int) $legacy : 0; } }