activity_types = include plugin_dir_path( ATKAI_PLUGIN_FILE ) . '/activities/types.php'; $this->logger = $logger; add_action( 'add_attachment', array( $this, 'atk_add_attachment' ) ); add_action( 'delete_attachment', array( $this, 'atk_delete_attachment' ) ); add_action( 'attachment_updated', array( $this, 'atk_update_attachment' ) ); } public function atk_add_attachment( $attachment_id ) { // Get the file path of the uploaded media $file_path = get_attached_file( $attachment_id ); // Extract the file name from the file path $file_name = basename( $file_path ); $referrer_url = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : ''; $activity_type = $this->activity_types['media']['upload']; $description = 'Media Added: the file name is ' . $file_name . ''; $user_id = get_current_user_id(); // Get the current user ID $this->logger->insert_log( $user_id, 'Media', $activity_type, $description, 'upload', $referrer_url ); } public function atk_delete_attachment( $attachment_id ) { // Get the file path of the uploaded media $file_path = get_attached_file( $attachment_id ); // Extract the file name from the file path $file_name = basename( $file_path ); $referrer_url = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : ''; $activity_type = $this->activity_types['media']['deletion']; $description = 'Media Deleted: the file name is ' . $file_name . ''; $user_id = get_current_user_id(); // Get the current user ID $this->logger->insert_log( $user_id, 'Media', $activity_type, $description, 'deletion', $referrer_url ); } public function atk_update_attachment( $attachment_id ) { // Get the file path of the uploaded media $file_path = get_attached_file( $attachment_id ); // Extract the file name from the file path $file_name = basename( $file_path ); $referrer_url = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : ''; $activity_type = $this->activity_types['media']['edit']; $description = 'Media Updated: the file name changed is ' . $file_name . ''; $user_id = get_current_user_id(); // Get the current user ID $this->logger->insert_log( $user_id, 'Media', $activity_type, $description, 'edit', $referrer_url ); } }