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