Skip to content

Commit

Permalink
Merge pull request #354 from rtCamp/feat/add-default-options
Browse files Browse the repository at this point in the history
Adds Default options in wp_options table to allow manipulating options from WP CLI.
  • Loading branch information
Vedant-Gandhi authored Oct 23, 2024
2 parents fbc7c4e + 9392d75 commit 127952f
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 127952f

Please sign in to comment.