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