Skip to content

Commit

Permalink
Merge pull request #363 from rtCamp/feat/add-default-options
Browse files Browse the repository at this point in the history
Add Default Options to DB to allow manipulation using WP CLI.
  • Loading branch information
Vedant-Gandhi authored Oct 24, 2024
2 parents f0c88c9 + 9392d75 commit bd917e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion admin/class-nginx-helper-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,29 @@ public function nginx_helper_default_settings() {
);

}


public function store_default_options() {
$options = get_site_option( 'rt_wp_nginx_helper_options', array() );
$default_settings = $this->nginx_helper_default_settings();

$removable_default_settings = array(
'redis_port',
'redis_prefix',
'redis_hostname',
'redis_database',
'redis_unix_socket'
);

// Remove all the keys that are not to be stored by default.
foreach ( $removable_default_settings as $removable_key ) {
unset( $default_settings[ $removable_key ] );
}

$diffed_options = wp_parse_args( $options, $default_settings );

add_site_option( 'rt_wp_nginx_helper_options', $diffed_options );
}

/**
* Get settings.
*
Expand Down
4 changes: 4 additions & 0 deletions includes/class-nginx-helper-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public static function activate() {
$role->add_cap( 'Nginx Helper | Purge cache' );

wp_schedule_event( time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily' );

if( method_exists( $nginx_helper_admin, 'store_default_options' ) ) {
$nginx_helper_admin->store_default_options();
}

}

Expand Down

0 comments on commit bd917e8

Please sign in to comment.