| @@ -9,8 +9,11 @@ | ||
| 9 | 9 | function bBlocksTestApiKeys($key,$value){ |
| 10 | 10 | if ($key == 'openAi') { |
| 11 | 11 | return BBlocksAi::get_instance()->test_api_key($value); |
| 12 | 12 | } |
| 13 | + if ($key == 'instagram') { | |
| 14 | + return BBlocksInstagram::test_token($value); | |
| 15 | + } | |
| 13 | 16 | } |
| 14 | 17 | |
| 15 | 18 | function bBlocksApiKeys(){ |
| 16 | 19 | $nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce']?? null ) ) ; |
| @@ -25,13 +28,19 @@ | ||
| 25 | 28 | |
| 26 | 29 | $key = sanitize_text_field(wp_unslash($_POST['key'] ?? '')); |
| 27 | 30 | $value = sanitize_text_field(wp_unslash($_POST['value'] ?? '')); |
| 28 | 31 | $apiKeys = get_option('bBlocksApiKeys',[]); |
| 29 | - $error = $this->bBlocksTestApiKeys($key,$value); | |
| 30 | - | |
| 31 | - if (isset($error['valid']) && !$error['valid']) { | |
| 32 | - wp_send_json_error([$key=>$error]); | |
| 32 | + | |
| 33 | + if ( '' !== $value ) { | |
| 34 | + $error = $this->bBlocksTestApiKeys($key,$value); | |
| 35 | + | |
| 36 | + if (isset($error['valid']) && !$error['valid']) { | |
| 37 | + wp_send_json_error([$key=>$error]); | |
| 38 | + } | |
| 39 | + } elseif ( 'instagram' === $key && class_exists( __NAMESPACE__ . '\BBlocksInstagram' ) ) { | |
| 40 | + BBlocksInstagram::flush(); | |
| 33 | 41 | } |
| 42 | + | |
| 34 | 43 | if ($key) { |
| 35 | 44 | $apiKeys[$key] = ['key'=> $value]; |
| 36 | 45 | update_option( 'bBlocksApiKeys',$apiKeys); |
| 37 | 46 | } |