Created
January 1, 2020 17:13
-
-
Save nczz/3590bafb06fb431f6097b79cb2e88c2f to your computer and use it in GitHub Desktop.
[WordPress] 客製化紀錄網站內容版本修訂的做法 https://www.mxp.tw/8784/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mxp_get_post_edit_log($new_status, $old_status, $post) { | |
if ($post->post_type != "page") { | |
return; | |
} | |
//取得編修人 | |
$current_user = wp_get_current_user(); | |
//組合紀錄格式 | |
$sp_line = "-.-.-.-.-.-.-.-.-.-.-.-"; | |
$log_user = "User ID: {$current_user->ID}:{$current_user->display_name}"; | |
$log_message = $log_user . " > " . $post->post_type . " -> status: " . $old_status . " to " . $new_status . " at " . date('Y-m-d H:i:s') . " | " . time(); | |
$log_content = $log_message . PHP_EOL . "Title: " . $post->post_title . PHP_EOL . $sp_line . PHP_EOL . $post->post_content . PHP_EOL . $sp_line . PHP_EOL; | |
//創建目錄 | |
$upload_dir = wp_upload_dir(); | |
$log_dirname = $upload_dir['basedir'] . '/post_edit_log'; | |
if (!file_exists($log_dirname)) { | |
wp_mkdir_p($log_dirname); | |
} | |
error_log($log_content, 3, $log_dirname . "/" . $post->ID . ".log"); | |
} | |
add_action('transition_post_status', 'mxp_get_post_edit_log', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment