get('global_api_token'); $user_name = smart_sbv_core()->get('global_user_name'); // If API is not configured, remove the problematic action if (empty($api_token) || empty($user_name)) { forumax_remove_sbv_profile_action(); return; } // Test if API actually works. This is a remote request, so remember the // answer instead of calling the API on every profile page view. $cache_key = 'frmx_sbv_api_ok_' . md5($user_name . '|' . $api_token); $api_ok = get_transient($cache_key); if (false === $api_ok) { $api_ok = is_wp_error(sbv_api()->user($user_name)) ? 'no' : 'yes'; set_transient($cache_key, $api_ok, 'yes' === $api_ok ? 12 * HOUR_IN_SECONDS : 15 * MINUTE_IN_SECONDS); } if ('yes' !== $api_ok) { forumax_remove_sbv_profile_action(); } } /** * Remove the sbv_bbpress profile action that causes fatal errors */ function forumax_remove_sbv_profile_action() { global $sbv_bbpress; if (isset($sbv_bbpress) && is_object($sbv_bbpress)) { remove_action('bbp_template_after_user_profile', array($sbv_bbpress, 'bbp_template_after_user_profile')); } // Also try to find and remove by class name global $wp_filter; if (isset($wp_filter['bbp_template_after_user_profile'])) { foreach ($wp_filter['bbp_template_after_user_profile']->callbacks as $priority => $callbacks) { foreach ($callbacks as $key => $callback) { if (is_array($callback['function']) && is_object($callback['function'][0])) { if (get_class($callback['function'][0]) === 'sbv_bbpress') { unset($wp_filter['bbp_template_after_user_profile']->callbacks[$priority][$key]); } } } } } }