ID : 0; } /** * Whether the client that asked for this page is a machine. * * Two ways to be one, and the second is the point of the whole feature: * * 1. The User-Agent says so — anything {@see Classifier::classify()} does not * call a plain 'Browser'. That is the same line {@see Referrals} draws, in * the same direction, so a visit is either a human referral or a machine * read and never both. * 2. ⭐ It carried a SIGNATURE. An agent driving a real browser sends a real * browser's User-Agent, and no amount of string-matching will ever separate * it from the person whose laptop it is running on. A signature can, and it * is the only thing that can — so a signed request is a machine no matter * what it calls itself. This is exactly the traffic the log was blind to. * * ⚠️ THE ABSENCE NAMES ITSELF: an unsigned agent behind a browser UA is * indistinguishable from a reader and is counted as one. Nothing here guesses. * * @return bool */ private static function is_machine() { $ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only classification, no state change. if ( 'Browser' !== Classifier::classify( $ua ) ) { return true; } // Cheap for the overwhelming majority: with no signature headers on the // request, inspect() returns 'unsigned' after four isset() checks and the // verdict is memoised for the rest of the request either way. return Guard::verification_on() && '' !== BotSignature::face(); } /** * Whether page-view logging is on. Requires BOTH switches: the master activity * toggle, and this stream's own — the volume is a different order of magnitude * from the endpoint stream, so it gets its own answer. * * @return bool */ public static function enabled() { if ( null === self::$enabled ) { $settings = new Settings(); /** * Filter whether machine page views are recorded. * * @param bool $on Whether both the activity log and this stream are enabled. */ self::$enabled = (bool) apply_filters( 'agentimus_log_page_views', $settings->enabled( 'enable_activity' ) && $settings->enabled( 'log_page_views' ) ); } return self::$enabled; } /** * Test seam: forget the cached enable flag. * * @internal * @return void */ public static function reset_cache() { self::$enabled = null; } }