publishedSet->all(); // EVERY Optin, including the drafts — the funnel's first gate is // *published*, and it is the commonest answer of all. $summaries = $this->optins->summaries(); $suspensions = Suspension::reasonsIn($set, $this->degradation, $this->rules); // **The clock is read here, on a request that reached PHP.** This one // is uncached by construction — `DONOTCACHEPAGE` above, and the // capability check before it — so "3 days" is 3 days as of now rather // than as of whenever a cache last filled. $schedules = InspectorSchedules::forSet($set, time()); // The same context the payload was decided against: term resolution is // conditional on the published set for the reason it always was, so // asking again here costs a page with no term rule nothing. $context = RequestContextFactory::forPublishedSet(PublishedOptin::fromSet($set), $this->roles); $labels = InspectorLabels::all(); add_action('wp_head', static function () use ($summaries, $suspensions, $schedules, $set, $context, $labels): void { // Not escaped, and correctly so — the same argument PayloadTag // carries one file over: JSON_HEX_TAG is the escaping this context // needs, and esc_html() over it would produce invalid JSON that // fails silently in the browser. There is no URL on this tag, so // there is nothing here for esc_url() either. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- InspectorTag::render() escapes for this context with JSON_HEX_TAG; the tag carries no URL. echo InspectorTag::render($summaries, $suspensions, $schedules, $set, $context, $labels); }, self::HEAD_PRIORITY); } /** * Has an administrator asked for this, on a page a visitor is looking at? * * ======================================================================== * THE CAPABILITY IS CHECKED FIRST AND IT IS NOT NEGOTIABLE. * ======================================================================== * A logged-out visitor and a subscriber get **no tag and no script** — * not a hidden panel, not an empty one. The report names every Optin on * the site, published or draft, with the rules behind each; it is the * single richest thing this plugin could accidentally print on a public * page. * * `Routes::MANAGE_CAPABILITY` rather than a literal, so the inspector and * the admin screens can never disagree about who may see this. * * The parameter is only read for presence. Nothing is done with its value, * so there is nothing to sanitise beyond that — and a nonce would be * wrong here rather than merely absent: this is a link a merchant is meant * to be able to type, bookmark and paste to a colleague, and it changes * nothing on the site. */ private static function asked(): bool { if (is_admin() || is_feed() || is_robots() || is_embed()) { return false; } if (!current_user_can(Routes::MANAGE_CAPABILITY)) { return false; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- A read-only diagnostic gated on manage_options; presence only, no value is read. return isset($_GET[self::PARAM]); } }