admin
2 years ago
captcha.php
2 years ago
cloudsecure-wp.php
2 years ago
common.php
2 years ago
config.php
2 years ago
disable-author-query.php
2 years ago
disable-login.php
2 years ago
disable-restapi.php
2 years ago
disable-xmlrpc.php
2 years ago
htaccess.php
2 years ago
login-log.php
2 years ago
login-notification.php
2 years ago
rename-login-page.php
2 years ago
restrict-admin-page.php
2 years ago
unify-messages.php
2 years ago
update-notice.php
2 years ago
disable-author-query.php
105 lines
| 1 | <?php |
| 2 | class CloudSecureWP_Disable_Author_Query extends CloudSecureWP_Common { |
| 3 | private const KEY_FEATURE = 'disable_author_query'; |
| 4 | private $config; |
| 5 | |
| 6 | function __construct( array $info, CloudSecureWP_Config $config ) { |
| 7 | parent::__construct( $info ); |
| 8 | $this->config = $config; |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * 機能毎のKEY取得 |
| 13 | * |
| 14 | * @return string |
| 15 | */ |
| 16 | public function get_feature_key(): string { |
| 17 | return self::KEY_FEATURE; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * 有効無効判定 |
| 22 | * |
| 23 | * @return bool |
| 24 | */ |
| 25 | public function is_enabled(): bool { |
| 26 | return $this->config->get( $this->get_feature_key() ) === 't' ? true : false; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * 初期設定値取得 |
| 31 | * |
| 32 | * @return array |
| 33 | */ |
| 34 | public function get_default(): array { |
| 35 | $ret = array( |
| 36 | self::KEY_FEATURE => $this->check_environment() ? 't' : 'f', |
| 37 | ); |
| 38 | return $ret; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * 設定値取得 |
| 43 | */ |
| 44 | public function get_settings(): array { |
| 45 | $settings = array(); |
| 46 | $default = $this->get_default(); |
| 47 | |
| 48 | foreach ( $default as $key => $val ) { |
| 49 | $settings[ $key ] = $this->config->get( $key ); |
| 50 | } |
| 51 | |
| 52 | return $settings; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * 設定値保存 |
| 57 | * |
| 58 | * @param array $settings |
| 59 | * @return void |
| 60 | */ |
| 61 | public function save_settings( $settings ): void { |
| 62 | $default = $this->get_default(); |
| 63 | |
| 64 | foreach ( $default as $key => $val ) { |
| 65 | $this->config->set( $key, $settings[ $key ] ?? '' ); |
| 66 | } |
| 67 | |
| 68 | $this->config->save(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * author_query |
| 73 | */ |
| 74 | function init() { |
| 75 | $url = sanitize_url( $_SERVER['REQUEST_URI'] ?? '' ); |
| 76 | |
| 77 | if ( ! empty( $url ) ) { |
| 78 | if ( ! is_admin() && preg_match( '/[?&]author=\d+/i', $url ) ) { |
| 79 | wp_safe_redirect( home_url( self::PAGE_404 ) ); |
| 80 | exit; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * 有効化 |
| 87 | * |
| 88 | * @return void |
| 89 | */ |
| 90 | public function activate(): void { |
| 91 | $this->save_settings( $this->get_default() ); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * 無効化 |
| 96 | * |
| 97 | * @return void |
| 98 | */ |
| 99 | public function deactivate(): void { |
| 100 | $this->config->set( $this->get_feature_key(), 'f' ); |
| 101 | $this->config->save(); |
| 102 | } |
| 103 | |
| 104 | } |
| 105 |