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

149 lines 3.1 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 the Page is Forum page
23 */
24 function bbpc_is_forum_page() {
25 if ( in_array( 'bbpress', get_body_class() ) ) {
26 return true;
27 }
28 }
29
30 /**
31 * Check if the pro plugin and plan is active
32 *
33 * @return bool|void
34 */
35 function bbpc_is_premium() {
36 if ( class_exists('BBPCorePro') && bc_fs()->can_use_premium_code() ) {
37 return true;
38 }
39 }
40
41 /**
42 * BBP Core Admin pages
43 * If any of the admin pages match the current page, return true.
44 *
45 * @return bool|void
46 */
47 function bbpc_admin_pages($admin) {
48 $current_url = ! empty( $_GET['page'] ) ? admin_url( 'admin.php?page=' ) . sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
49
50 if ( $admin == 'admin' ){
51 if ( $current_url == admin_url('admin.php?page=bbp-core') ) {
52 return true;
53 }
54 } elseif ( $admin == 'settings' ) {
55 if ( $current_url == admin_url('admin.php?page=bbp-core-settings') ) {
56 return true;
57 }
58 }
59 }
60
61 function bbpc_forum_assets(){
62 if ( bbp_is_single_forum() || bbp_is_single_topic() ) {
63 return true;
64 }
65 }
66
67
68 /**
69 * Posts Arraty
70 * @param object Post Type
71 */
72 function bbp_core_get_posts( $post_type = 'forum' ) {
73 $posts = get_pages(
74 [
75 'post_type' => $post_type,
76 'parent' => 0,
77 ]
78 );
79
80 $posts_array = [];
81
82 if ( $posts ) {
83 foreach ( $posts as $post ) {
84 $posts_array[ $post->ID ] = $post->post_title;
85 }
86 }
87
88 return $posts_array;
89 }
90
91 /**
92 * Limit letter
93 * @param $string
94 * @param $limit_length
95 * @param string $suffix
96 */
97 function bbp_core_limit_letter( $string, $limit_length, $suffix = '...' ) {
98 if ( strlen( $string ) > $limit_length ) {
99 echo strip_shortcodes( substr( $string, 0, $limit_length ) . $suffix );
100 } else {
101 echo strip_shortcodes( esc_html( $string ) );
102 }
103 }
104
105 /**
106 * Return the topic view count.
107 *
108 * @param int $topic_id Optional. Topic id
109 *
110 * @return int The view count
111 * @uses get_post_meta() To get the view count meta
112 * @uses bbp_get_topic_id() To get the topic id
113 */
114 function bbp_get_topic_view_count( $topic_id = 0 ) {
115 $topic_id = bbp_get_topic_id( $topic_id );
116
117 if ( empty( $topic_id ) ) {
118 return 0;
119 }
120
121 $views = (int) get_post_meta( $topic_id, '_btv_view_count', true );
122
123 return $views;
124 }
125
126 /**
127 * Output the topic view count.
128 *
129 * @param int $topic_id Optional. Topic id
130 *
131 * @uses bbp_get_topic_id() To get the topic id
132 * @uses btv_get_topic_view_count() To get the view count for the topic
133 */
134 function bbp_topic_view_count( $topic_id = 0 ) {
135 $topic_id = bbp_get_topic_id( $topic_id );
136 $view_count = bbp_get_topic_view_count( $topic_id );
137 return $view_count;
138 }
139
140
141 /**
142 * Get forum title
143 * @return string
144 */
145 function bbpc_forum_title(){
146 $forum_id = bbp_get_forum_id();
147 $forum_title = get_the_title( $forum_id );
148 return $forum_title;
149 }