class-cloudsecure-wp-cli-disable-restapi.php
8 months ago
class-cloudsecure-wp-cli-disable.php
8 months ago
class-cloudsecure-wp-cli-enable.php
8 months ago
class-cloudsecure-wp-cli-list.php
8 months ago
class-cloudsecure-wp-cli-status.php
8 months ago
class-cloudsecure-wp-cli-disable-restapi.php
100 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CloudSecure WP Security CLI Disable REST API Command |
| 4 | * |
| 5 | * @package CloudSecure_WP_Security |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | if ( ! class_exists( 'WP_CLI' ) ) { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | // ベースクラスを読み込み |
| 17 | require_once dirname( __DIR__ ) . '/class-cloudsecure-wp-cli-base.php'; |
| 18 | |
| 19 | /** |
| 20 | * CloudSecure WP Security Disable REST API Command |
| 21 | * REST API無効化機能専用のコマンドクラス |
| 22 | */ |
| 23 | class CloudSecureWP_CLI_Disable_Restapi extends CloudSecureWP_CLI_Base { |
| 24 | |
| 25 | /** |
| 26 | * 機能名 |
| 27 | */ |
| 28 | private const FEATURE_NAME = 'disable-restapi'; |
| 29 | |
| 30 | /** |
| 31 | * @var object REST API無効化機能のインスタンス |
| 32 | */ |
| 33 | private $feature_instance; |
| 34 | |
| 35 | public function __construct() { |
| 36 | parent::__construct(); |
| 37 | $this->init_feature_instance(); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * REST API無効化機能のインスタンスを初期化 |
| 42 | */ |
| 43 | private function init_feature_instance() { |
| 44 | $this->feature_instance = $this->get_feature_instance( self::FEATURE_NAME ); |
| 45 | |
| 46 | if ( ! $this->feature_instance ) { |
| 47 | WP_CLI::error( 'REST API無効化機能のインスタンスを取得できませんでした。' ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * 有効済みプラグインの一覧を取得 |
| 53 | * |
| 54 | * ## DESCRIPTION |
| 55 | * REST API無効化機能で除外指定していない有効なプラグインの一覧を取得します。 |
| 56 | * |
| 57 | * ## EXAMPLES |
| 58 | * wp cldsec-wp-security disable-restapi list-plugins |
| 59 | * |
| 60 | * @subcommand list-plugins |
| 61 | */ |
| 62 | public function list_plugins( $args = array(), $assoc_args = array() ) { |
| 63 | try { |
| 64 | // 機能が存在するかチェック |
| 65 | if ( ! $this->feature_instance ) { |
| 66 | $this->output_error_response( array( 'message' => 'REST API無効化機能が利用できません。' ) ); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | // 有効済みプラグインの一覧を取得 |
| 71 | if ( ! method_exists( $this->feature_instance, 'get_active_plugin_names' ) ) { |
| 72 | $this->output_error_response( array( 'message' => 'get_active_plugin_namesメソッドが見つかりません。' ) ); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | $active_plugins = $this->feature_instance->get_active_plugin_names(); |
| 77 | |
| 78 | // プラグイン名をカンマ区切りの文字列に変換 |
| 79 | $plugin_names_string = $this->convert_array_to_string( $active_plugins ); |
| 80 | |
| 81 | // 成功レスポンス |
| 82 | $response_data = array( |
| 83 | 'result' => 'success', |
| 84 | 'data' => array( |
| 85 | 'active_plugin_names' => $plugin_names_string, |
| 86 | ), |
| 87 | ); |
| 88 | |
| 89 | $this->output_success_response( $response_data ); |
| 90 | |
| 91 | } catch ( Exception $e ) { |
| 92 | $this->output_error_response( |
| 93 | array( |
| 94 | 'message' => 'コマンド実行中にエラーが発生しました: ' . $e->getMessage(), |
| 95 | ) |
| 96 | ); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 |