| @@ -70,25 +70,30 @@ | ||
| 70 | 70 | * |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | 73 | function forumax_is_hello_theme() { |
| 74 | - $theme = wp_get_theme(); | |
| 75 | - $stylesheet = $theme->get_stylesheet(); | |
| 76 | - $template = $theme->get_template(); | |
| 74 | + // Runs on every bbPress template lookup; resolve it once per request/theme. | |
| 75 | + static $cache = array(); | |
| 77 | 76 | |
| 77 | + $stylesheet = get_stylesheet(); | |
| 78 | + $template = get_template(); | |
| 79 | + $key = $stylesheet . '|' . $template; | |
| 80 | + | |
| 81 | + if ( isset( $cache[ $key ] ) ) { | |
| 82 | + return $cache[ $key ]; | |
| 83 | + } | |
| 84 | + | |
| 78 | 85 | $hello_slugs = array( 'hello-elementor', 'hello-biz' ); |
| 79 | 86 | |
| 87 | + $cache[ $key ] = false; | |
| 80 | 88 | foreach ( $hello_slugs as $slug ) { |
| 81 | - if ( $slug === $template || 0 === strpos( $template, $slug ) ) { | |
| 82 | - return true; | |
| 89 | + if ( 0 === strpos( $template, $slug ) || 0 === strpos( $stylesheet, $slug ) ) { | |
| 90 | + $cache[ $key ] = true; | |
| 91 | + break; | |
| 83 | 92 | } |
| 84 | - | |
| 85 | - if ( $slug === $stylesheet || 0 === strpos( $stylesheet, $slug ) ) { | |
| 86 | - return true; | |
| 87 | - } | |
| 88 | 93 | } |
| 89 | 94 | |
| 90 | - return false; | |
| 95 | + return $cache[ $key ]; | |
| 91 | 96 | } |
| 92 | 97 | |
| 93 | 98 | /** |
| 94 | 99 | * Ensure Forumax templates are preferred on Hello theme. |