activity_types = include plugin_dir_path( ATKAI_PLUGIN_FILE ) . '/activities/types.php'; $this->logger = $logger; add_filter( 'widget_update_callback', array( $this, 'atk_widget_update' ), 99, 4 ); add_action( 'sidebar_admin_setup', array( $this, 'atk_detect_sidebar_changes') ); add_action( 'delete_widget', array( $this, 'atk_widget_deletion'), 10, 3 ); } public function atk_widget_update($instance, $new_instance, $old_instance, WP_Widget $this_widget) { // only allow users who can edit widgets/themes if ( ! current_user_can( 'edit_theme_options' ) ) { return $instance; } if ( $new_instance != $old_instance ) { $description = 'Widget Updated: '. $this_widget->id_base .''; $activity_type = $this->activity_types['widget']['edit']; $user_id = get_current_user_id(); // Get the current user ID $this->logger->insert_log( $user_id, 'Widget', $activity_type, $description, 'edit' ); } return $instance; } public function atk_detect_sidebar_changes() { // only allow users who can edit widgets/themes if ( ! current_user_can( 'edit_theme_options' ) ) { return; } $method = isset( $_SERVER['REQUEST_METHOD'] ) ? strtolower( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ) : ''; // 2) Bail if it's not a POST or if our field isn't there if ( 'post' !== $method || ! isset( $_POST['sidebar'] ) ) { return; } // 3) Now safely pull in the actual value $sidebar_id = sanitize_text_field( wp_unslash( $_POST['sidebar'] ) ); // Grab & unslash the raw POST array (will recursively unslash strings in arrays) $added_widgets = isset( $_POST['widget-id'] ) && is_array( $_POST['widget-id'] ) // wp_unslash reverses magic‐quotes; sanitize_text_field cleans each value ? array_map( 'sanitize_text_field', wp_unslash( $_POST['widget-id'] ) ) : []; $description = sprintf( 'Sidebar Edited: %s. Widgets: %s', $sidebar_id, implode( ', ', $added_widgets ) ); $activity_type = $this->activity_types['widget']['sidebar']; $user_id = get_current_user_id(); $this->logger->insert_log( $user_id, 'Widget', $activity_type, $description, 'sidebar' ); } public function atk_widget_deletion($widget_id, $sidebar_id, $id_base){ $description = "Widget Deleted: Widget ID - " . $widget_id . ", Sidebar ID - " . $sidebar_id . ", Widget Type - " . $id_base; $activity_type = $this->activity_types['widget']['deletion']; $user_id = get_current_user_id(); // Get the current user ID $this->logger->insert_log( $user_id, 'Widget', $activity_type, $description, 'deletion' ); } }