admin
2 weeks ago
cli
2 weeks ago
lib
1 month ago
captcha.php
2 weeks ago
cloudsecure-wp.php
6 days ago
common.php
4 months ago
config.php
2 years ago
disable-access-system-file.php
1 month ago
disable-author-query.php
2 weeks ago
disable-login.php
1 month ago
disable-restapi.php
2 weeks ago
disable-xmlrpc.php
1 year ago
htaccess.php
4 months ago
login-log.php
1 month ago
login-notification.php
3 months ago
protect-rest-batch.php
1 month ago
rename-login-page.php
4 months ago
restrict-admin-page.php
3 months ago
server-error-notification.php
3 months ago
two-factor-authentication.php
6 days ago
unify-messages.php
2 years ago
update-notice.php
9 months ago
waf-engine.php
6 days ago
waf.php
1 month ago
disable-author-query.php
115 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 | * @param WP_Query $query |
| 80 | * @return void |
| 81 | */ |
| 82 | public function pre_get_posts( $query ) { |
| 83 | if ( is_admin() || ! $query->is_main_query() ) { |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | // URL クエリ(?author=)由来で、WordPress が数値 author として作� |
| 88 | アーカイブに解決したものだけを遮断する。 |
| 89 | if ( $query->is_author() && isset( $_GET['author'] ) && '' !== $_GET['author'] && '' !== $query->get( 'author' ) ) { |
| 90 | wp_safe_redirect( home_url( self::PAGE_404 ) ); |
| 91 | exit; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * 有効化 |
| 97 | * |
| 98 | * @return void |
| 99 | */ |
| 100 | public function activate(): void { |
| 101 | $this->save_settings( $this->get_default() ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * 無効化 |
| 106 | * |
| 107 | * @return void |
| 108 | */ |
| 109 | public function deactivate(): void { |
| 110 | $this->config->set( $this->get_feature_key(), 'f' ); |
| 111 | $this->config->save(); |
| 112 | } |
| 113 | |
| 114 | } |
| 115 |