roles ); } return true; } private static function scope_ok( array $o ): bool { switch ( $o['display_scope'] ) { case 'none': return false; case 'include': return self::matches( $o ); case 'exclude': return ! self::matches( $o ); default: return true; } } private static function matches( array $o ): bool { $special = (array) $o['display_special']; $checks = array( 'front' => fn() => is_front_page(), 'blog' => fn() => is_home(), 'single' => fn() => is_single(), 'page' => fn() => is_page(), 'archive' => fn() => is_archive(), 'search' => fn() => is_search(), '404' => fn() => is_404(), ); if ( function_exists( 'is_woocommerce' ) ) { $checks += array( 'wc_shop' => fn() => is_shop(), 'wc_product' => fn() => is_product(), 'wc_cart' => fn() => is_cart(), 'wc_checkout' => fn() => is_checkout(), 'wc_account' => fn() => is_account_page(), ); } foreach ( $special as $key ) { if ( isset( $checks[ $key ] ) && $checks[ $key ]() ) { return true; } } if ( $o['display_post_types'] && is_singular( (array) $o['display_post_types'] ) ) { return true; } $ids = array_filter( array_map( 'absint', explode( ',', (string) $o['display_ids'] ) ) ); if ( $ids && is_singular() && in_array( get_queried_object_id(), $ids, true ) ) { return true; } $path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ?? '/' ) ), PHP_URL_PATH ) ?: '/'; foreach ( preg_split( '/\R/u', (string) $o['display_urls'] ) as $pattern ) { $pattern = trim( $pattern ); if ( '' !== $pattern && fnmatch( $pattern, $path ) ) { return true; } } return false; } }