Skip to content

Commit d3fbe89

Browse files
authored
Upd. Settings. Update links on wpms to subsite settings. (#738)
Co-authored-by: svedge <svedge@users.noreply.github.com>
1 parent c7c6ef4 commit d3fbe89

9 files changed

Lines changed: 78 additions & 7 deletions

File tree

‎inc/spbc-settings.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ function spbc_field_scanner__show_accordion($direct_call = false)
19331933

19341934
//cure log description
19351935
$cure_log_description = sprintf(
1936-
'<div> %s <a href="/wp-admin/options-general.php?page=spbc&spbc_tab=backups">%s</a><br><ul><li>%s</li><li>%s</li></ul></div>',
1936+
'<div> %s <a href="' . esc_url($spbc->settings_link . '&spbc_tab=backups') . '">%s</a><br><ul><li>%s</li><li>%s</li></ul></div>',
19371937
__('These files were automatically cured. You can see backups and restore files on the ', 'security-malware-firewall'),
19381938
__('Backups tab:', 'security-malware-firewall'),
19391939
__('CURED - the file was automatically cured.', 'security-malware-firewall'),

‎js/public/spbct-react-bundle.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/src/react/components/TabContent/TabFirewall/TabFirewall.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ export default function TabFirewall({sectionId, sectionData, isActive}) {
319319
'Plugin does not work until you enter the Access key in ',
320320
'security-malware-firewall',
321321
)}
322-
<a href={'/wp-admin/options-general.php?page=spbc&spbc_tab=settings_general'}>
322+
<a href={sectionData.strings.access_key_settings_url ||
323+
'options-general.php?page=spbc&spbc_tab=settings_general'}>
323324
{__('General settings', 'security-malware-firewall')}
324325
</a>.
325326
</h3>

‎lib/CleantalkSP/SpbctWP/AdminBannersModule/AdminBanners/AdminBannerEmptyKey.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function needToShow()
6464
*/
6565
protected function display()
6666
{
67-
$link = get_admin_url(get_main_site_id(), 'options-general.php?page=spbc&spbc_tab=settings_general');
67+
$link = $this->banners_handler->spbc->getAccessKeySettingsUrl();
6868
$msg = __('Please enter the Access Key in Security by CleanTalk plugin to enable security features!', 'security-malware-firewall');
6969
$is_dismissible_text = $this->is_settings_page ? '' : 'is-dismissible';
7070
$div_head = '<div class="spbc-notice error um-admin-notice notice '

‎lib/CleantalkSP/SpbctWP/AdminBannersModule/AdminBanners/AdminBannerWrongKey.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ protected function needToShow()
6565
*/
6666
protected function display()
6767
{
68-
$link = get_admin_url(get_main_site_id(), 'options-general.php?page=spbc&spbc_tab=settings_general');
69-
$msg = __('Access key is not valid. Enter into plugin settings in the main site dashboard to get access key.', 'security-malware-firewall');
68+
$link = $this->banners_handler->spbc->getAccessKeySettingsUrl();
69+
$use_main_site_copy = $this->banners_handler->spbc->is_network
70+
&& ! $this->banners_handler->spbc->is_mainsite
71+
&& (int) $this->banners_handler->spbc->ms__work_mode === 2;
72+
$msg = $use_main_site_copy
73+
? __('Access key is not valid. Enter into plugin settings in the main site dashboard to get access key.', 'security-malware-firewall')
74+
: __('Access key is not valid. Enter into plugin settings to get access key.', 'security-malware-firewall');
7075
$is_dismissible_text = $this->is_settings_page ? '' : 'is-dismissible';
7176
$div_head = '<div class="spbc-notice error um-admin-notice notice '
7277
. $is_dismissible_text

‎lib/CleantalkSP/SpbctWP/FeatureRestriction/FeatureRestrictionView.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ class FeatureRestrictionView
1313
*/
1414
public static function keyNotValid()
1515
{
16+
global $spbc;
17+
18+
$link = admin_url('options-general.php?page=spbc&spbc_tab=settings_general');
19+
if (isset($spbc) && is_object($spbc) && method_exists($spbc, 'getAccessKeySettingsUrl')) {
20+
$maybe_link = $spbc->getAccessKeySettingsUrl();
21+
if (is_string($maybe_link) && $maybe_link !== '') {
22+
$link = $maybe_link;
23+
}
24+
}
25+
1626
return '<div style="margin: 10px auto; text-align: center;"><h3 style="margin: 5px; display: inline-block;">'
1727
. __('Plugin does not work until you enter the Access key in ', 'security-malware-firewall')
18-
. '<a href="/wp-admin/options-general.php?page=spbc&spbc_tab=settings_general">'
28+
. '<a href="' . esc_url($link) . '">'
1929
. __('General settings', 'security-malware-firewall')
2030
. '</a>.</h3></div>';
2131
}

‎lib/CleantalkSP/SpbctWP/Firewall/View.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static function getReactData($data)
2525
$data['objects']['service_id'] = $spbc->service_id;
2626

2727
$data['flags']['is_key_ok'] = $spbc->key_is_ok;
28+
$data['strings']['access_key_settings_url'] = $spbc->getAccessKeySettingsUrl();
2829
$data['flags']['showMoreButton'] = self::getFirewallRowsCount() > SPBC_LAST_ACTIONS_TO_VIEW;
2930
$data['flags']['is_traffic_control_enabled'] = isset($spbc->settings['traffic_control__enabled']) && $spbc->settings['traffic_control__enabled'] == true;
3031
$data['flags']['is_waf_enabled'] = isset($spbc->settings['waf__enabled']) && $spbc->settings['waf__enabled'] == true;

‎lib/CleantalkSP/SpbctWP/State.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,30 @@ protected function init()
423423
$this->update_logger = new Firewall\SpbcFWUpdateLogger();
424424
}
425425

426+
/**
427+
* Settings URL where the Access key is entered.
428+
* Individual keys (WPMS modes 1 and 3): current site.
429+
* Mutual Access Key (mode 2): main site.
430+
*
431+
* @param string $tab
432+
*
433+
* @return string
434+
* @psalm-suppress PossiblyUnusedMethod
435+
*/
436+
public function getAccessKeySettingsUrl($tab = 'settings_general')
437+
{
438+
$path = 'options-general.php?page=spbc';
439+
if ($tab !== '') {
440+
$path .= '&spbc_tab=' . rawurlencode($tab);
441+
}
442+
443+
if ($this->is_network && ! $this->is_mainsite && (int) $this->ms__work_mode === 2) {
444+
return get_admin_url(get_main_site_id(), $path);
445+
}
446+
447+
return admin_url($path);
448+
}
449+
426450
/**
427451
* Wrapper for CMS
428452
* Getting the option from the database

‎tests/main/StateTest.php‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,34 @@ public function testIsHaveErrors()
3838
));
3939
$this->assertTrue($this->state->isHaveErrors());
4040
}
41+
42+
public function testGetAccessKeySettingsUrlUsesCurrentSiteForIndividualKeys()
43+
{
44+
$subsite_state = new State(
45+
'spbc',
46+
array(
47+
'settings',
48+
'data',
49+
'remote_calls',
50+
'debug',
51+
'installing',
52+
'errors',
53+
'fw_stats'
54+
),
55+
true,
56+
false
57+
);
58+
$subsite_state->ms__work_mode = 1;
59+
60+
$this->assertSame(
61+
admin_url('options-general.php?page=spbc&spbc_tab=settings_general'),
62+
$subsite_state->getAccessKeySettingsUrl()
63+
);
64+
65+
$subsite_state->ms__work_mode = 2;
66+
$this->assertSame(
67+
get_admin_url(get_main_site_id(), 'options-general.php?page=spbc&spbc_tab=settings_general'),
68+
$subsite_state->getAccessKeySettingsUrl()
69+
);
70+
}
4171
}

0 commit comments

Comments
 (0)