できた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
class TwentySeventeenTechnotes_Note_ModifiedDateProtector { public $aPostTypeSlugs = array(); // e.g. note /** * Performs necessary set-ups. */ public function __construct( $asPostTypeSlug ) { $this->aPostTypeSlugs = ( array ) $asPostTypeSlug; add_filter( 'wp_insert_post_data', array( $this, 'replyToProtectModifiedDate' ), 10, 2 ); } public function replyToProtectModifiedDate( $aData, $aPost ){ if ( ! in_array( $aData[ 'post_type' ], $this->aPostTypeSlugs ) ) { return $aData; } if ( empty( $aPost[ 'ID' ] ) ) { return $aData; } $_oOldPost = get_post( $aPost[ 'ID' ] ); if ( empty( $_oOldPost ) ) { return $aData; } // When the content is the same, then do not update the modified date. if ( $_oOldPost->post_content === $aData[ 'post_content' ] ) { $aData[ 'post_modified' ] = $_oOldPost->post_modified; $aData[ 'post_modified_gmt' ] = $_oOldPost->post_modified_gmt; } return $aData; } } |