| 1 |
<?php |
| 2 |
// Exit if accessed directly. |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Synchronize the directory-indexing marker section after an option save. |
| 9 |
* |
| 10 |
* @param mixed $value New option value. |
| 11 |
* @return array |
| 12 |
*/ |
| 13 |
function ns_shield_sync_directory_indexing_htaccess( $value ) { |
| 14 |
$lines = ns_shield_htaccess_option_is_enabled( $value ) |
| 15 |
? array( 'Options -Indexes' ) |
| 16 |
: array(); |
| 17 |
|
| 18 |
return ns_shield_sync_htaccess_marker( |
| 19 |
'NETSENSAI SHIELD DIRECTORY INDEXING', |
| 20 |
$lines, |
| 21 |
'ns_shield_directory_indexing_htaccess_sync_result' |
| 22 |
); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Synchronize after the option is first added. |
| 27 |
* |
| 28 |
* @param string $option Option name. |
| 29 |
* @param mixed $value New option value. |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
function ns_shield_directory_indexing_option_added( $option, $value ) { |
| 33 |
ns_shield_sync_directory_indexing_htaccess( $value ); |
| 34 |
} |
| 35 |
add_action( 'add_option_ns_shield_directory_indexing', 'ns_shield_directory_indexing_option_added', 10, 2 ); |
| 36 |
|
| 37 |
/** |
| 38 |
* Synchronize only after the option value actually changes. |
| 39 |
* |
| 40 |
* @param mixed $old_value Previous option value. |
| 41 |
* @param mixed $value New option value. |
| 42 |
* @param string $option Option name. |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
function ns_shield_directory_indexing_option_updated( $old_value, $value, $option ) { |
| 46 |
if ( ns_shield_htaccess_option_is_enabled( $old_value ) === ns_shield_htaccess_option_is_enabled( $value ) ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
ns_shield_sync_directory_indexing_htaccess( $value ); |
| 51 |
} |
| 52 |
add_action( 'update_option_ns_shield_directory_indexing', 'ns_shield_directory_indexing_option_updated', 10, 3 ); |
| 53 |
|