diff --git a/inc/spbc-admin.php b/inc/spbc-admin.php index 365d6edd2..1a431d382 100644 --- a/inc/spbc-admin.php +++ b/inc/spbc-admin.php @@ -174,8 +174,16 @@ function spbc_admin_init() new CleantalkSettingsTemplates($spbc->api_key); } - // Getting key for daughter blogs once - if (!$spbc->is_mainsite && $spbc->ms__work_mode == 1 && $spbc->ms__hoster_api_key && $spbc->data['ms__key_tries'] < 3) { + // Getting key for daughter blogs once. + // The network key could be stored on the subsite after saving the settings in the mode 2 - not an individual key. + $subsite_key = $spbc->settings['spbc_key']; + if ( + !$spbc->is_mainsite && + $spbc->ms__work_mode == 1 && + $spbc->ms__hoster_api_key && + (empty($subsite_key) || $subsite_key === $spbc->network_settings['spbc_key']) && + $spbc->data['ms__key_tries'] < 3 + ) { $spbc->data['ms__key_tries']++; $spbc->save('data'); spbc_set_api_key(); diff --git a/inc/spbc-settings.php b/inc/spbc-settings.php index a9b457fb1..fefb1944e 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -574,14 +574,18 @@ function spbc_settings__error__output() $errors = $spbc->errors; $errors_out = array(); + $network_scope_types = spbc_settings__error__network_scope_types(); foreach ($errors as $type => $error) { - if (empty($error) || !isset($types[$type])) { + if (empty($error) || !isset($types[$type]) || in_array($type, $network_scope_types, true)) { continue; } if (is_array(current($error))) { foreach ($error as $sub_type => $sub_error) { + if ($type === 'cron' && in_array($sub_type, $network_scope_types, true)) { + continue; + } $text_time = isset($sub_error['error_time']) ? date('Y-m-d H:i:s', $sub_error['error_time']) . ': ' : ''; $text_type = $types[ $type ]; $text_sub_type = isset($sub_types[ $sub_type ]) ? $sub_types[ $sub_type ] : $sub_type . ': '; @@ -599,6 +603,31 @@ function spbc_settings__error__output() return $errors_out; } +/** + * Error types the network super-admin is responsible for, so they are not shown on a WPMS subsite. + * Mode 1 (Mutual Account, Individual Access Keys): the key is obtained with the network Hoster Access Key. + * Mode 2 (Mutual Account, Mutual Access Key): the subsite works with the main site key. + * + * @return string[] + */ +function spbc_settings__error__network_scope_types() +{ + global $spbc; + + if ( ! $spbc->is_network || $spbc->is_mainsite ) { + return array(); + } + + switch ( (int)$spbc->ms__work_mode ) { + case 1: + return array('get_key'); + case 2: + return array('apikey', 'get_key', 'notice_paid_till', 'access_key_notices'); + default: + return array(); + } +} + function spbc_tab__summary() { global $spbc;