PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.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 All 31 releases
← All changes | includes/functions.php +96 -25 2.4.0 → 2.5.1 View file →
@@ -18,8 +18,30 @@
18 18 return $default;
19 19 }
20 20
21 21 /**
22 + * Render the guest login form used on topic/reply/forum prompts.
23 + *
24 + * Uses the Shortcodes setting when set; otherwise falls back to [forumax_login_form]
25 + * so Sign In / Create Account tabs always appear (when registration is allowed).
26 + *
27 + * @return void
28 + */
29 +function forumax_render_topic_login_form() {
30 + $shortcode = '';
31 +
32 + if ( function_exists( 'forumax_get_opt' ) ) {
33 + $shortcode = trim( (string) forumax_get_opt( 'topic_login_shortcode', '[forumax_login_form]' ) );
34 + }
35 +
36 + if ( '' === $shortcode ) {
37 + $shortcode = '[forumax_login_form]';
38 + }
39 +
40 + echo do_shortcode( $shortcode ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
41 +}
42 +
43 +/**
22 44 * Check if a plugin has been installed for specific number of days
23 45 *
24 46 * @param string $plugin_path The plugin path (e.g. 'woocommerce/woocommerce.php')
25 47 * @param int $days Number of days to check against
@@ -47,15 +69,24 @@
47 69 /**
48 70 * Check If the Page is Forum page
49 71 */
50 72 function forumax_is_forum_page() {
51 - if ( in_array( 'bbpress', get_body_class(), true ) ) {
52 - return true;
53 - }
54 - return false;
73 + return function_exists( 'is_bbpress' ) && is_bbpress();
55 74 }
56 75
57 76 /**
77 + * Whether the request is a bbPress user profile page.
78 + *
79 + * Mirrors the 'bbp-user-page' body class without rebuilding the whole
80 + * body class list (get_body_class() runs every theme/plugin filter).
81 + *
82 + * @return bool
83 + */
84 +function forumax_is_user_profile_page() {
85 + return function_exists( 'bbp_is_single_user' ) && bbp_is_single_user() && ! bbp_is_single_user_edit();
86 +}
87 +
88 +/**
58 89 * Add a stable body class for all Forumax/bbPress related pages.
59 90 *
60 91 * This helps themes (e.g. Hello Biz) and custom CSS target Forumax pages
61 92 * reliably, even when the page uses shortcodes/blocks instead of bbPress
@@ -611,9 +642,9 @@
611 642 }
612 643 add_filter( 'user_has_cap', 'forumax_grant_bbpress_caps_to_admins', 10, 3 );
613 644
614 645 /**
615 - * Mutual Deactivation of Forumax and bbp-core plugins
646 + * Mutual Deactivation of old and new plugin paths
616 647 */
617 648 add_action( 'activated_plugin', function( $plugin ) {
618 649 if ( ! function_exists( 'is_plugin_active' ) ) {
619 650 require_once ABSPATH . 'wp-admin/includes/plugin.php';
@@ -618,31 +649,33 @@
618 649 if ( ! function_exists( 'is_plugin_active' ) ) {
619 650 require_once ABSPATH . 'wp-admin/includes/plugin.php';
620 651 }
621 652
622 - // All Forumax plugins
623 - $forumax_plugins = [
624 - 'forumax/forumax.php',
625 - 'forumax-pro/forumax.php',
626 - ];
653 + $free_plugins_new = [ 'forumax/forumax.php' ];
654 + $free_plugins_old = [ 'bbp-core/bbp-core.php', 'bbp-core/forumax.php' ];
655 +
656 + $pro_plugins_new = [ 'forumax-pro/forumax.php' ];
657 + $pro_plugins_old = [ 'bbp-core-pro/bbp-core.php', 'forumax-premium/bbp-core.php', 'forumax-premium/forumax.php' ];
627 658
628 - // All bbp-core plugins
629 - $bbp_core_plugins = [
630 - 'bbp-core/bbp-core.php',
631 - 'bbp-core-pro/bbp-core.php',
632 - ];
659 + // If activating NEW free, deactivate OLD free
660 + if ( in_array( $plugin, $free_plugins_new, true ) ) {
661 + deactivate_plugins( $free_plugins_old );
662 + }
633 663
634 - // If activating Forumax (free or pro) → deactivate bbp-core (all versions)
635 - if ( in_array( $plugin, $forumax_plugins, true ) ) {
636 - deactivate_plugins( $bbp_core_plugins );
664 + // If activating OLD free, deactivate NEW free
665 + if ( in_array( $plugin, $free_plugins_old, true ) ) {
666 + deactivate_plugins( $free_plugins_new );
637 667 }
668 +
669 + // If activating NEW pro, deactivate OLD pro
670 + if ( in_array( $plugin, $pro_plugins_new, true ) ) {
671 + deactivate_plugins( $pro_plugins_old );
672 + }
638 673
639 -
640 - // If activating bbp-core (free or pro) → deactivate Forumax (all versions)
641 - if ( in_array( $plugin, $bbp_core_plugins, true ) ) {
642 - deactivate_plugins( $forumax_plugins );
674 + // If activating OLD pro, deactivate NEW pro
675 + if ( in_array( $plugin, $pro_plugins_old, true ) ) {
676 + deactivate_plugins( $pro_plugins_new );
643 677 }
644 -
645 678 } );
646 679
647 680 /**
648 681 * Register Forum Sidebar widget area
@@ -812,15 +845,15 @@
812 845 if ( false !== $count ) {
813 846 return (int) $count;
814 847 }
815 848
816 - $status = esc_sql( $status );
817 - $where = "WHERE post_type = 'topic' AND post_status = '{$status}'";
849 + $where = $wpdb->prepare( "WHERE post_type = 'topic' AND post_status = %s", $status );
818 850
819 851 if ( false !== $parent_id && is_numeric( $parent_id ) ) {
820 852 $where .= $wpdb->prepare( " AND post_parent = %d", $parent_id );
821 853 }
822 854
855 + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $where is prepared above.
823 856 $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" );
824 857
825 858 // Set transient cache for 1 hour
826 859 set_transient( $cache_key, (int) $count, HOUR_IN_SECONDS );
@@ -825,8 +858,46 @@
825 858 // Set transient cache for 1 hour
826 859 set_transient( $cache_key, (int) $count, HOUR_IN_SECONDS );
827 860
828 861 return (int) $count;
862 +}
863 +
864 +/**
865 + * Sticky topic IDs from every forum.
866 + *
867 + * Reads the _bbp_sticky_topics meta of all forums in one query instead of
868 + * calling bbp_get_stickies() once per forum.
869 + *
870 + * @param bool $published_only Only read stickies of published forums.
871 + * @return int[]
872 + */
873 +function forumax_get_all_forum_stickies( $published_only = false ) {
874 + global $wpdb;
875 +
876 + $sql = $wpdb->prepare(
877 + "SELECT pm.meta_value FROM {$wpdb->postmeta} pm
878 + INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id
879 + WHERE pm.meta_key = %s AND p.post_type = %s",
880 + '_bbp_sticky_topics',
881 + 'forum'
882 + );
883 +
884 + if ( $published_only ) {
885 + $sql .= " AND p.post_status = 'publish'";
886 + }
887 +
888 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- prepared above.
889 + $rows = $wpdb->get_col( $sql );
890 +
891 + $stickies = [];
892 + foreach ( $rows as $value ) {
893 + $value = maybe_unserialize( $value );
894 + if ( is_array( $value ) ) {
895 + $stickies = array_merge( $stickies, $value );
896 + }
897 + }
898 +
899 + return array_values( array_unique( array_filter( array_map( 'intval', $stickies ) ) ) );
829 900 }
830 901
831 902 /**
832 903 * Get unanswered topics count.