exclusions(); $rule = array( 'source' => 'document', 'where' => array( 'and' => array( array( 'href_matches' => '/*' ), array( 'not' => array( 'href_matches' => $exclusions ) ), ), ), 'eagerness' => 'moderate', ); $payload = array( $mode => array( $rule ) ); $payload = apply_filters( 'nbh_performance_speculation_rules', $payload, $mode ); if ( empty( $payload ) ) { return; } wp_print_inline_script_tag( (string) wp_json_encode( $payload, JSON_UNESCAPED_SLASHES ), array( 'type' => 'speculationrules', 'id' => 'nbh-performance-speculation-rules', ) ); } /** @return array */ private function exclusions() { $defaults = array( '/wp-admin/*', '/wp-login.php*', '/*?*add-to-cart=*', '/*?*wc-ajax=*', '/cart/*', '/checkout/*', '/my-account/*', ); $custom = preg_split( '/\r\n|\r|\n/', (string) get_option( 'nbh_performance_speculation_exclusions', '' ) ); $custom = array_values( array_filter( array_map( 'sanitize_text_field', (array) $custom ) ) ); return array_values( array_unique( array_merge( $defaults, $custom ) ) ); } }