@@ -78,6 +78,15 @@ public function __construct( $plugin_name, $version ) {
7878 $ this ->plugin_name = $ plugin_name ;
7979 $ this ->version = $ version ;
8080
81+ $ this ->options = $ this ->nginx_helper_settings ();
82+ }
83+
84+ /**
85+ * Initialize the settings tab.
86+ * Required since i18n is used in the settings tab which can be invoked only after init hook since WordPress 6.7
87+ */
88+ public function initialize_setting_tab () {
89+
8190 /**
8291 * Define settings tabs
8392 */
@@ -94,8 +103,6 @@ public function __construct( $plugin_name, $version ) {
94103 ),
95104 )
96105 );
97-
98- $ this ->options = $ this ->nginx_helper_settings ();
99106 }
100107
101108 /**
@@ -274,16 +281,44 @@ public function nginx_helper_default_settings() {
274281 'purge_feeds ' => 1 ,
275282 'redis_hostname ' => '127.0.0.1 ' ,
276283 'redis_port ' => '6379 ' ,
277- 'redis_prefix ' => 'nginx-cache: ' ,
284+ 'redis_prefix ' => 'nginx-cache: ' ,
285+ 'redis_unix_socket ' => '' ,
286+ 'redis_database ' => 0 ,
287+ 'redis_username ' => '' ,
288+ 'redis_password ' => '' ,
278289 'purge_url ' => '' ,
279290 'redis_enabled_by_constant ' => 0 ,
280291 'purge_amp_urls ' => 1 ,
292+ 'redis_socket_enabled_by_constant ' => 0 ,
293+ 'redis_acl_enabled_by_constant ' => 0 ,
281294 'preload_cache ' => 0 ,
282295 'is_cache_preloaded ' => 0
283296 );
284297
285298 }
286-
299+
300+ public function store_default_options () {
301+ $ options = get_site_option ( 'rt_wp_nginx_helper_options ' , array () );
302+ $ default_settings = $ this ->nginx_helper_default_settings ();
303+
304+ $ removable_default_settings = array (
305+ 'redis_port ' ,
306+ 'redis_prefix ' ,
307+ 'redis_hostname ' ,
308+ 'redis_database ' ,
309+ 'redis_unix_socket '
310+ );
311+
312+ // Remove all the keys that are not to be stored by default.
313+ foreach ( $ removable_default_settings as $ removable_key ) {
314+ unset( $ default_settings [ $ removable_key ] );
315+ }
316+
317+ $ diffed_options = wp_parse_args ( $ options , $ default_settings );
318+
319+ add_site_option ( 'rt_wp_nginx_helper_options ' , $ diffed_options );
320+ }
321+
287322 /**
288323 * Get settings.
289324 *
@@ -297,6 +332,7 @@ public function nginx_helper_settings() {
297332 'redis_hostname ' => '127.0.0.1 ' ,
298333 'redis_port ' => '6379 ' ,
299334 'redis_prefix ' => 'nginx-cache: ' ,
335+ 'redis_database ' => 0 ,
300336 )
301337 );
302338
@@ -311,17 +347,24 @@ public function nginx_helper_settings() {
311347 defined ( 'RT_WP_NGINX_HELPER_REDIS_PREFIX ' )
312348 );
313349
350+ $ data ['redis_acl_enabled_by_constant ' ] = defined ('RT_WP_NGINX_HELPER_REDIS_USERNAME ' ) && defined ('RT_WP_NGINX_HELPER_REDIS_PASSWORD ' );
351+ $ data ['redis_socket_enabled_by_constant ' ] = defined ('RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET ' );
352+ $ data ['redis_unix_socket ' ] = $ data ['redis_socket_enabled_by_constant ' ] ? RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET : $ data ['redis_unix_socket ' ];
353+ $ data ['redis_username ' ] = $ data ['redis_acl_enabled_by_constant ' ] ? RT_WP_NGINX_HELPER_REDIS_USERNAME : $ data ['redis_username ' ];
354+ $ data ['redis_password ' ] = $ data ['redis_acl_enabled_by_constant ' ] ? RT_WP_NGINX_HELPER_REDIS_PASSWORD : $ data ['redis_password ' ];
355+
314356 if ( ! $ is_redis_enabled ) {
315357 return $ data ;
316358 }
317-
318- $ data ['redis_enabled_by_constant ' ] = $ is_redis_enabled ;
319- $ data ['enable_purge ' ] = $ is_redis_enabled ;
320- $ data ['cache_method ' ] = 'enable_redis ' ;
321- $ data ['redis_hostname ' ] = RT_WP_NGINX_HELPER_REDIS_HOSTNAME ;
322- $ data ['redis_port ' ] = RT_WP_NGINX_HELPER_REDIS_PORT ;
323- $ data ['redis_prefix ' ] = RT_WP_NGINX_HELPER_REDIS_PREFIX ;
324-
359+
360+ $ data ['redis_enabled_by_constant ' ] = $ is_redis_enabled ;
361+ $ data ['enable_purge ' ] = $ is_redis_enabled ;
362+ $ data ['cache_method ' ] = 'enable_redis ' ;
363+ $ data ['redis_hostname ' ] = RT_WP_NGINX_HELPER_REDIS_HOSTNAME ;
364+ $ data ['redis_port ' ] = RT_WP_NGINX_HELPER_REDIS_PORT ;
365+ $ data ['redis_prefix ' ] = RT_WP_NGINX_HELPER_REDIS_PREFIX ;
366+ $ data ['redis_database ' ] = defined ('RT_WP_NGINX_HELPER_REDIS_DATABASE ' ) ? RT_WP_NGINX_HELPER_REDIS_DATABASE : 0 ;
367+
325368 return $ data ;
326369
327370 }
0 commit comments