PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.2.0
Forumax – AI Powered Advanced Community Forum Plugin v2.2.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / template-functions.php

template-functions.php in Forumax – AI Powered Advanced Community Forum Plugin 2.2.0, at includes/template-functions.php

123 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Template Functions for Forumax
4 *
5 * @package Forumax
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Register external template stack locations
12 * @return void
13 */
14 add_action( 'after_setup_theme', 'forumax_register_external_templates', 5 );
15 function forumax_register_external_templates() {
16
17 /**
18 * External templates (themes + plugins) - HIGHEST PRIORITY
19 * This allows theme templates to override plugin templates
20 * @return void
21 */
22 foreach ( forumax_get_external_template_dirs() as $dir ) {
23 bbp_register_template_stack( fn() => trailingslashit( $dir ), 1 );
24 }
25
26 /**
27 * Plugin fallback templates - LOWER PRIORITY
28 * (runs if theme doesn't override)
29 * @return void
30 */
31 bbp_register_template_stack( fn() => trailingslashit( FORUMAX_PATH . 'templates' ), 5 );
32 }
33
34 /**
35 * Get template directories from themes, child themes, and plugins
36 * using /forumax or /bbpress folders (when supported).
37 *
38 * @return array
39 */
40 function forumax_get_external_template_dirs() {
41 $dirs = [];
42 $slugs = [ 'forumax', 'bbpress' ];
43 $themes = [ get_template_directory(), get_stylesheet_directory() ];
44
45 // === Themes ===
46 foreach ( array_unique( $themes ) as $theme ) {
47 foreach ( $slugs as $slug ) {
48 $path = trailingslashit( $theme ) . $slug . '/';
49 if ( is_dir( $path ) ) {
50 $dirs[] = $path;
51 }
52 }
53 }
54
55 // === Plugins ===
56 foreach ( glob( WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR ) as $plugin ) {
57 if ( 'forumax' === basename( $plugin ) ) {
58 continue;
59 }
60
61 foreach ( $slugs as $slug ) {
62 $path = trailingslashit( $plugin ) . $slug . '/';
63 if ( is_dir( $path ) ) {
64 $dirs[] = $path;
65 }
66 }
67 }
68
69 return $dirs;
70 }
71
72 /**
73 * Extend bbPress template locations
74 */
75 add_filter( 'bbp_get_template_locations', 'forumax_extend_template_locations', 10, 2 );
76 function forumax_extend_template_locations( $locations ) {
77
78 foreach ( [ 'forumax', 'bbpress' ] as $slug ) {
79 if ( ! in_array( $slug, $locations, true ) ) {
80 array_unshift( $locations, $slug );
81 }
82 }
83
84 return $locations;
85 }
86
87 /**
88 * Banner preset background styles
89 *
90 * @return array[]|string[]
91 */
92 function forumax_banner_bg_style() {
93 return [
94 'color' => FORUMAX_IMG . '/options/color.png',
95 'faded-sun' => FORUMAX_IMG . '/options/faded-sun.jpg',
96 'happy-journey' => FORUMAX_IMG . '/options/happy-journey.jpg',
97 'apparent-circle' => FORUMAX_IMG . '/options/apparent-circle.jpg',
98 'soft-weather' => FORUMAX_IMG . '/options/soft-weather.jpg',
99 'romantic-sun' => FORUMAX_IMG . '/options/romantic-sun.jpg',
100 'teal-eclipse' => FORUMAX_IMG . '/options/teal-eclipse.jpg',
101 ];
102 }
103
104
105
106 /**
107 * Image from Settings
108 *
109 * @param string $option_id
110 * @param string $class
111 * @param string $alt
112 */
113 function get_image_from_settings( string $option_id = '', string $class = '', string $alt = '' ):void {
114 $image = forumax_get_opt($option_id) ?? '';
115
116 // Check if the image has an 'id' or a 'url' and display accordingly
117 if ( ! empty($image['id']) ) {
118 echo wp_get_attachment_image($image['id'], 'full', '' );
119 } elseif ( !empty($image['url']) ) {
120 echo "<img src='{$image['url']}'>";
121 }
122 }
123