*/ public static function caching_sensitive_types(): array { /** * Filters the condition types that get the page caching warning. Pro adds its own. * * @param array $types Condition type IDs. */ return apply_filters( 'yangra_conditional_caching_sensitive_types', array( 'visitor_device' ) ); } /** * Warnings and tips for a condition type. * * @param string $type Condition type ID. * @return array Status is "warning" or "info". */ public static function for_type( string $type ): array { $caching = array( 'status' => 'warning', 'text' => __( 'This condition may show the wrong result if your site uses page caching.', 'yangra-conditional' ), ); $notices = array( 'user_role' => array( array( 'status' => 'info', 'text' => __( 'Logged-out visitors have no role, so they never match "is" and always match "is not".', 'yangra-conditional' ), ), ), 'visitor_device' => array( array( 'status' => 'info', 'text' => __( 'Tablets count as mobile.', 'yangra-conditional' ), ), ), ); $type_notices = $notices[ $type ] ?? array(); if ( in_array( $type, self::caching_sensitive_types(), true ) ) { array_unshift( $type_notices, $caching ); } /** * Filters the warnings and tips shown next to a condition. Pro adds * them for its own conditions. * * @param mixed $type_notices Notices, each array{status: string, text: string}; status is "warning" or "info". * Anything else is dropped. * @param string $type Condition type ID. */ $filtered = apply_filters( 'yangra_conditional_condition_notices', $type_notices, $type ); $clean = array(); foreach ( (array) $filtered as $notice ) { if ( is_array( $notice ) && isset( $notice['status'], $notice['text'] ) && in_array( $notice['status'], array( 'warning', 'info' ), true ) ) { $clean[] = array( 'status' => (string) $notice['status'], 'text' => (string) $notice['text'], ); } } return $clean; } }