| 1 |
<?php |
| 2 |
/** |
| 3 |
* Smart bbPress nVerify Compatibility Layer |
| 4 |
* |
| 5 |
* Fixes compatibility issues between Forumax and Smart bbPress nVerify plugin. |
| 6 |
* The issue: sbv_render_account_link() function doesn't check for WP_Error |
| 7 |
* before calling methods on the API response, causing fatal errors. |
| 8 |
* |
| 9 |
* Solution: Remove the problematic action when API is not configured. |
| 10 |
* |
| 11 |
* @package Forumax |
| 12 |
* @since 2.1.0 |
| 13 |
*/ |
| 14 |
|
| 15 |
defined('ABSPATH') || exit; |
| 16 |
|
| 17 |
/** |
| 18 |
* Fix Smart bbPress nVerify compatibility with Forumax |
| 19 |
* Runs on plugins_loaded with high priority to catch issues early |
| 20 |
*/ |
| 21 |
add_action('plugins_loaded', 'forumax_init_sbv_compatibility', 999); |
| 22 |
|
| 23 |
function forumax_init_sbv_compatibility() |
| 24 |
{ |
| 25 |
// Only proceed if smart-bbpress-nverify is active |
| 26 |
if (!class_exists('sbv_bbpress')) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
// Add our safety check before the profile template loads |
| 31 |
add_action('bbp_template_after_user_profile', 'forumax_sbv_safety_check', 0); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Safety check that runs before sbv_bbpress tries to render |
| 36 |
* Removes the problematic action if API is not configured |
| 37 |
*/ |
| 38 |
function forumax_sbv_safety_check() |
| 39 |
{ |
| 40 |
// Check if required functions exist |
| 41 |
if (!function_exists('smart_sbv_core') || !function_exists('sbv_api')) { |
| 42 |
forumax_remove_sbv_profile_action(); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
// Check if API settings are properly configured |
| 47 |
$api_token = smart_sbv_core()->get('global_api_token'); |
| 48 |
$user_name = smart_sbv_core()->get('global_user_name'); |
| 49 |
|
| 50 |
// If API is not configured, remove the problematic action |
| 51 |
if (empty($api_token) || empty($user_name)) { |
| 52 |
forumax_remove_sbv_profile_action(); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
// Test if API actually works |
| 57 |
$user = sbv_api()->user($user_name); |
| 58 |
if (is_wp_error($user)) { |
| 59 |
forumax_remove_sbv_profile_action(); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Remove the sbv_bbpress profile action that causes fatal errors |
| 65 |
*/ |
| 66 |
function forumax_remove_sbv_profile_action() |
| 67 |
{ |
| 68 |
global $sbv_bbpress; |
| 69 |
|
| 70 |
if (isset($sbv_bbpress) && is_object($sbv_bbpress)) { |
| 71 |
remove_action('bbp_template_after_user_profile', array($sbv_bbpress, 'bbp_template_after_user_profile')); |
| 72 |
} |
| 73 |
|
| 74 |
// Also try to find and remove by class name |
| 75 |
global $wp_filter; |
| 76 |
if (isset($wp_filter['bbp_template_after_user_profile'])) { |
| 77 |
foreach ($wp_filter['bbp_template_after_user_profile']->callbacks as $priority => $callbacks) { |
| 78 |
foreach ($callbacks as $key => $callback) { |
| 79 |
if (is_array($callback['function']) && is_object($callback['function'][0])) { |
| 80 |
if (get_class($callback['function'][0]) === 'sbv_bbpress') { |
| 81 |
unset($wp_filter['bbp_template_after_user_profile']->callbacks[$priority][$key]); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|