Remove fictioneer_first_publish_date meta

This commit is contained in:
Tetrakern 2024-09-17 15:43:57 +02:00
parent a86f1ae8ba
commit 927ceb7bf5
5 changed files with 21 additions and 39 deletions

View File

@ -108,9 +108,6 @@ function fictioneer_migrate_chapters( $query_args = [], $story_args = [], $previ
update_post_meta( $post->ID, 'fictioneer_chapter_story', $story_id );
}
// Update other meta
update_post_meta( $post->ID, 'fictioneer_first_publish_date', $post->post_date_gmt );
// Change post type to fcn_chapter (also triggers hooked actions and updates story)
wp_update_post(
array(

View File

@ -158,7 +158,6 @@ function fictioneer_generate_test_content() {
fictioneer_generate_test_comments( $chapter_id, $comment_count );
update_post_meta( $chapter_id, 'fictioneer_chapter_story', $story_id );
update_post_meta( $chapter_id, 'fictioneer_first_publish_date', current_time( 'mysql', true ) );
}
}

View File

@ -115,38 +115,6 @@ if ( get_option( 'fictioneer_count_characters_as_words' ) ) {
add_action( 'save_post', 'fictioneer_characters_as_word_count' );
}
// =============================================================================
// STORE ORIGINAL PUBLISH DATE
// =============================================================================
/**
* Stores the original publish date of a post in post meta
*
* @since 5.6.0
*
* @param int $post_id The ID of the post being saved.
* @param WP_Post $post The post object being saved.
*/
function fictioneer_store_original_publish_date( $post_id, $post ) {
// Prevent miss-fire
if (
fictioneer_multi_save_guard( $post_id ) ||
$post->post_status !== 'publish'
) {
return;
}
// Get first publish date (if set)
$first_publish_date = get_post_meta( $post_id, 'fictioneer_first_publish_date', true );
// Set if missing
if ( empty( $first_publish_date ) || strtotime( $first_publish_date ) === false ) {
update_post_meta( $post_id, 'fictioneer_first_publish_date', current_time( 'mysql', true ) );
}
}
add_action( 'save_post', 'fictioneer_store_original_publish_date', 10, 2 );
// =============================================================================
// STORY CHANGELOG
// =============================================================================

View File

@ -1528,10 +1528,10 @@ if ( ! current_user_can( 'manage_options' ) ) {
function fictioneer_prevent_publish_date_update( $data, $postarr ) {
// Setup
$first_publish_date = get_post_meta( $postarr['ID'], 'fictioneer_first_publish_date', true );
$current_post_date_gmt = get_post_time( 'Y-m-d H:i:s', 1, $postarr['ID'] );
// Remove from update array if already published once
if ( ! empty( $first_publish_date ) ) {
if ( $current_post_date_gmt !== $data['post_date_gmt'] ) {
unset( $data['post_date'] );
unset( $data['post_date_gmt'] );
}

View File

@ -349,7 +349,7 @@ function fictioneer_purge_caches_after_update() {
add_action( 'fictioneer_after_update', 'fictioneer_purge_caches_after_update' );
/**
* Removed default chapter icons from post meta table
* Removes default chapter icons from post meta table
*
* @since 5.24.1
*/
@ -371,6 +371,24 @@ function fictioneer_remove_default_chapter_icons_from_meta() {
}
add_action( 'fictioneer_after_update', 'fictioneer_remove_default_chapter_icons_from_meta' );
/**
* Removes obsolete fictioneer_first_publish_date from post meta table
*
* @since 5.24.1
*/
function fictioneer_remove_first_publish_date_from_meta() {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
'fictioneer_first_publish_date'
)
);
}
add_action( 'fictioneer_after_update', 'fictioneer_remove_first_publish_date_from_meta' );
// =============================================================================
// PROTECT META FIELDS
// =============================================================================