exists() ) { $user = $u->user_login; } elseif ( wp_doing_cron() ) { $user = 'cron'; } } $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prefix . 'aicitare_logs', array( 'action' => substr( (string) $action, 0, 60 ), 'detail' => substr( (string) $detail, 0, 255 ), 'log_user' => substr( (string) $user, 0, 60 ), 'created_at' => current_time( 'mysql' ), ), array( '%s', '%s', '%s', '%s' ) ); } /** Most recent entries. */ public static function recent( $limit = 200 ) { global $wpdb; $table = $wpdb->prefix . 'aicitare_logs'; $rows = $wpdb->get_results( $wpdb->prepare( "SELECT action, detail, log_user, created_at FROM {$table} ORDER BY id DESC LIMIT %d", $limit ), ARRAY_A ); // phpcs:ignore return is_array( $rows ) ? $rows : array(); } /** Remove all entries. */ public static function clear() { global $wpdb; $table = $wpdb->prefix . 'aicitare_logs'; $wpdb->query( "TRUNCATE TABLE {$table}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- table name is $wpdb->prefix + a hardcoded literal; cannot be a bound parameter. self::add( 'logs_cleared', 'Activity log cleared' ); } }