can_inject_tag() || ! $this->passes_exclusions( $settings ) ) { return false; } /** * Filters whether the AdPix tag is printed on this request. * * Runs last, so a theme can restore the tag on a view the settings excluded as well as remove * it from one they allowed. * * @since 1.0.0 * * @param bool $should_inject Whether to print the tag. * @param Settings $settings Current configuration. */ return (bool) apply_filters( 'adpix_analytics_should_inject_tag', true, $settings ); } /** * Whether the site's own extra markup should be printed for this request. * * Held to the same exclusions as the tag, but not to the same credentials: a verification meta * tag or a third-party snippet is a legitimate reason to use this field on a site that has not * finished connecting, and refusing to print it until then would be surprising. * * @param Settings $settings Current configuration. * @return bool */ public function allows_custom_code( Settings $settings ): bool { if ( '' === $settings->str( 'custom_code' ) || ! $this->passes_exclusions( $settings ) ) { return false; } /** * Filters whether the site's custom code block is printed on this request. * * @since 1.0.0 * * @param bool $should_print Whether to print the block. * @param Settings $settings Current configuration. */ return (bool) apply_filters( 'adpix_analytics_should_print_custom_code', true, $settings ); } /** * The exclusion rules shared by everything this plugin prints to a page. * * @param Settings $settings Current configuration. * @return bool */ private function passes_exclusions( Settings $settings ): bool { if ( is_admin() && ! $settings->flag( 'tag_admin_area' ) ) { return false; } if ( $this->is_excluded_user( $settings ) ) { return false; } return is_admin() || ! $this->is_excluded_view( $settings ); } /** * Whether the logged-in user holds a role that is excluded from measurement. * * @param Settings $settings Current configuration. * @return bool */ private function is_excluded_user( Settings $settings ): bool { $excluded = $settings->arr( 'exclude_roles' ); if ( array() === $excluded || ! is_user_logged_in() ) { return false; } $user = wp_get_current_user(); return array() !== array_intersect( (array) $user->roles, $excluded ); } /** * Whether the view being rendered is one the settings exclude. * * @param Settings $settings Current configuration. * @return bool */ private function is_excluded_view( Settings $settings ): bool { if ( $settings->flag( 'exclude_search_archive' ) && ( is_search() || is_archive() ) ) { return true; } $ids = $settings->excluded_post_ids(); if ( array() === $ids ) { return false; } // get_queried_object_id() rather than get_the_ID(), so the rule matches the page the visitor // asked for and not whichever post the main loop happens to be on when the tag is enqueued. $current = (int) get_queried_object_id(); return 0 !== $current && in_array( $current, $ids, true ); } }