activity_types = include plugin_dir_path( ATKAI_PLUGIN_FILE ) . '/activities/types.php'; $this->logger = $logger; add_action( 'transition_post_status', array( &$this, 'atk_post_updated_or_created'), 10, 3 ); add_action( 'delete_post', array( &$this, 'atk_delete_post' ) ); } public function atk_post_updated_or_created( $new_status, $old_status, $post ) { if ( wp_is_post_revision( $post->ID ) ) return; $edit_link = get_edit_post_link($post->ID); $post_type_object = get_post_type_object( $post->post_type ); $post_type_name = $post_type_object->labels->singular_name; if ( empty($post->post_title) || $new_status === 'auto-draft' || $post_type_name === 'Navigation Menu Item' ) { return; } $user_id = get_current_user_id(); // Get the current user ID $description = ''; $status = ''; $activity_type = ''; // Determine the transition if ( $new_status === 'trash' && $old_status !== 'trash' ) { $description = 'Post Trashed: ' . $post->post_title .' in '. $post_type_name; $status = 'deletion'; } elseif ( $new_status === 'draft' && $old_status !== 'draft' ) { $description = 'Post Draft: ' . $post->post_title .' in '. $post_type_name; $status = 'draft'; } elseif ($new_status === 'publish' && $old_status !== 'publish') { $description = 'Post Published: ' . $post->post_title .' in '. $post_type_name; $status = 'publish'; } elseif ($new_status === 'publish' && $old_status === 'publish') { $description = 'Post Updated: ' . $post->post_title .' in '. $post_type_name; $status = 'edit'; } else { return; // If no recognized status transition, exit the function } $activity_type = $this->activity_types['content'][$status] ?? 'general'; $this->logger->insert_log( $user_id, 'Content', $activity_type, $description, $status, $edit_link ); } public function atk_delete_post( $post_id ) { // Ensure this is not an autosave routine if ( wp_is_post_revision( $post_id ) ) return; $post = get_post( $post_id ); $edit_link = get_edit_post_link($post_id); if ( ! $post ) { return; } if ( 'nav_menu_item' === get_post_type( $post->ID ) ) return; if ( in_array( $post->post_status, array( 'auto-draft', 'inherit' ) ) ) return; // Get the post object $post = get_post( $post_id ); // Get the post type object $post_type_object = get_post_type_object( $post->post_type ); // Get the singular name of the post type $post_type_name = $post_type_object->labels->singular_name; $description = 'Post Deleted: ' . $post->post_title .' in '. $post_type_name; $activity_type = $this->activity_types['content']['deletion']; $user_id = get_current_user_id(); // Get the current user ID $this->logger->insert_log( $user_id, 'Content', $activity_type, $description, 'deletion', $edit_link ); } }