settings = $settings; $this->visitor = $visitor; } /** * Whether an event in this category may be sent. * * @param string $category Consent category. * @param VisitorContextInterface|null $visitor Whose decision to read; defaults to the current * request. An order reports the decision the customer * made at checkout, not whoever is logged into * wp-admin when the status changes. * @return bool */ public function allows( string $category = self::CATEGORY_STATISTICS, ?VisitorContextInterface $visitor = null ): bool { $visitor = null !== $visitor ? $visitor : $this->visitor; // Opt-out is absolute. It is the visitor's own decision rather than a category preference, so it // is honoured whether or not the site has consent enforcement switched on. if ( $visitor->has_opted_out() ) { $allowed = false; } elseif ( $this->settings->load()->flag( 'respect_consent' ) ) { $allowed = $visitor->allows( $category ); } else { $allowed = true; } /** * Filters whether a server-side event may be sent for this visitor. * * Useful for sites whose consent state lives somewhere this plugin cannot see, such as a * consent management platform that keeps its decision server-side. * * @since 1.0.0 * * @param bool $allowed Whether sending is permitted. * @param string $category Consent category being checked. * @param VisitorContextInterface $visitor The visitor whose decision was read. */ return (bool) apply_filters( 'adpix_analytics_consent_allows', $allowed, $category, $visitor ); } }