| @@ -52,11 +52,19 @@ | ||
| 52 | 52 | forumax_remove_sbv_profile_action(); |
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - // Test if API actually works | |
| 57 | - $user = sbv_api()->user($user_name); | |
| 58 | - if (is_wp_error($user)) { | |
| 56 | + // Test if API actually works. This is a remote request, so remember the | |
| 57 | + // answer instead of calling the API on every profile page view. | |
| 58 | + $cache_key = 'frmx_sbv_api_ok_' . md5($user_name . '|' . $api_token); | |
| 59 | + $api_ok = get_transient($cache_key); | |
| 60 | + | |
| 61 | + if (false === $api_ok) { | |
| 62 | + $api_ok = is_wp_error(sbv_api()->user($user_name)) ? 'no' : 'yes'; | |
| 63 | + set_transient($cache_key, $api_ok, 'yes' === $api_ok ? 12 * HOUR_IN_SECONDS : 15 * MINUTE_IN_SECONDS); | |
| 64 | + } | |
| 65 | + | |
| 66 | + if ('yes' !== $api_ok) { | |
| 59 | 67 | forumax_remove_sbv_profile_action(); |
| 60 | 68 | } |
| 61 | 69 | } |
| 62 | 70 | |