slug = 'pmp-wp-activity-log'; // Displayed title for this panel. $this->title = \__( 'Member Activity', 'wp-security-audit-log' ); } /** * Events data * * Some PMP events can be triggered only by Admins and will not be returned in this panel. We get only the events that this specific user has triggered. * * @param int $user_id The user ID to fetch events for. * * @return array List of events for this user. * * @since 5.5.2 */ private static function pmp_panel_events( int $user_id ) { $events = Paid_Memberships_Pro_Helper::get_plugin_events(); // Short-circuit if no events are configured to avoid invalid SQL. if ( empty( $events ) ) { return array(); } // Placeholders to spread events in the SQL query. $placeholders = implode( ',', array_fill( 0, count( $events ), '%d' ) ); $sql = Occurrences_Entity::get_connection()->prepare( 'SELECT * FROM ' . Occurrences_Entity::get_table_name() . ' WHERE user_id = %d AND alert_id IN (' . $placeholders . ') ORDER BY created_on DESC LIMIT 10', $user_id, ...$events ); $response = Occurrences_Entity::load_query( $sql ); // Return events with metadata. return Occurrences_Entity::get_multi_meta_array( $response ); } /** * Gets the audit log URL filtered by user. * * @param int $user_id - The user ID to use in the filter for the activity log. * * @return string - The audit log URL with user filter applied. * * @since 5.6.0 */ private static function get_user_activity_log_url( int $user_id ): string { $username = ''; if ( $user_id > 0 ) { $user_data = \get_userdata( $user_id ); if ( $user_data ) { $username = $user_data->user_login; } } $audit_log_url = \admin_url( '?page=wsal-auditlog' ); if ( ! empty( $username ) ) { $audit_log_url = \add_query_arg( array( 'filters[0]' => 'username:' . $username ), $audit_log_url ); } return $audit_log_url; } /** * Display the panel contents. * * @since 5.5.2 */ protected function display_panel_contents() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only panel view, no nonce provided by PMPro. Capability check below. $user_id = isset( $_REQUEST['user_id'] ) ? (int) $_REQUEST['user_id'] : 0; if ( ! \current_user_can( 'edit_users' ) && \get_current_user_id() !== $user_id ) { return array(); } if ( $user_id <= 0 ) { return array(); } $events = self::pmp_panel_events( $user_id ); ?>
| array() ) ); ?> |