Skip to content

Commit d8d4553

Browse files
Merge pull request #17 from GDATASoftwareAG/apply-wordpress-review-suggestions
Apply wordpress review suggestions
2 parents 9a4ad7e + 50fcb2c commit d8d4553

File tree

12 files changed

+248
-237
lines changed

12 files changed

+248
-237
lines changed

.zipignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.git/*
44
wordpress/*
55
tests/*
6-
compose*
6+
compose.yml
77
Dockerfile
88
test.sh
99
xdebug.ini

PluginPage/AdminNotices.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public static function add_notice( $text ) {
1919
}
2020

2121
public function save_notices() {
22-
update_option('GdataAntivirusMenuNotices', self::$notices);
22+
update_option('gdatacyberdefenseag_antivirus_notices', self::$notices);
2323
}
2424

2525
public function output_notices() {
26-
$notices = maybe_unserialize(get_option('GdataAntivirusMenuNotices'));
26+
$notices = maybe_unserialize(get_option('gdatacyberdefenseag_antivirus_notices'));
2727

2828
if (! empty($notices)) {
2929
echo '<div id="notice" class="notice notice-info is-dismissible">';
@@ -34,7 +34,7 @@ public function output_notices() {
3434

3535
echo '</div>';
3636

37-
delete_option('GdataAntivirusMenuNotices');
37+
delete_option('gdatacyberdefenseag_antivirus_notices');
3838
}
3939
}
4040
}

PluginPage/Findings/FindingsMenuPage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function __construct(
2828
$this->logger = $logger;
2929
$this->admin_notices = $admin_notices;
3030

31-
register_activation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_findings_table' ));
32-
register_deactivation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_findings_table' ));
31+
register_activation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_findings_table' ));
32+
register_deactivation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_findings_table' ));
3333

3434
if ($this->get_findings_count() === 0) {
3535
return;
@@ -41,7 +41,7 @@ public function __construct(
4141

4242
private function get_table_name(): string {
4343
$this->logger->debug('FindingsMenuPage::get_table_name');
44-
return $this->database->get_prefix(). WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME;
44+
return $this->database->get_prefix(). GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_TABLE_NAME;
4545
}
4646

4747
public function create_findings_table() {
@@ -134,11 +134,11 @@ public function get_findings_count(): int {
134134

135135
public function setup_menu(): void {
136136
\add_submenu_page(
137-
WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG,
137+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG,
138138
'Scan Findings',
139139
'Scan Findings <span class="awaiting-mod">' . $this->get_findings_count() . '</span>',
140140
'manage_options',
141-
WORDPRESS_GDATA_ANTIVIRUS_MENU_FINDINGS_SLUG,
141+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FINDINGS_SLUG,
142142
array( $this, 'findings_list' )
143143
);
144144
}

PluginPage/FullScan/FullScanMenuPage.php

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function __construct(
3232
$this->logger = $logger;
3333
$this->database = $database;
3434

35-
register_activation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_full_scan_operations_table' ));
36-
register_deactivation_hook(WORDPRESS_GDATA_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_full_scan_operations_table' ));
35+
register_activation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'create_full_scan_operations_table' ));
36+
register_deactivation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this, 'remove_full_scan_operations_table' ));
3737

3838
if (! $vaas_options->credentials_configured()) {
3939
return;
@@ -44,36 +44,36 @@ public function __construct(
4444
\add_action('init', array( $this, 'setup_fields' ));
4545
\add_action('admin_menu', array( $this, 'setup_menu' ));
4646
\add_action('admin_post_full_scan', array( $this, 'full_scan_interactive' ));
47-
\add_action('wordpress_gdata_antivirus_scheduled_full_scan', array( $this, 'full_scan' ));
47+
\add_action('gdatacyberdefenseag_antivirus_scheduled_full_scan', array( $this, 'full_scan' ));
4848
\add_action(
49-
'wordpress_gdata_antivirus_scan_batch',
49+
'gdatacyberdefenseag_antivirus_scan_batch',
5050
array( $this, 'scan_batch' ),
5151
);
5252

5353
$this->setup_scheduled_scan();
5454
}
5555

5656
private function setup_scheduled_scan() {
57-
$full_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false);
58-
$schedule_start = \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_start', '01:00');
59-
$next = wp_next_scheduled('wordpress_gdata_antivirus_scheduled_full_scan');
57+
$full_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
58+
$schedule_start = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
59+
$next = wp_next_scheduled('gdatacyberdefenseag_antivirus_scheduled_full_scan');
6060

6161
if (! $full_scan_enabled && $next) {
62-
\wp_unschedule_event($next, 'wordpress_gdata_antivirus_scheduled_full_scan');
62+
\wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
6363
return;
6464
}
6565

6666
if ($full_scan_enabled && ! $next) {
6767
$timestamp = strtotime($schedule_start);
6868
$this->logger->debug('schedule start timestamp: ' . $timestamp);
69-
\wp_schedule_event($timestamp, 'daily', 'wordpress_gdata_antivirus_scheduled_full_scan');
69+
\wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
7070
return;
7171
}
7272
$nextschedule_start = gmdate('H:i', $next);
7373
if ($nextschedule_start !== $schedule_start) {
74-
\wp_unschedule_event($next, 'wordpress_gdata_antivirus_scheduled_full_scan');
74+
\wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
7575
$timestamp = strtotime($schedule_start);
76-
\wp_schedule_event($timestamp, 'daily', 'wordpress_gdata_antivirus_scheduled_full_scan');
76+
\wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
7777
}
7878
}
7979

@@ -91,7 +91,7 @@ public function create_full_scan_operations_table() {
9191
}
9292

9393
private function get_table_name(): string {
94-
return $this->database->get_prefix() . WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME;
94+
return $this->database->get_prefix() . GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_OPERATIONS_TABLE_NAME;
9595
}
9696

9797
public function lock_scan_operations_table() {
@@ -128,26 +128,26 @@ public function reset_scan_operations(): void {
128128

129129
public function setup_fields(): void {
130130
\register_setting(
131-
'wordpress_gdata_antivirus_options_full_scan_run',
132-
'wordpress_gdata_antivirus_options_full_scan_batch_size',
131+
'gdatacyberdefenseag_antivirus_options_full_scan_run',
132+
'gdatacyberdefenseag_antivirus_options_full_scan_batch_size',
133133
array(
134134
'type' => 'number',
135135
'default' => 100,
136-
'sanitize_callback' => array( $this, 'wordpress_gdata_antivirus_options_full_scan_batch_size_validation' ),
136+
'sanitize_callback' => array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation' ),
137137
)
138138
);
139139
\register_setting(
140-
'wordpress_gdata_antivirus_options_full_scan_run',
141-
'wordpress_gdata_antivirus_options_full_scan_schedule_start',
140+
'gdatacyberdefenseag_antivirus_options_full_scan_run',
141+
'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start',
142142
array(
143143
'type' => 'string',
144144
'default' => '01:00',
145-
'sanitize_callback' => array( $this, 'wordpress_gdata_antivirus_options_full_scan_schedule_start_validation' ),
145+
'sanitize_callback' => array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation' ),
146146
)
147147
);
148148
\register_setting(
149-
'wordpress_gdata_antivirus_options_full_scan_run',
150-
'wordpress_gdata_antivirus_options_full_scan_schedule_enabled',
149+
'gdatacyberdefenseag_antivirus_options_full_scan_run',
150+
'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled',
151151
array(
152152
'type' => 'boolean',
153153
'default' => false,
@@ -157,106 +157,106 @@ public function setup_fields(): void {
157157

158158
public function setup_menu(): void {
159159
\add_settings_section(
160-
'wordpress_gdata_antivirus_options_full_scan',
160+
'gdatacyberdefenseag_antivirus_options_full_scan',
161161
esc_html__('Full Scan', 'gdata-antivirus'),
162-
array( $this, 'wordpress_gdata_antivirus_options_full_scan_text' ),
163-
WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG
162+
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_text' ),
163+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG
164164
);
165165

166166
\add_settings_field(
167-
'wordpress_gdata_antivirus_options_full_scan_batch_size',
167+
'gdatacyberdefenseag_antivirus_options_full_scan_batch_size',
168168
esc_html__('Batch Size', 'gdata-antivirus'),
169-
array( $this, 'wordpress_gdata_antivirus_options_full_scan_batch_size_text' ),
170-
WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
171-
'wordpress_gdata_antivirus_options_full_scan'
169+
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text' ),
170+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
171+
'gdatacyberdefenseag_antivirus_options_full_scan'
172172
);
173173

174174
\add_settings_field(
175-
'wordpress_gdata_antivirus_options_full_scan_schedule_enabled',
175+
'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled',
176176
esc_html__('Scheduled Scan enabled', 'gdata-antivirus'),
177-
array( $this, 'wordpress_gdata_antivirus_options_full_scan_schedule_enabled_text' ),
178-
WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
179-
'wordpress_gdata_antivirus_options_full_scan'
177+
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text' ),
178+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
179+
'gdatacyberdefenseag_antivirus_options_full_scan'
180180
);
181181

182182
\add_settings_field(
183-
'wordpress_gdata_antivirus_options_full_scan_schedule_start',
183+
'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start',
184184
esc_html__('Scheduled Scan starting Hour', 'gdata-antivirus'),
185-
array( $this, 'wordpress_gdata_antivirus_options_full_scan_schedule_start_text' ),
186-
WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
187-
'wordpress_gdata_antivirus_options_full_scan'
185+
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text' ),
186+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
187+
'gdatacyberdefenseag_antivirus_options_full_scan'
188188
);
189189

190190
\add_submenu_page(
191-
WORDPRESS_GDATA_ANTIVIRUS_MENU_SLUG,
191+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_SLUG,
192192
'Full scan',
193193
'Full scan',
194194
'manage_options',
195-
WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
195+
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
196196
array( $this, 'full_scan_menu' )
197197
);
198198
}
199199

200-
public function wordpress_gdata_antivirus_options_full_scan_batch_size_validation( $value ) {
201-
$option = get_option('wordpress_gdata_antivirus_options_full_scan_batch_size', 100);
200+
public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation( $value ) {
201+
$option = get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100);
202202
if (0 === $value) {
203203
$value = $option;
204204
add_settings_error(
205-
'wordpress_gdata_antivirus_options_full_scan_batch_size',
206-
'wordpress_gdata_antivirus_options_full',
207-
__('batch_size cannot be 0')
205+
'gdatacyberdefenseag_antivirus_options_full_scan_batch_size',
206+
'gdatacyberdefenseag_antivirus_options_full',
207+
__('batch_size cannot be 0', 'gdata-antivirus')
208208
);
209209
}
210210
if ($value < 100) {
211211
$value = $option;
212212
add_settings_error(
213-
'wordpress_gdata_antivirus_options_full_scan_batch_size',
214-
'wordpress_gdata_antivirus_options_full',
215-
__('batch_size should be at least 100')
213+
'gdatacyberdefenseag_antivirus_options_full_scan_batch_size',
214+
'gdatacyberdefenseag_antivirus_options_full',
215+
__('batch_size should be at least 100', 'gdata-antivirus')
216216
);
217217
}
218218
return $value;
219219
}
220220

221-
public function wordpress_gdata_antivirus_options_full_scan_schedule_start_validation( $value ) {
222-
$option = get_option('wordpress_gdata_antivirus_options_full_scan_schedule_start', '01:00');
223-
$full_scan_enabled = get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false);
221+
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation( $value ) {
222+
$option = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
223+
$full_scan_enabled = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
224224

225225
if (! $full_scan_enabled) {
226226
return $option;
227227
}
228228
if (preg_match('#^[0-9]{2}:[0-9]{2}$#', $value) !== 1) {
229229
$value = $option;
230230
add_settings_error(
231-
'wordpress_gdata_antivirus_options_full_scan_schedule_start',
232-
'wordpress_gdata_antivirus_options_full_scan',
233-
__('schedule start must be of format H:i')
231+
'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start',
232+
'gdatacyberdefenseag_antivirus_options_full_scan',
233+
__('schedule start must be of format H:i', 'gdata-antivirus')
234234
);
235235
}
236236
return $value;
237237
}
238238

239-
public function wordpress_gdata_antivirus_options_full_scan_text() {
239+
public function gdatacyberdefenseag_antivirus_options_full_scan_text() {
240240
echo '<p>' . esc_html__('Here you can set options for the full scan', 'gdata-antivirus') . '</p>';
241241
}
242242

243-
public function wordpress_gdata_antivirus_options_full_scan_schedule_enabled_text() {
244-
$full_scan_enabled = (bool) \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false);
245-
echo "<input id='wordpress_gdata_antivirus_options_full_scan_schedule_enabled' name='wordpress_gdata_antivirus_options_full_scan_schedule_enabled' type='checkbox' value='true' " . \checked(true, $full_scan_enabled, false) . "' />";
243+
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text() {
244+
$full_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
245+
echo "<input id='gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled' name='gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled' type='checkbox' value='true' " . \checked(true, $full_scan_enabled, false) . "' />";
246246
}
247247

248-
public function wordpress_gdata_antivirus_options_full_scan_batch_size_text() {
249-
$batch_size = \get_option('wordpress_gdata_antivirus_options_full_scan_batch_size', 100);
250-
echo "<input id='wordpress_gdata_antivirus_options_full_scan_batch_size' name='wordpress_gdata_antivirus_options_full_scan_batch_size' type='text' value='" . \esc_attr($batch_size) . "' />";
248+
public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text() {
249+
$batch_size = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100);
250+
echo "<input id='gdatacyberdefenseag_antivirus_options_full_scan_batch_size' name='gdatacyberdefenseag_antivirus_options_full_scan_batch_size' type='text' value='" . \esc_attr($batch_size) . "' />";
251251
}
252252

253-
public function wordpress_gdata_antivirus_options_full_scan_schedule_start_text() {
254-
$schedule_start = \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_start', '01:00');
253+
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text() {
254+
$schedule_start = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
255255
$full_scan_enabled =
256-
(bool) \get_option('wordpress_gdata_antivirus_options_full_scan_schedule_enabled', false);
256+
(bool) \get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
257257
$this->logger->debug('schedule_start: ' . $schedule_start);
258258

259-
echo "<input id='wordpress_gdata_antivirus_options_full_scan_schedule_start' name='wordpress_gdata_antivirus_options_full_scan_schedule_start' type='text' value='" . \esc_attr($schedule_start) . "' " . ( $full_scan_enabled ? '' : 'disabled' ) . '/>';
259+
echo "<input id='gdatacyberdefenseag_antivirus_options_full_scan_schedule_start' name='gdatacyberdefenseag_antivirus_options_full_scan_schedule_start' type='text' value='" . \esc_attr($schedule_start) . "' " . ( $full_scan_enabled ? '' : 'disabled' ) . '/>';
260260
}
261261

262262
public function full_scan_interactive(): void {
@@ -285,7 +285,7 @@ public function full_scan_interactive(): void {
285285
public function full_scan(): void {
286286
$this->admin_notices->add_notice(__('Full Scan started', 'gdata-antivirus'));
287287

288-
$batch_size = \get_option('wordpress_gdata_antivirus_options_full_scan_batch_size', 100);
288+
$batch_size = \get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100);
289289
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ABSPATH, \FilesystemIterator::SKIP_DOTS));
290290
$files = array();
291291
foreach ($it as $file_path) {
@@ -300,13 +300,13 @@ public function full_scan(): void {
300300
if (count($files) >= $batch_size) {
301301
$this->increase_scheduled_scans();
302302

303-
\wp_schedule_single_event(time(), 'wordpress_gdata_antivirus_scan_batch', array( 'files' => $files ));
303+
\wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array( 'files' => $files ));
304304
$files = array();
305305
}
306306
}
307307
if (count($files) > 0) {
308308
$this->increase_scheduled_scans();
309-
\wp_schedule_single_event(time(), 'wordpress_gdata_antivirus_scan_batch', array( 'files' => $files ));
309+
\wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array( 'files' => $files ));
310310
}
311311
}
312312

@@ -339,14 +339,14 @@ public function scan_batch( array $files ): void {
339339
}
340340

341341
public function full_scan_menu(): void {
342-
settings_errors('wordpress_gdata_antivirus_options_full_scan_schedule_start');
343-
settings_errors('wordpress_gdata_antivirus_options_full_scan_batch_size');
342+
settings_errors('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start');
343+
settings_errors('gdatacyberdefenseag_antivirus_options_full_scan_batch_size');
344344
?>
345345
<h2>Full Scan Settings</h2>
346346
<form action="options.php" method="post">
347347
<?php
348-
\settings_fields('wordpress_gdata_antivirus_options_full_scan_run');
349-
\do_settings_sections(WORDPRESS_GDATA_ANTIVIRUS_MENU_FULL_SCAN_SLUG);
348+
\settings_fields('gdatacyberdefenseag_antivirus_options_full_scan_run');
349+
\do_settings_sections(GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG);
350350
?>
351351
<input name="submit" class="button button-primary" type="submit" value="<?php \esc_attr_e('Save', 'gdata-antivirus'); ?>" />
352352
</form>

0 commit comments

Comments
 (0)