$action, 'object_type' => 'Plugin', 'object_id' => 0, 'object_name' => $plugin_name, ] ); } public function hooks_deactivated_plugin( $plugin_name ) { $this->_add_log_plugin( 'deactivated', $plugin_name ); } public function hooks_activated_plugin( $plugin_name ) { $this->_add_log_plugin( 'activated', $plugin_name ); } public function hooks_plugin_modify( $location, $status ) { if ( false !== strpos( $location, 'plugin-editor.php' ) ) { if ( ( ! empty( $_POST ) && 'update' === $_REQUEST['action'] ) ) { $aal_args = [ 'action' => 'file_updated', 'object_type' => 'Plugin', 'object_subtype' => 'plugin_unknown', 'object_id' => 0, 'object_name' => 'file_unknown', ]; if ( ! empty( $_REQUEST['file'] ) ) { $aal_args['object_name'] = sanitize_text_field( wp_unslash( $_REQUEST['file'] ) ); // Get plugin name $plugin_dir = explode( '/', sanitize_text_field( wp_unslash( $_REQUEST['file'] ) ) ); $plugin_data = array_values( get_plugins( '/' . $plugin_dir[0] ) ); $plugin_data = array_shift( $plugin_data ); $aal_args['object_subtype'] = $plugin_data['Name']; } adminify_activity_logs( $aal_args ); } } // We are need return the instance, for complete the filter. return $location; } /** * @param Plugin_Upgrader $upgrader * @param array $extra */ public function hooks_plugin_install_or_update( $upgrader, $extra ) { if ( ! isset( $extra['type'] ) || 'plugin' !== $extra['type'] ) { return; } if ( 'install' === $extra['action'] ) { $path = $upgrader->plugin_info(); if ( ! $path ) { return; } $data = get_plugin_data( $upgrader->skin->result['local_destination'] . '/' . $path, true, false ); adminify_activity_logs( [ 'action' => 'installed', 'object_type' => 'Plugin', 'object_name' => $data['Name'], 'object_subtype' => $data['Version'], ] ); } if ( 'update' === $extra['action'] ) { if ( isset( $extra['bulk'] ) && true == $extra['bulk'] ) { $slugs = $extra['plugins']; } else { if ( ! isset( $upgrader->skin->plugin ) ) { return; } $slugs = [ $upgrader->skin->plugin ]; } foreach ( $slugs as $slug ) { $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $slug, true, false ); adminify_activity_logs( [ 'action' => 'updated', 'object_type' => 'Plugin', 'object_name' => esc_html( $data['Name'] ), 'object_subtype' => esc_html( $data['Version'] ), ] ); } } } }