PluginProbe
bbp style pack / trunk
bbp style pack vtrunk
6.4.7 6.4.6 4.9.11 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 All 375 releases
bbp-style-pack / bbp-style-pack.php

bbp-style-pack.php in bbp style pack trunk, at bbp-style-pack.php

877 lines 41.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Plugin Name: bbp style pack
5 Plugin URI: http://www.rewweb.co.uk/bbp-style-pack/
6 Description: This plugin adds styling and features to bbPress.
7 Version: 6.4.7
8 Author: Robin Wilson
9 Text Domain: bbp-style-pack
10 Domain Path: /languages
11 Author URI: http://www.rewweb.co.uk
12 License: GPL2
13 */
14 /* Copyright 2016-2026 Robin Wilson (email : wilsonrobine@btinternet.com)
15
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License, version 2, as
18 published by the Free Software Foundation.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 https://www.gnu.org/licenses/gpl-2.0.html
26
27 */
28
29 //if you decativate and delete bsp plugin, then on reinstalling the default css files are not there, but bsp_version is, so we blank bsp_version to ensure they are recreated
30 register_activation_hook( __FILE__, 'bsp_plugin_activate' );
31
32 function bsp_plugin_activate($network_wide){
33 delete_option( 'bsp_version');
34 }
35
36 /*******************************************
37 * global variables
38 *******************************************/
39
40 // load the plugin options
41 $bsp_style_settings_f = get_option( 'bsp_style_settings_f' );
42 $bsp_templates = get_option( 'bsp_templates' );
43 $bsp_forum_display = get_option( 'bsp_forum_display' );
44 $bsp_forum_order = get_option( 'bsp_forum_order' );
45 $bsp_style_settings_freshness = get_option( 'bsp_style_settings_freshness' );
46 $bsp_breadcrumb = get_option( 'bsp_breadcrumb' );
47 $bsp_style_settings_buttons = get_option( 'bsp_style_settings_buttons' );
48 $bsp_login = get_option( 'bsp_login' );
49 $bsp_login_fail = get_option( 'bsp_login_fail' );
50 $bsp_roles = get_option( 'bsp_roles' );
51 $bsp_style_settings_email = get_option( 'bsp_style_settings_email' );
52 $bsp_style_settings_sub_management = get_option( 'bsp_style_settings_sub_management' );
53 $bsp_topic_order = get_option( 'bsp_topic_order' );
54 $bsp_style_settings_ti = get_option( 'bsp_style_settings_ti' );
55 $bsp_style_settings_topic_preview = get_option( 'bsp_style_settings_topic_preview' );
56 $bsp_style_settings_t = get_option( 'bsp_style_settings_t' );
57 $bsp_settings_topic_count = get_option ('bsp_settings_topic_count');
58 $bsp_style_settings_form = get_option( 'bsp_style_settings_form' );
59 $bsp_profile = get_option( 'bsp_profile' );
60 $bsp_style_settings_search = get_option( 'bsp_style_settings_search' );
61 $bsp_style_settings_unread = get_option( 'bsp_style_settings_unread' );
62 $bsp_style_settings_quote = get_option( 'bsp_style_settings_quote' );
63 $bsp_style_settings_modtools = get_option( 'bsp_style_settings_modtools' );
64 $bsp_style_settings_la = get_option( 'bsp_style_settings_la' );
65 $bsp_css_location = get_option( 'bsp_css_location' );
66 $bsp_style_settings_translation = get_option( 'bsp_style_settings_translation' );
67 $bsp_settings_admin = get_option ('bsp_settings_admin') ;
68 $bsp_style_settings_bugs = get_option( 'bsp_style_settings_bugs' );
69 $bsp_style_settings_block_widgets = get_option( 'bsp_style_settings_block_widgets' );
70 $bsp_css = get_option( 'bsp_css' );
71 $bsp_style_settings_theme_support = get_option( 'bsp_style_settings_theme_support' );
72 $bsp_buddypress_support = get_option( 'bsp_buddypress_support' );
73 $bsp_style_settings_column_display = get_option( 'bsp_style_settings_column_display' );
74 $bsp_style_settings_topic_fields = get_option( 'bsp_style_settings_topic_fields' );
75
76 if(!defined('BSP_PLUGIN_DIR'))
77 define('BSP_PLUGIN_DIR', dirname(__FILE__));
78
79 if(!defined('BSP_PLUGIN_URL'))
80 define('BSP_PLUGIN_URL', plugin_dir_url( __FILE__ ));
81
82
83 add_action('plugins_loaded', 'bbp_style_pack_init');
84
85
86
87 /*theme check needs to be run from setup theme action , as calling at time of plugins loaded produces translation error in 6.7
88 see also https://wordpress.org/support/topic/function-load-error/#post-18745586 on possibly running it later
89 so if you are running a child theme (which could be a block child theme!), then doing the bsp_theme_check at 'setup_theme' does not work, and it must be called
90 at the 'after_setup_theme' action point. The issue is that we don't know until after setup if it is a child theme, so the option to call
91 the right action is not there !!!
92 */
93
94 if (!empty ($bsp_style_settings_bugs['child_theme'])) {
95 add_action('after_setup_theme' , 'bsp_theme_check') ;
96 }
97 else {
98 add_action('setup_theme', 'bsp_theme_check');
99 }
100
101
102
103 //set bbpress version which is needed for function below and template order (around line 236)
104 $bsp_bbpress_full_version = get_option('bsp_bbpress_version', '2.6.12') ;
105 $bsp_bbpress_version = substr($bsp_bbpress_full_version, 0, 3) ;
106
107
108 //now we add the class-bbp-admin class as this throws a dynamic property error as php 8.2 or above does not allow dynamic properties - we need to do this before bbpress loads
109 // and the bbpress extend buddypress loader.php for the same reason if buddypress is active
110 //unless we are in buddyboss which has it's own admin. is_plugin_active checks whether it is in wp_options active_plugins list, so tells us if buddyboss loader plugin is active - this doesn't guarantee that buddyboss is active, but unlikely not to be !
111 // OR we are not on bbpress 2.6.9 or later
112 //function loaded so we can use is_plugin_active
113 if( ! function_exists('get_plugin_data') ){
114 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
115 //$path = str_replace ('wp-content' , 'wp-admin' ,WP_CONTENT_DIR ) ;
116 //require_once( $path . '/includes/plugin.php' );
117 }
118 if (!is_plugin_active ('buddyboss-platform/bp-loader.php') && ($bsp_bbpress_full_version == '2.6.9' || $bsp_bbpress_full_version == '2.6.10' || $bsp_bbpress_full_version == '2.6.11' || $bsp_bbpress_full_version == '2.6.12')) {
119 include(BSP_PLUGIN_DIR . '/bbpress-admin/class-bbp-admin.php');
120 }
121
122
123 function bbp_style_pack_init() {
124 unload_textdomain( 'bbpress' );
125 load_plugin_textdomain('bbp-style-pack', false, basename( dirname( __FILE__ ) ) . '/languages' );
126 load_plugin_textdomain('bbpress', false, 'bbpress/languages' );
127 //save the bbpress version
128 if( class_exists( 'bbpress' ) ) update_option ('bsp_bbpress_version' , bbp_get_version()) ;
129 //load the plugin stuff
130 bsp_load_plugin() ;
131 }
132
133
134
135 // TEMPLATES - done now as needed when bbpress loads
136 //register the new templates location
137 if (!empty ($bsp_templates['template'] ) && ($bsp_templates['template'] == 1)) {
138 add_action( 'bbp_register_theme_packages', 'bsp_register_plugin_template1' );
139 $alt_template = 1 ;
140 }
141
142 //add in loop-forums if we need to and not done by above alternate template
143 if (!empty ($bsp_style_settings_f['forum_icons']) && empty ($alt_template) ) {
144 add_action( 'bbp_register_theme_packages', 'bsp_register_loop_forums' );
145 }
146
147 //add in the forum search if set
148 if (!empty ($bsp_style_settings_search['SearchingActivate'] )) {
149 add_action( 'bbp_register_theme_packages', 'bsp_register_plugin_search_template' );
150 }
151
152 //add in the topic/reply_form if we need to
153 if (!empty ($bsp_style_settings_form['Remove_Edit_LogsActivate'] ) || !empty ($bsp_style_settings_form['Remove_Edit_ReasonActivate'] ) || !empty ($bsp_style_settings_form ['htmlActivate']) || !empty ($bsp_style_settings_form ['nologinActivate']) || !empty ($bsp_style_settings_form['topic_tag_list'])) {
154 add_action( 'bbp_register_theme_packages', 'bsp_register_plugin_form_topicandreply_template' );
155 }
156
157 //add in loop-topics if we need to
158 if (!empty ($bsp_style_settings_ti['topic_icons']) ) {
159 add_action( 'bbp_register_theme_packages', 'bsp_register_loop_topics' );
160 }
161
162 //add in the mod tools pending shortcode if modtools activated
163 if( !class_exists( 'bbPressModToolsPlugin') && !empty($bsp_style_settings_modtools['modtools_activate']) ) {
164 add_action( 'bbp_register_theme_packages', 'bsp_register_modtools_template' );
165 }
166
167 //add in the feedback no topics if this is to be blank or have a different message
168 if (!empty ($bsp_style_settings_ti['empty_forumActivate']) || !empty ($bsp_style_settings_ti['empty_forum'] ) ) {
169 add_action( 'bbp_register_theme_packages', 'bsp_register_feedback_no_topics_template' );
170 }
171
172 //add in the loop-single-topic if needed
173 if (!empty ($bsp_style_settings_ti['topic_title_link'])) {
174 add_action( 'bbp_register_theme_packages', 'bsp_register_plugin_topic_title' );
175 }
176
177 //add in the form-anonymous if needed - if any of the three form anon fields are completed
178 if (!empty ($bsp_style_settings_form['no_anon_nameActivate']) || !empty ($bsp_style_settings_form['no_anon_emailActivate']) || !empty ($bsp_style_settings_form['no_anon_websiteActivate'])) {
179 add_action( 'bbp_register_theme_packages', 'bsp_register_plugin_form_anonymous' );
180 }
181
182 //get the template paths
183 function bsp_get_template1_path() {
184 return BSP_PLUGIN_DIR . '/templates/templates1';
185 }
186
187 function bsp_get_search_template_path() {
188 return BSP_PLUGIN_DIR . '/templates/searchform';
189 }
190
191 function bsp_get_form_topicandreply_template_path5() {
192 return BSP_PLUGIN_DIR . '/templates/topicandreplyform5';
193 }
194
195 function bsp_get_form_topicandreply_template_path6() {
196 return BSP_PLUGIN_DIR . '/templates/topicandreplyform6';
197 }
198
199 function bsp_get_feedback_no_topics_templatepath() {
200 return BSP_PLUGIN_DIR . '/templates/feedback';
201 }
202
203
204 function bsp_get_modtools_template_path() {
205 return BSP_PLUGIN_DIR . '/templates/modtools';
206 }
207
208 function bsp_get_topic_title_template_path() {
209 return BSP_PLUGIN_DIR . '/templates/topictitle';
210 }
211
212 function bsp_get_loop_topics_template_path() {
213 return BSP_PLUGIN_DIR . '/templates/loop_topics';
214 }
215
216 function bsp_get_loop_forums_template_path() {
217 return BSP_PLUGIN_DIR . '/templates/loop_forums';
218 }
219
220 function bsp_get_form_anonymous_template_path() {
221 return BSP_PLUGIN_DIR . '/templates/form_anonymous';
222 }
223
224 //register the templates
225
226 // TEMPLATES - fix
227
228 /*Template Loading
229
230 The method is different (I think) between 2.5.12 and 2.6, it certainly seems to affect the load order, so we find out which version we are on, and allocate dependant on that.
231 We also allow an override, so admins can try different numbers
232 */
233
234
235 /* This is the bit that determines the order they load
236 in 2.5 we have
237 bbp_register_template_stack( 'get_template_directory', 12 );
238 bbp_register_template_stack( 'bbp_get_theme_compat_dir', 14 );
239
240 so we load at 12 to get the templates to work, so not sure which loads first - theme or bsp - one to test when I get a moment
241
242 in 2.6 we have
243 bbp_register_template_stack( 'get_template_directory', 8 );
244 bbp_register_template_stack( array( $bbp->theme_compat->theme, 'get_dir' ) );
245
246 which is different, and seems to cause issues if left at 12 as other templates have loaded before, so we alter to 6 as default
247 it actualy looks like something is using a default of 10, as setting to that works, but not 11.
248 */
249
250 //$bbpress version is set at the beginning on this file.
251
252 if ($bsp_bbpress_version == '2.5') $priority = 12;
253 elseif ($bsp_bbpress_version == '2.6') $priority = 6 ;
254 //allow for case where neither is set and assume version 2.6.x
255 else $priority = 6 ;
256
257 //then allow custom setting
258 if (!empty($bsp_templates['template_priority']) && is_numeric ($bsp_templates['template_priority']) ) $priority = $bsp_templates['template_priority'] ;
259
260 function bsp_register_plugin_template1() {
261 global $priority ;
262 bbp_register_template_stack( 'bsp_get_template1_path', $priority);
263 }
264
265 function bsp_register_plugin_search_template() {
266 global $priority ;
267 bbp_register_template_stack( 'bsp_get_search_template_path', $priority );
268 }
269
270 function bsp_register_modtools_template() {
271 global $priority ;
272 bbp_register_template_stack( 'bsp_get_modtools_template_path', $priority );
273 }
274
275 function bsp_register_plugin_form_topicandreply_template() {
276 global $priority ;
277 //if version 2.5...
278 if ($priority == 12) {
279 bbp_register_template_stack( 'bsp_get_form_topicandreply_template_path5', $priority);
280 }
281 //if version 2.6...
282 else {
283 bbp_register_template_stack( 'bsp_get_form_topicandreply_template_path6', $priority);
284 }
285 }
286
287 function bsp_register_loop_topics() {
288 global $priority ;
289 bbp_register_template_stack( 'bsp_get_loop_topics_template_path', $priority );
290 }
291
292 function bsp_register_loop_forums() {
293 global $priority ;
294 bbp_register_template_stack( 'bsp_get_loop_forums_template_path', $priority );
295 }
296
297 function bsp_register_feedback_no_topics_template() {
298 global $priority ;
299 bbp_register_template_stack( 'bsp_get_feedback_no_topics_templatepath', $priority);
300 }
301
302 function bsp_register_plugin_topic_title() {
303 global $priority ;
304 bbp_register_template_stack( 'bsp_get_topic_title_template_path', $priority);
305 }
306
307 function bsp_register_plugin_form_anonymous() {
308 global $priority ;
309 bbp_register_template_stack( 'bsp_get_form_anonymous_template_path', $priority);
310 }
311
312
313 //add our version of wp_authenticate (pluggable wordpress function) if failed login tab activated - done now to ensure it loads
314 if( ! function_exists('wp_authenticate') && !empty($bsp_login_fail['activate_failed_login']) ) {
315 function wp_authenticate( $username, $password ) {
316 $username = sanitize_user( $username );
317 $password = trim( $password );
318
319 /**
320 * Filters whether a set of user login credentials are valid.
321 *
322 * A WP_User object is returned if the credentials authenticate a user.
323 * WP_Error or null otherwise.
324 *
325 * @since 2.8.0
326 * @since 4.5.0 `$username` now accepts an email address.
327 *
328 * @param null|WP_User|WP_Error $user WP_User if the user is authenticated.
329 * WP_Error or null otherwise.
330 * @param string $username Username or email address.
331 * @param string $password User password
332 */
333 $user = apply_filters( 'authenticate', null, $username, $password );
334
335 if ( null == $user ) {
336 // TODO: What should the error message be? (Or would these even happen?)
337 // Only needed if all authentication handlers fail to return anything.
338 $user = new WP_Error( 'authentication_failed', __( 'Error: Invalid username, email address or incorrect password.', 'bbp-style-pack' ) );
339 }
340 //***function amended to take out this line and add blank array to ensure we pass back to bbpress on any error
341 //$ignore_codes = array( 'empty_username', 'empty_password' );
342 $ignore_codes = array () ;
343 if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes ) ) {
344 $error = $user;
345
346 /**
347 * Fires after a user login has failed.
348 *
349 * @since 2.5.0
350 * @since 4.5.0 The value of `$username` can now be an email address.
351 * @since 5.4.0 The `$error` parameter was added.
352 *
353 * @param string $username Username or email address.
354 * @param WP_Error $error A WP_Error object with the authentication failure details.
355 */
356 do_action( 'wp_login_failed', $username, $error );
357 }
358
359 return $user;
360 }
361 }
362
363
364
365 /*******************************************
366 * file includes
367 *******************************************/
368
369 //only fires after all plugins loaded to ensure bbpress is loaded before we add bbpress functions and filters
370 function bsp_load_plugin() {
371
372 if( class_exists( 'bbpress' ) ) {
373
374 //add the blocks - note the register looks for a .asset file in the build folder with a prefix that matches both the .js and the .css file, so the css file enqueue below must match
375
376 include_once( 'generator/generator.php' );
377 add_action( 'init', 'bsp_register_blocks' );
378
379 add_action( 'wp_enqueue_scripts', 'bsp_enqueue_block_css' ) ;
380
381 add_action( 'init', 'bsp_register_block_pattern_categories', 9 );
382
383
384 //and add the patterns
385
386 include(BSP_PLUGIN_DIR . '/blocks/patterns.php');
387
388 add_action( 'init', 'bsp_register_forum_patterns' );
389
390
391
392 /*******************************************
393 * front-end and admin files
394 *******************************************/
395
396 global $bsp_style_settings_sub_management ;
397 if (!function_exists( 'forums_toolkit_page') && !empty($bsp_style_settings_sub_management['subscriptions_management_activate']))
398 include(BSP_PLUGIN_DIR . '/includes/subscriptions_management.php');
399
400 global $bsp_style_settings_unread ;
401 //only load functions_unread if activated
402 if (!empty($bsp_style_settings_unread['unread_activate'])) {
403 include(BSP_PLUGIN_DIR . '/includes/functions_unread.php') ;
404 include(BSP_PLUGIN_DIR . '/includes/unread_posts_page.php');
405 }
406
407 //only load functions_quote if activated
408 global $bsp_style_settings_quote ;
409 if (!empty($bsp_style_settings_quote['quote_activate']))
410 include(BSP_PLUGIN_DIR . '/includes/functions_quote.php');
411
412 //only load functions_topic_fields if activated
413 global $bsp_style_settings_topic_fields ;
414 if (!empty($bsp_style_settings_topic_fields['number_of_fields']))
415 include(BSP_PLUGIN_DIR . '/includes/functions_topic_fields.php');
416
417 //load moderation tools if activated
418 //don't load if mod tools plugin already loaded
419 global $bsp_style_settings_modtools ;
420 if( !class_exists( 'bbPressModToolsPlugin') && !empty($bsp_style_settings_modtools['modtools_activate']) ) {
421 //load moderation tools
422 require_once( BSP_PLUGIN_DIR. '/modtools/bbpress-modtools.php' );
423 require_once( BSP_PLUGIN_DIR . '/modtools/settings.php' );
424 require_once( BSP_PLUGIN_DIR . '/modtools/admin.php' );
425 require_once( BSP_PLUGIN_DIR . '/modtools/bbpress.php' );
426 require_once( BSP_PLUGIN_DIR . '/modtools/moderation.php' );
427 require_once( BSP_PLUGIN_DIR . '/modtools/report.php' );
428 require_once( BSP_PLUGIN_DIR . '/modtools/users.php' );
429 require_once( BSP_PLUGIN_DIR . '/modtools/scripts.php' );
430 require_once( BSP_PLUGIN_DIR . '/modtools/notifications.php' );
431 //add shortcode function
432 include(BSP_PLUGIN_DIR . '/includes/functions_modtools.php');
433 }
434
435 include(BSP_PLUGIN_DIR . '/includes/functions.php');
436 include(BSP_PLUGIN_DIR . '/includes/functions_email.php');
437 include(BSP_PLUGIN_DIR . '/includes/forum_image_metabox.php');
438 include(BSP_PLUGIN_DIR . '/includes/generate_css.php');
439 include(BSP_PLUGIN_DIR . '/includes/widgets.php');
440 include(BSP_PLUGIN_DIR . '/includes/functions_bugs.php');
441
442
443 //bp-loader if buddypress active and set
444 global $bsp_style_settings_bugs ;
445
446 if (!empty($bsp_style_settings_bugs['bbpress_domain_early_buddypress'])) {
447 include(BSP_PLUGIN_DIR . '/includes/functions_buddypress_support.php');
448 add_action ('bp_include' , 'bsp_amend_buddypress_loader', 1) ;
449 }
450
451 // admin-only files
452 if ( is_admin() ) {
453 include(BSP_PLUGIN_DIR . '/includes/defined_option_groups.php');
454 include(BSP_PLUGIN_DIR . '/includes/defined_tabs.php');
455 include(BSP_PLUGIN_DIR . '/includes/settings.php');
456 include(BSP_PLUGIN_DIR . '/includes/settings_forums_index.php');
457 include(BSP_PLUGIN_DIR . '/includes/settings_topics_index.php');
458 include(BSP_PLUGIN_DIR . '/includes/settings_topic_reply_display.php');
459 include(BSP_PLUGIN_DIR . '/includes/settings_forum_display.php');
460 include(BSP_PLUGIN_DIR . '/includes/settings_forum_roles.php');
461 include(BSP_PLUGIN_DIR . '/includes/settings_custom_css.php');
462 include(BSP_PLUGIN_DIR . '/includes/settings_topic_order.php');
463 include(BSP_PLUGIN_DIR . '/includes/settings_forum_order.php');
464 include(BSP_PLUGIN_DIR . '/includes/settings_freshness_display.php');
465 include(BSP_PLUGIN_DIR . '/includes/settings_topic_reply_form.php');
466 include(BSP_PLUGIN_DIR . '/includes/settings_css_location.php');
467 include(BSP_PLUGIN_DIR . '/includes/settings_login.php');
468 include(BSP_PLUGIN_DIR . '/includes/settings_login_fail.php');
469 include(BSP_PLUGIN_DIR . '/includes/settings_search.php');
470 include(BSP_PLUGIN_DIR . '/includes/settings_forum_templates.php');
471 include(BSP_PLUGIN_DIR . '/includes/settings_breadcrumbs.php');
472 include(BSP_PLUGIN_DIR . '/includes/settings_buttons.php');
473 include(BSP_PLUGIN_DIR . '/includes/settings_profile.php');
474 include(BSP_PLUGIN_DIR . '/includes/settings_shortcodes.php');
475 include(BSP_PLUGIN_DIR . '/includes/settings_latest_activity_widget_styling.php');
476 include(BSP_PLUGIN_DIR . '/includes/settings_widgets.php');
477 include(BSP_PLUGIN_DIR . '/includes/settings_reset.php');
478 include(BSP_PLUGIN_DIR . '/includes/not_working.php');
479 include(BSP_PLUGIN_DIR . '/includes/settings_unread.php');
480 include(BSP_PLUGIN_DIR . '/includes/settings_export.php');
481 include(BSP_PLUGIN_DIR . '/includes/settings_import.php');
482 include(BSP_PLUGIN_DIR . '/includes/settings_email.php');
483 include(BSP_PLUGIN_DIR . '/includes/settings_quote.php');
484 include(BSP_PLUGIN_DIR . '/includes/settings_moderation.php');
485 include(BSP_PLUGIN_DIR . '/includes/settings_theme_support.php');
486 include(BSP_PLUGIN_DIR . '/includes/settings_buddypress_support.php');
487 include(BSP_PLUGIN_DIR . '/includes/settings_translation.php');
488 include(BSP_PLUGIN_DIR . '/includes/settings_bugs.php');
489 include(BSP_PLUGIN_DIR . '/includes/settings_subscriptions_management.php');
490 include(BSP_PLUGIN_DIR . '/includes/settings_topic_count.php');
491 include(BSP_PLUGIN_DIR . '/includes/settings_admin.php');
492 include(BSP_PLUGIN_DIR . '/includes/settings_topic_preview.php');
493 include(BSP_PLUGIN_DIR . '/includes/help.php');
494 include(BSP_PLUGIN_DIR . '/includes/plugins.php');
495 include(BSP_PLUGIN_DIR . '/includes/plugin_info.php');
496 include(BSP_PLUGIN_DIR . '/includes/whats_new.php');
497 include(BSP_PLUGIN_DIR . '/includes/logo.php');
498 include(BSP_PLUGIN_DIR . '/includes/functions_admin.php');
499 include(BSP_PLUGIN_DIR . '/includes/settings_block_widgets.php');
500 include(BSP_PLUGIN_DIR . '/includes/settings_column_display.php');
501 include(BSP_PLUGIN_DIR . '/includes/settings_topic_fields.php');
502 }
503
504 // frontend-only files
505 if ( ! is_admin() ) {
506 include(BSP_PLUGIN_DIR . '/includes/buddypress.php');
507 include(BSP_PLUGIN_DIR . '/includes/functions_topic_count.php');
508 include(BSP_PLUGIN_DIR . '/includes/shortcodes.php');
509
510 }
511
512
513 /*
514 * Handle upgrade actions
515 */
516 if ( ! function_exists( 'get_plugin_data' ) ) {
517 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
518 }
519
520 $new_version = get_plugin_data( __FILE__, false, false )['Version'];
521
522 if ( ! defined( 'BSP_VERSION_KEY' ) )
523 define( 'BSP_VERSION_KEY', 'bsp_version' );
524
525 if ( ! defined( 'BSP_VERSION_NUM' ) )
526 define( 'BSP_VERSION_NUM', $new_version );
527
528 $curr_version = get_option( BSP_VERSION_KEY, false );
529
530 if ($new_version != $curr_version ) {
531
532 // first set whether network activated or not
533 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
534 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
535 }
536
537 $bsp_name = plugin_basename( __FILE__ );
538
539 $network_wide = ( is_multisite() && is_plugin_active_for_network( $bsp_name ) ) ? true : false;
540
541 // do the activation actions
542 bsp_plugin_update( $network_wide );
543 }
544
545 } // end of if bbpress class exists - main plugin loading
546
547
548 /*
549 * Add plugin page links whether bbPress is active or not
550 */
551 // plugin title action links
552 add_filter( 'plugin_action_links', 'bsp_modify_plugin_action_links', 10, 2 );
553
554 // plugin description links
555 add_filter( 'plugin_row_meta', 'bsp_modify_plugin_description_links', 10, 2 );
556
557 } //end of bsp_load_plugin
558
559
560 /*
561 * Handle update actions
562 */
563 function bsp_plugin_update( $network_wide ) {
564
565 if ( ! function_exists( 'get_plugin_data' ) ) {
566 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
567 }
568
569 if ( is_multisite() ) {
570 /* multisite install */
571
572 $site_ids = get_sites( array( 'fields' => 'ids' ) );
573
574 $bsp_name = plugin_basename( __FILE__ );
575
576 foreach( $site_ids as $site_id ) {
577 switch_to_blog( $site_id );
578 // network-activated, or active for current site?
579 if ( $network_wide || in_array( $bsp_name, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
580 bsp_plugin_update_actions();
581 }
582 restore_current_blog();
583 }
584
585 } else {
586 /* single site install */
587 bsp_plugin_update_actions();
588 } // end plugin update
589
590 }
591
592
593 // repeat actions on plugin activation/upgrade that apply to single site and per-site within a multisite sintall
594 function bsp_plugin_update_actions() {
595 $new_version = get_plugin_data( __FILE__, false, false )['Version'];
596
597 if ( ! defined( 'BSP_VERSION_KEY' ) )
598 define( 'BSP_VERSION_KEY', 'bsp_version' );
599
600 if ( ! defined( 'BSP_VERSION_NUM' ) )
601 define( 'BSP_VERSION_NUM', $new_version );
602
603 //and update version whether new installation or update
604 update_option( BSP_VERSION_KEY, BSP_VERSION_NUM );
605
606 // do any necessary field/value conversions
607 bsp_convert_values();
608
609 /*
610 * Regenerate CSS/JS files
611 * Pro-actively regenerate files to replace CSS/JS files removed during the upgrade process
612 */
613 require_once( plugin_dir_path( __FILE__ ) . 'includes/generate_css.php' );
614 copy_to_custom_dirs();
615 generate_style_css();
616 generate_quote_style_css();
617 generate_delete_js();
618 bsp_clear_cache();
619 }
620
621
622 /*
623 * Convert Values
624 * Some setting values have changed with the upcoming BETA release
625 * This function handles auto-conversions between releases
626 * Also includes backward compatibility conversions for when option groups were tied to specific tabs
627 */
628 function bsp_convert_values( $option_group = false, $field_setting = false ) {
629
630 /*
631 * FIRST
632 * Backward Compatibility with previous fields/values tied to specific tabs
633 */
634
635
636 //amend for searching activate being moved from forum index styling to search styling tab
637 // bsp ?.?.?
638 $options_f= get_option( 'bsp_style_settings_f', array() );
639 if ( is_array( $options_f ) ) {
640 if ( ! empty( $options_f["SearchingActivate"] ) ) {
641 //update bsp_style_settings_search
642 $options = get_option( 'bsp_style_settings_search', array() );
643 $options['SearchingActivate'] = '1';
644 $options['SearchingSearching'] = $options_f["SearchingSearching"];
645 $options['SearchingSpinner'] = $options_f["SearchingSpinner"];
646 //Update entire array
647 update_option( 'bsp_style_settings_search', $options );
648 //update bsp_style_settings_f
649 unset ( $options_f['SearchingActivate'] );
650 unset ( $options_f['SearchingSearching'] );
651 unset ( $options_f['SearchingSpinner'] );
652 //Update entire array
653 update_option( 'bsp_style_settings_f', $options_f );
654 }
655 }
656
657
658 //update for bsp_login menus
659 // bsp 4.4.8+
660 $bsp_login = get_option( 'bsp_login', array() );
661 if ( is_array( $bsp_login ) ) {
662 if ( empty( $bsp_login['update448'] ) ) {
663
664 $options = get_option( 'bsp_login' );
665 $options['update448'] = '1' ;
666 $menu_locations = get_nav_menu_locations();
667 $menus = get_terms( 'nav_menu' );
668 $field_prefixes = array( 'register', 'login', 'profile' );
669
670 //run the update once per field
671 foreach ( $field_prefixes as $field_prefix ) {
672 if ( ! empty( $bsp_login[ ( $field_prefix === 'login' ? 'add_login' : ( $field_prefix === 'profile' ? 'edit_profile' : $field_prefix ) ) ] ) && ! empty( $menus ) ) {
673 foreach( $menus as $menu ){
674 if( ! empty( $bsp_login[ ( $field_prefix == 'login' ? 'only_primary' : $field_prefix . '_only_primary' ) ] ) ) {
675 if ( ! empty( $menu_locations ) && isset( $menu_locations['primary'] ) ) {
676 if ( $menu_locations['primary'] == $menu->term_id ) {
677 $name = $field_prefix . '_' . $menu->name;
678 $options[$name] = '1';
679 unset( $options[ ( $field_prefix == 'login' ? 'only_primary' : $field_prefix . '_only_primary' ) ] );
680 }
681 }
682 }
683 else {
684 $name = $field_prefix . '_' . $menu->name ;
685 $options[$name] = '1' ;
686 }
687 }
688 }
689 }
690 update_option('bsp_login', $options);
691 }
692 }
693
694
695 //amend settings topic/reply form to allow for different topic/reply text
696 // bsp 4.1.8+
697 $options = get_option( 'bsp_style_settings_form', array() );
698 if ( is_array( $options ) ) {
699 if ( empty( $options['update418'] ) ) {
700 if ( ! empty( $options['topic_rules_text'] ) && ! empty( $options['topic_posting_rulesactivate_for_replies'] ) ) {
701 if ( empty( $options['reply_rules_text'] ) ) $options['reply_rules_text'] = $options['topic_rules_text'];
702 //and set it to stop running again
703 $options['update418'] = '1' ;
704 update_option('bsp_style_settings_form', $options);
705 }
706 }
707 }
708
709
710 // amend for topic subscribe button separator field being moved from Forum Butons tab (bsp_style_settings_buttons) to Topic/Reply Display (bsp_style_settings_t)
711 // bsp 5.6.0+
712 $options = get_option( 'bsp_style_settings_buttons', array() );
713 $new_options = get_option( 'bsp_style_settings_t', array() );
714 if ( is_array( $options ) ) {
715 // activated
716 if ( array_key_exists( 'activate_topic_subscribe_button_prefix', $options ) ) {
717 if ( ! empty( $options['activate_topic_subscribe_button_prefix'] ) ) {
718 // add the value to the new tab/option group and save
719 $new_options['activate_topic_subscribe_button_prefix'] = $options['activate_topic_subscribe_button_prefix'];
720 update_option( 'bsp_style_settings_t', $new_options );
721 //remove the value from the old tab/option group and save
722 unset ( $options['activate_topic_subscribe_button_prefix'] );
723 update_option( 'bsp_style_settings_buttons', $options );
724 }
725 }
726 // actual prefix
727 if ( array_key_exists( 'topic_subscribe_button_prefix', $options ) ) {
728 if ( ! empty( $options['topic_subscribe_button_prefix'] ) ) {
729 // add the value to the new tab/option group and save
730 $new_options['topic_subscribe_button_prefix'] = $options['topic_subscribe_button_prefix'];
731 update_option( 'bsp_style_settings_t', $new_options );
732 //remove the value from the old tab/option group and save
733 unset ( $options['topic_subscribe_button_prefix'] );
734 update_option( 'bsp_style_settings_buttons', $options );
735 }
736 }
737 }
738
739
740 /*
741 * SECOND
742 * Convert any old values where the field type and/or value type has changed
743 * Coming in a future release
744 */
745 }
746
747
748 // plugin title action links
749 function bsp_modify_plugin_action_links( $links, $file ) {
750
751 // Return normal links if not bbPress style
752 // revised to make sure links added to the Style Pack plugin regardless of directory
753 if ( strpos( $file, 'bbp-style-pack.php' ) !== false ) {
754
755 // New links to merge into existing links
756 $new_links = array();
757
758 // Settings page and what's new page
759 if ( current_user_can( 'manage_options' ) ) {
760 $new_links['settings'] = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbp-style-pack' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'Settings', 'bbp-style-pack' ) . '</a>';
761 $new_links['about'] = '<a href="' . esc_url( add_query_arg( array( 'page' => 'bbp-style-pack', 'tab' => 'new' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html__( 'What\'s New?', 'bbp-style-pack' ) . '</a>';
762 }
763
764 // Add a few links to the existing links array
765 $links = array_merge( $links, $new_links );
766
767 }
768 return $links;
769 }
770
771
772 // plugin description links
773 function bsp_modify_plugin_description_links( $links, $file ) {
774
775 $slug = 'bbp-style-pack.php';
776
777 // Return normal links if not bbPress style
778 // revised to make sure links added to the Style Pack plugin regardless of directory
779 if ( strpos( $file, $slug ) !== false ) {
780
781 // New links to merge into existing links
782 $new_links = array();
783
784 // Support link
785 // if inactive, or user can't admin, show WP support forum link
786 $new_links['support'] = '<a href="' . esc_url( 'https://wordpress.org/support/plugin/bbp-style-pack/' ) . '" target="_blank">' . esc_html__( 'Official Support', 'bbp-style-pack' ) . '</a>';
787
788 // Donate Link
789 $new_links['donate'] = '<a href="' . esc_url( 'http://www.rewweb.co.uk/donate' ) . '" target="_blank">' . esc_html__( 'Donate', 'bbp-style-pack' ) . '</a>';
790
791 // Rate/Review Link
792 $new_links['rate'] = '<a href="' . esc_url( 'https://wordpress.org/support/plugin/bbp-style-pack/reviews/#new-post' ) . '" target="_blank">' . esc_html__( 'Rate Us', 'bbp-style-pack' ) . ' <span style="font-size:14px;color:gold;">&starf;&starf;&starf;&starf;&starf;</span></a>';
793
794 // Add a few links to the existing links array
795 $links = array_merge( $links, $new_links );
796
797 }
798 return $links;
799
800 }
801
802
803 // register blocks
804 function bsp_register_blocks () {
805 register_block_type( BSP_PLUGIN_DIR . '/blocks/bsp-latest-activity-widget-block.json' );
806 register_block_type( BSP_PLUGIN_DIR . '/blocks/login-widget-block.json' );
807 register_block_type( BSP_PLUGIN_DIR . '/blocks/bsp-single-topic-information-block.json' );
808 register_block_type( BSP_PLUGIN_DIR . '/blocks/bsp-single-forum-information-block.json' );
809 register_block_type( BSP_PLUGIN_DIR . '/blocks/bsp-forums-list-widget-block.json' );
810 register_block_type( BSP_PLUGIN_DIR . '/blocks/topic-views-list-widget-block.json' );
811 register_block_type( BSP_PLUGIN_DIR . '/blocks/bsp-statistics-widget-block.json' );
812 register_block_type( BSP_PLUGIN_DIR . '/blocks/bsp-search-widget-block.json' );
813 }
814
815
816 //add pattern categories
817 function bsp_register_block_pattern_categories() {
818
819 $block_pattern_categories = array(
820 'bsp-forums' => array( 'label' => __( 'bbp style pack forum patterns', 'bbp-style-pack' ) ),
821 );
822
823
824 /**
825 * Filters the theme block pattern categories.
826 */
827 $block_pattern_categories = apply_filters( 'bbp-style-pack_pattern_categories', $block_pattern_categories );
828
829 foreach ( $block_pattern_categories as $name => $properties ) {
830 if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
831 register_block_pattern_category( $name, $properties );
832 }
833 }
834 }
835
836
837 function bsp_theme_check() {
838
839 /*******************************************
840 * Theme Checks
841 *******************************************/
842 global $bsp_theme_check ;
843
844 // CHECK IF BLOCK THEME
845 // get current theme dir
846 $theme_dir = get_template_directory();
847 //Detect if FSE (what WordPress calls block themes) theme or traditional - FSE Block themes require a theme.json file.
848 if ( file_exists( $theme_dir . '/templates/index.html') ) {
849 $bsp_theme_check = 'block_theme' ;
850 }
851 else {
852 //check for specific themes
853 $theme= wp_get_theme() ;
854 $theme_name = $theme->get( 'Name' ) ;
855 $parent = wp_get_theme()->parent();
856
857 if ($theme_name == 'Astra' || $parent == 'Astra') {
858 // if (!empty ($theme_name->get('Version'))) $version = $theme_name->get('Version');
859 $version = '' ;
860 //older version don't have this issue, and fixed in later, so only...
861 if ($version == '4.0.2' || $version == '4.1.0' || $version == '4.1.1' || $version == '4.1.2' || $version == '4.1.3' || $version == '4.1.4' || $version == '4.1.5' || $version == '4.1.6' ) {
862 $bsp_theme_check = 'astra' ;
863 }
864 }
865
866
867 if ($theme_name == 'Divi' || $parent == 'Divi' ) $bsp_theme_check = 'divi' ;
868 if ($theme_name == 'Kadence' || $parent == 'Kadence' ) $bsp_theme_check = 'kadence' ;
869 if ($theme_name == 'Hello Elementor' || $parent == 'Hello Elementor') $bsp_theme_check = 'hello-elementor' ;
870 }
871
872 if (!empty ($bsp_theme_check))
873 include(BSP_PLUGIN_DIR . '/includes/functions_theme_support.php');
874
875 }
876
877