PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.4.0
Forumax – AI Powered Advanced Community Forum Plugin v1.4.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 1.4.0, at includes/functions.php

203 lines 4.7 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 bbpc_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 bbpc_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 bbpc_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 bbpc_is_premium() {
62 if ( class_exists('BBPCorePro') && bc_fs()->can_use_premium_code() ) {
63 return true;
64 }
65 }
66
67 /**
68 * BBP Core Admin pages
69 * If any of the admin pages match the current page, return true.
70 *
71 * @return bool|void
72 */
73 function bbpc_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=bbp-core') ) {
78 return true;
79 }
80 } elseif ( $admin == 'settings' ) {
81 if ( $current_url == admin_url('admin.php?page=bbp-core-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 bbpc_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 bbp_core_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 bbp_core_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( strip_shortcodes( 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 bbp_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 bbp_topic_view_count( $topic_id = 0 ) {
167 $topic_id = bbp_get_topic_id( $topic_id );
168 $view_count = bbp_get_topic_view_count( $topic_id );
169 return $view_count;
170 }
171
172 /**
173 * Get forum title
174 * @return string
175 */
176 function bbpc_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 bbpc_get_registered_nav_menus() {
194 $menus = get_registered_nav_menus();
195 $menu_locations = [];
196 $empty = [ '' => esc_html__('Select Menu Location', 'bbp-core') ];
197 foreach ( $menus as $location => $description ) {
198 $menu_locations[ $location ] = $description;
199 }
200
201 return $empty + $menu_locations;
202 }
203