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
bbp-core / includes / Frontend / Frontend_Assets.php

Frontend_Assets.php in Forumax – AI Powered Advanced Community Forum Plugin 2.5.1, at includes/Frontend/Frontend_Assets.php

139 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Frontend;
3
4 /**
5 * Class Assets
6 * @package EazyDocs\Admin
7 */
8 class Frontend_Assets
9 {
10
11 /**
12 * Assets constructor.
13 */
14 public function __construct()
15 {
16 add_action('wp_enqueue_scripts', [$this, 'frontend_scripts'], 999);
17 }
18
19 /**
20 * Register scripts and styles [ FRONTEND ]
21 */
22 public function frontend_scripts()
23 {
24
25 if (!class_exists('bbPress') || !class_exists('Forumax')) {
26 return;
27 }
28
29 // Register front-end scripts/styles first so they are available for Gutenberg/Elementor blocks.
30 wp_register_script('bbpc-ajax', FORUMAX_FRONT_ASS . 'js/ajax.js', ['jquery'], FORUMAX_VERSION, true);
31 wp_register_script('bbpc-frontend', FORUMAX_FRONT_ASS . 'js/frontend.js', ['jquery'], FORUMAX_VERSION, true);
32
33 // Always localize 'forumax_localize_script' on 'jquery' (since it is loaded everywhere) if bbPress exists.
34 // This guarantees that any script requiring these variables won't fail with a ReferenceError.
35 // Forum-specific values are only resolved on bbPress pages; elsewhere they are empty.
36 $is_bbpress_page = function_exists('is_bbpress') && is_bbpress();
37
38 wp_localize_script('jquery', 'forumax_localize_script', [
39 'ajaxurl' => admin_url('admin-ajax.php'),
40 'nonce' => wp_create_nonce('forumax-nonce'),
41 'bbpc_subscribed_link' => $is_bbpress_page ? wp_kses_post(bbp_get_forum_subscription_link()) : '',
42 'bbpc_subscribed_forum_title' => $is_bbpress_page ? forumax_forum_title() : '',
43 'bbpc_subscribed_forum_id' => $is_bbpress_page ? bbp_get_forum_id() : 0,
44 'bbp_topic_id' => get_the_ID()
45 ]);
46
47 wp_register_style('bbpc-single', FORUMAX_STYLES . 'frontend/forum-single.css', [], FORUMAX_VERSION);
48 wp_register_style('bbpc-forum', FORUMAX_STYLES . 'frontend/forum.css', [], FORUMAX_VERSION);
49
50 if ( is_rtl() ) {
51 wp_enqueue_style( 'bbpc-main-rtl', FORUMAX_STYLES . 'frontend/main-rtl.css', [], FORUMAX_VERSION );
52 }
53
54 if (!$is_bbpress_page) {
55 return;
56 }
57
58 wp_enqueue_style('elegant-icon', FORUMAX_VEND . 'elegant-icon/style.css', [], FORUMAX_VERSION);
59 wp_register_script('bbpc-wp-widget', FORUMAX_ASSETS . 'frontend/js/wp-widgets.js', ['jquery'], FORUMAX_VERSION, true);
60
61 // Nice Select for frontend (prefixed to avoid conflicts)
62 wp_register_style('frmx-nice-select', FORUMAX_VEND . 'frmx-nice-select/nice-select.css', [], FORUMAX_VERSION);
63 wp_register_script('frmx-nice-select', FORUMAX_VEND . 'frmx-nice-select/jquery.nice-select.min.js', ['jquery'], '1.0', true);
64
65 $bbpc_brand_color = forumax_get_opt('bbpc_brand_color');
66 if ( ! empty( $bbpc_brand_color ) ) {
67 $dynamic_css = sprintf(
68 ':root { --bbpc_brand_color: %s; }',
69 sanitize_hex_color( $bbpc_brand_color )
70 );
71 wp_add_inline_style( 'bbpc-single', $dynamic_css );
72 }
73
74
75 wp_register_script('bbpc-voting', FORUMAX_FRONT_ASS . 'voting/bbpc-voting.js', ['jquery'], FORUMAX_VERSION, true);
76 wp_register_script('forumax-custom', FORUMAX_FRONT_ASS . 'js/custom.js', ['jquery'], FORUMAX_VERSION, true);
77 wp_register_script('bbp-replies-sorting', FORUMAX_FRONT_ASS . 'js/bbp-replies-sorting.js', ['jquery'], FORUMAX_VERSION, true);
78 wp_register_script('docy-forum', FORUMAX_FRONT_ASS . 'js/forum.js', ['jquery'], FORUMAX_VERSION, true);
79 wp_register_script('frmx-inline-edit', FORUMAX_FRONT_ASS . 'js/frmx-inline-edit.js', ['jquery'], FORUMAX_VERSION, true);
80
81 wp_enqueue_style('bbpc-single');
82 wp_enqueue_style('bbpc-forum');
83 wp_enqueue_style('bbpc-voting', FORUMAX_FRONT_ASS . 'voting/bbpc-voting.css', [], FORUMAX_VERSION);
84 wp_enqueue_style('frmx-nice-select');
85
86 wp_enqueue_script('frmx-nice-select');
87 wp_enqueue_script('forumax-custom');
88 wp_enqueue_script('bbp-replies-sorting');
89 wp_enqueue_script('docy-forum');
90 wp_enqueue_script('bbpc-voting');
91 wp_enqueue_script('bbpc-frontend');
92
93 // Ensure TinyMCE scripts are queued early on all forumax editor pages
94 if ( bbp_is_single_topic() || bbp_is_single_forum() || bbp_is_reply_edit() || bbp_is_topic_edit() ) {
95 wp_enqueue_editor();
96 }
97
98 // Inline edit — only on single topic pages.
99 if ( bbp_is_single_topic() ) {
100
101 wp_enqueue_script( 'frmx-inline-edit' );
102 wp_localize_script( 'frmx-inline-edit', 'frmxInlineEdit', [
103 'ajaxurl' => admin_url( 'admin-ajax.php' ),
104 'nonce' => wp_create_nonce( 'forumax-nonce' ),
105 'topic_id' => bbp_get_topic_id(),
106 'i18n' => [
107 'edit' => esc_html__( 'Edit', 'forumax' ),
108 'save' => esc_html__( 'Save', 'forumax' ),
109 'cancel' => esc_html__( 'Cancel', 'forumax' ),
110 'saving' => esc_html__( 'Saving…', 'forumax' ),
111 'loading' => esc_html__( 'Loading…', 'forumax' ),
112 'title_label' => esc_html__( 'Topic Title', 'forumax' ),
113 'content_label' => esc_html__( 'Topic Content', 'forumax' ),
114 'title_required' => esc_html__( 'Title cannot be empty.', 'forumax' ),
115 'content_required' => esc_html__( 'Content cannot be empty.', 'forumax' ),
116 'error' => esc_html__( 'Something went wrong. Please try again.', 'forumax' ),
117 'editing_reply' => esc_html__( 'Editing reply', 'forumax' ),
118 'to_save' => esc_html__( 'to save', 'forumax' ),
119 'to_cancel' => esc_html__( 'to cancel', 'forumax' ),
120 'unsaved_changes' => esc_html__( 'Unsaved changes', 'forumax' ),
121 'discard_confirm' => esc_html__( 'Discard unsaved changes?', 'forumax' ),
122 'discard' => esc_html__( 'Discard', 'forumax' ),
123 'keep_editing' => esc_html__( 'Keep editing', 'forumax' ),
124 ],
125 ] );
126 }
127
128
129 // User page styles
130 if ( function_exists( 'bbp_is_single_user' ) ) {
131 if ( bbp_is_single_user() || bbp_is_favorites() || bbp_is_subscriptions() || bbp_is_single_user_engagements() || bbp_is_single_user_topics() || bbp_is_single_user_replies() || bbp_is_single_user_edit() || bbp_is_single_user_profile() ) {
132 wp_enqueue_style('bbpc-forum-user', FORUMAX_STYLES . 'frontend/forum-user.css', [], FORUMAX_VERSION);
133 }
134 }
135
136 }
137 }
138
139