= $required_time; } /** * Check If the Page is Forum page */ function forumax_is_forum_page() { if ( in_array( 'bbpress', get_body_class() ) ) { return true; } } /** * Check if the pro plugin and plan is active * * @return bool|void */ function forumax_is_premium() { if ( class_exists('Forumax_Pro') && bc_fs()->can_use_premium_code() ) { return true; } } /** * Forumax Admin pages * If any of the admin pages match the current page, return true. * * @return bool|void */ function forumax_admin_pages($admin) { $current_url = ! empty( $_GET['page'] ) ? admin_url( 'admin.php?page=' ) . sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; if ( $admin == 'admin' ){ if ( $current_url == admin_url('admin.php?page=forumax') ) { return true; } } elseif ( $admin == 'settings' ) { if ( $current_url == admin_url('admin.php?page=forumax-settings') ) { return true; } } } /** * BBP Forum Assets * Checks if the current page is a single forum or a single topic. * * @return bool True if the current page is a single forum or topic, false otherwise. */ function forumax_forum_and_topic_page(){ if ( bbp_is_single_forum() || bbp_is_single_topic() || bbp_is_reply_edit()) { return true; } } /** * Posts Arraty * @param object Post Type */ function forumax_get_posts( $post_type = 'forum' ) { $posts = get_pages( [ 'post_type' => $post_type, 'parent' => 0, ] ); $posts_array = []; if ( $posts ) { foreach ( $posts as $post ) { $posts_array[ $post->ID ] = $post->post_title; } } return $posts_array; } /** * Limit letter * @param $string * @param $limit_length * @param string $suffix */ function forumax_limit_letter( $string, $limit_length, $suffix = '...' ) { if ( strlen( $string ) > $limit_length ) { echo esc_html ( strip_shortcodes( substr( $string, 0, $limit_length ) . $suffix ) ); } else { echo esc_html( $string ); } } /** * Return the topic view count. * * @param int $topic_id Optional. Topic id * * @return int The view count * @uses get_post_meta() To get the view count meta * @uses bbp_get_topic_id() To get the topic id */ function forumax_get_topic_view_count( $topic_id = 0 ) { $topic_id = bbp_get_topic_id( $topic_id ); if ( empty( $topic_id ) ) { return 0; } $views = (int) get_post_meta( $topic_id, '_btv_view_count', true ); return $views; } /** * Output the topic view count. * * @param int $topic_id Optional. Topic id * * @uses bbp_get_topic_id() To get the topic id * @uses btv_get_topic_view_count() To get the view count for the topic */ function forumax_topic_view_count( $topic_id = 0 ) { $topic_id = bbp_get_topic_id( $topic_id ); $view_count = forumax_get_topic_view_count( $topic_id ); return $view_count; } /** * Get forum title * @return string */ function forumax_forum_title(){ $forum_id = bbp_get_forum_id(); $forum_title = get_the_title( $forum_id ); return $forum_title; } /** * Customizer section hide from customizer */ add_action( 'customize_register', function( $wp_customize ) { // Unset the section you want to hide $wp_customize->remove_section( 'design_fields' ); }, 20 ); /** * Get all the registered menus */ function forumax_get_registered_nav_menus() { $menus = get_registered_nav_menus(); $menu_locations = []; $empty = [ '' => esc_html__('Select Menu Location', 'forumax') ]; foreach ( $menus as $location => $description ) { $menu_locations[ $location ] = $description; } return $empty + $menu_locations; } /** * Enable REST API for bbPress forum post type * This allows the forum post type to be accessed via the WordPress REST API * which is required for the Gutenberg block to fetch forum data */ function forumax_enable_forum_rest_api() { $post_type_obj = get_post_type_object( 'forum' ); if ( $post_type_obj ) { $post_type_obj->show_in_rest = true; } } add_action( 'init', 'forumax_enable_forum_rest_api', 20 ); /** * Mutual Deactivation of Forumax and bbp-core plugins */ add_action( 'activated_plugin', function( $plugin ) { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // All Forumax plugins $forumax_plugins = array( 'forumax/forumax.php', 'forumax-pro/forumax.php', ); // All bbp-core plugins $bbp_core_plugins = array( 'bbp-core/bbp-core.php', 'bbp-core-pro/bbp-core.php', ); // If activating Forumax (free or pro) → deactivate bbp-core (all versions) if ( in_array( $plugin, $forumax_plugins, true ) ) { deactivate_plugins( $bbp_core_plugins ); } // If activating bbp-core (free or pro) → deactivate Forumax (all versions) if ( in_array( $plugin, $bbp_core_plugins, true ) ) { deactivate_plugins( $forumax_plugins ); } } );