Skip to content

Commit bd917e8

Browse files
authoredOct 24, 2024
Merge pull request #363 from rtCamp/feat/add-default-options
Add Default Options to DB to allow manipulation using WP CLI.
2 parents f0c88c9 + 9392d75 commit bd917e8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
 

‎admin/class-nginx-helper-admin.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,29 @@ public function nginx_helper_default_settings() {
282282
);
283283

284284
}
285-
285+
286+
public function store_default_options() {
287+
$options = get_site_option( 'rt_wp_nginx_helper_options', array() );
288+
$default_settings = $this->nginx_helper_default_settings();
289+
290+
$removable_default_settings = array(
291+
'redis_port',
292+
'redis_prefix',
293+
'redis_hostname',
294+
'redis_database',
295+
'redis_unix_socket'
296+
);
297+
298+
// Remove all the keys that are not to be stored by default.
299+
foreach ( $removable_default_settings as $removable_key ) {
300+
unset( $default_settings[ $removable_key ] );
301+
}
302+
303+
$diffed_options = wp_parse_args( $options, $default_settings );
304+
305+
add_site_option( 'rt_wp_nginx_helper_options', $diffed_options );
306+
}
307+
286308
/**
287309
* Get settings.
288310
*

‎includes/class-nginx-helper-activator.php

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public static function activate() {
5757
$role->add_cap( 'Nginx Helper | Purge cache' );
5858

5959
wp_schedule_event( time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily' );
60+
61+
if( method_exists( $nginx_helper_admin, 'store_default_options' ) ) {
62+
$nginx_helper_admin->store_default_options();
63+
}
6064

6165
}
6266

0 commit comments

Comments
 (0)