PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.0.0
Forumax – AI Powered Advanced Community Forum Plugin v2.0.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 / functions.php

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

248 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get the value of a settings field.
4 *
5 * @param string $option settings field name
6 * @param string $section the section name this field belongs to
7 * @param string $default default text if it's not found
8 *
9 * @return mixed
10 */
11 function forumax_get_opt( $option, $default = '' ) {
12 $options = get_option( 'bbp_core_settings' );
13
14 if ( isset( $options[ $option ] ) ) {
15 return $options[ $option ];
16 }
17
18 return $default;
19 }
20
21 /**
22 * Check if a plugin has been installed for specific number of days
23 *
24 * @param string $plugin_path The plugin path (e.g. 'woocommerce/woocommerce.php')
25 * @param int $days Number of days to check against
26 * @return bool True if plugin is installed for specified days, false otherwise
27 */
28 function forumax_is_plugin_installed_for_days( $days, $plugin_slug='eazydocs' ) {
29 // Get the installation timestamp of the plugin
30 $installed_time = get_option( $plugin_slug . '_installed' );
31
32 // Ensure it's a valid timestamp
33 if ( ! is_numeric( $installed_time ) || $installed_time <= 0 ) {
34 return false;
35 }
36
37 // Convert days to seconds
38 $required_time = (int) $days * DAY_IN_SECONDS;
39
40 // Get the current UTC time
41 $current_time = time();
42
43 // Check if the plugin has been installed for the required duration
44 return ( $current_time - $installed_time ) >= $required_time;
45 }
46
47 /**
48 * Check If the Page is Forum page
49 */
50 function forumax_is_forum_page() {
51 if ( in_array( 'bbpress', get_body_class() ) ) {
52 return true;
53 }
54 }
55
56 /**
57 * Check if the pro plugin and plan is active
58 *
59 * @return bool|void
60 */
61 function forumax_is_premium() {
62 if ( class_exists('Forumax_Pro') && bc_fs()->can_use_premium_code() ) {
63 return true;
64 }
65 }
66
67 /**
68 * Forumax Admin pages
69 * If any of the admin pages match the current page, return true.
70 *
71 * @return bool|void
72 */
73 function forumax_admin_pages($admin) {
74 $current_url = ! empty( $_GET['page'] ) ? admin_url( 'admin.php?page=' ) . sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
75
76 if ( $admin == 'admin' ){
77 if ( $current_url == admin_url('admin.php?page=forumax') ) {
78 return true;
79 }
80 } elseif ( $admin == 'settings' ) {
81 if ( $current_url == admin_url('admin.php?page=forumax-settings') ) {
82 return true;
83 }
84 }
85 }
86
87 /**
88 * BBP Forum Assets
89 * Checks if the current page is a single forum or a single topic.
90 *
91 * @return bool True if the current page is a single forum or topic, false otherwise.
92 */
93 function forumax_forum_and_topic_page(){
94 if ( bbp_is_single_forum() || bbp_is_single_topic() || bbp_is_reply_edit()) {
95 return true;
96 }
97 }
98
99
100 /**
101 * Posts Arraty
102 * @param object Post Type
103 */
104 function forumax_get_posts( $post_type = 'forum' ) {
105 $posts = get_pages(
106 [
107 'post_type' => $post_type,
108 'parent' => 0,
109 ]
110 );
111
112 $posts_array = [];
113
114 if ( $posts ) {
115 foreach ( $posts as $post ) {
116 $posts_array[ $post->ID ] = $post->post_title;
117 }
118 }
119
120 return $posts_array;
121 }
122
123 /**
124 * Limit letter
125 * @param $string
126 * @param $limit_length
127 * @param string $suffix
128 */
129 function forumax_limit_letter( $string, $limit_length, $suffix = '...' ) {
130 if ( strlen( $string ) > $limit_length ) {
131 echo esc_html ( strip_shortcodes( substr( $string, 0, $limit_length ) . $suffix ) );
132 } else {
133 echo esc_html( $string );
134 }
135 }
136
137 /**
138 * Return the topic view count.
139 *
140 * @param int $topic_id Optional. Topic id
141 *
142 * @return int The view count
143 * @uses get_post_meta() To get the view count meta
144 * @uses bbp_get_topic_id() To get the topic id
145 */
146 function forumax_get_topic_view_count( $topic_id = 0 ) {
147 $topic_id = bbp_get_topic_id( $topic_id );
148
149 if ( empty( $topic_id ) ) {
150 return 0;
151 }
152
153 $views = (int) get_post_meta( $topic_id, '_btv_view_count', true );
154
155 return $views;
156 }
157
158 /**
159 * Output the topic view count.
160 *
161 * @param int $topic_id Optional. Topic id
162 *
163 * @uses bbp_get_topic_id() To get the topic id
164 * @uses btv_get_topic_view_count() To get the view count for the topic
165 */
166 function forumax_topic_view_count( $topic_id = 0 ) {
167 $topic_id = bbp_get_topic_id( $topic_id );
168 $view_count = forumax_get_topic_view_count( $topic_id );
169 return $view_count;
170 }
171
172 /**
173 * Get forum title
174 * @return string
175 */
176 function forumax_forum_title(){
177 $forum_id = bbp_get_forum_id();
178 $forum_title = get_the_title( $forum_id );
179 return $forum_title;
180 }
181
182 /**
183 * Customizer section hide from customizer
184 */
185 add_action( 'customize_register', function( $wp_customize ) {
186 // Unset the section you want to hide
187 $wp_customize->remove_section( 'design_fields' );
188 }, 20 );
189
190 /**
191 * Get all the registered menus
192 */
193 function forumax_get_registered_nav_menus() {
194 $menus = get_registered_nav_menus();
195 $menu_locations = [];
196 $empty = [ '' => esc_html__('Select Menu Location', 'forumax') ];
197 foreach ( $menus as $location => $description ) {
198 $menu_locations[ $location ] = $description;
199 }
200
201 return $empty + $menu_locations;
202 }
203
204 /**
205 * Enable REST API for bbPress forum post type
206 * This allows the forum post type to be accessed via the WordPress REST API
207 * which is required for the Gutenberg block to fetch forum data
208 */
209 function forumax_enable_forum_rest_api() {
210 $post_type_obj = get_post_type_object( 'forum' );
211 if ( $post_type_obj ) {
212 $post_type_obj->show_in_rest = true;
213 }
214 }
215 add_action( 'init', 'forumax_enable_forum_rest_api', 20 );
216
217 /**
218 * Mutual Deactivation of Forumax and bbp-core plugins
219 */
220 add_action( 'activated_plugin', function( $plugin ) {
221 if ( ! function_exists( 'is_plugin_active' ) ) {
222 require_once ABSPATH . 'wp-admin/includes/plugin.php';
223 }
224
225 // All Forumax plugins
226 $forumax_plugins = array(
227 'forumax/forumax.php',
228 'forumax-pro/forumax.php',
229 );
230
231 // All bbp-core plugins
232 $bbp_core_plugins = array(
233 'bbp-core/bbp-core.php',
234 'bbp-core-pro/bbp-core.php',
235 );
236
237 // If activating Forumax (free or pro) → deactivate bbp-core (all versions)
238 if ( in_array( $plugin, $forumax_plugins, true ) ) {
239 deactivate_plugins( $bbp_core_plugins );
240 }
241
242 // If activating bbp-core (free or pro) → deactivate Forumax (all versions)
243 if ( in_array( $plugin, $bbp_core_plugins, true ) ) {
244 deactivate_plugins( $forumax_plugins );
245 }
246 } );
247
248