post_type ) ) { return; } if ( $post->post_status === 'auto-draft' ) { return; } $post_type = $post->post_type; $author_id = (int) $post->post_author; if ( $author_id > 0 ) { $user = get_user_by( 'id', $author_id ); $user_id = $author_id; $user_name = $user ? $user->display_name : 'System'; } else { $user_id = 0; $user_name = 'System'; } $status_raw = get_post_status( $post_ID ); $status = astr_human_post_status( $status_raw ); if ( $post_type === 'page' ) { $data = [ 'post_id' => $post_ID, 'revision_id' => 0, 'post_title' => get_the_title( $post_ID ), 'post_content' => $post->post_content, 'post_type' => 'page', 'status' => $status, 'user_id' => $user_id, 'user_name' => $user_name, 'time' => current_time( 'mysql' ), ]; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $wpdb->prefix . 'astr_pages_history', $data ); } else { $data = [ 'post_id' => $post_ID, 'revision_id' => 0, 'post_title' => get_the_title( $post_ID ), 'post_content' => $post->post_content, 'post_type' => $post_type, 'status' => $status, 'user_id' => $user_id, 'user_name' => $user_name, 'time' => current_time( 'mysql' ), ]; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $wpdb->prefix . 'astr_posts_history', $data ); } } add_action( 'wp_after_insert_post', 'astr_record_post_save', 10, 4 );