PluginProbe ʕ •ᴥ•ʔ
Hostinger Tools / 3.0.70
Hostinger Tools v3.0.70
3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 3.0.0 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 3.0.35 3.0.36 3.0.37 3.0.38 3.0.39 3.0.4 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.5 3.0.50 3.0.51 3.0.52 3.0.53 3.0.54 3.0.55 3.0.56 3.0.57 3.0.58 3.0.59 3.0.6 3.0.60 3.0.61 3.0.62 3.0.65 3.0.7 3.0.8 3.0.9 trunk 1.8.0
hostinger / includes / Cli / Commands / AI.php
hostinger / includes / Cli / Commands Last commit date
AI.php 2 weeks ago Maintenance.php 1 year ago
AI.php
151 lines
1 <?php
2
3 namespace Hostinger\Cli\Commands;
4
5 use Exception;
6 use Hostinger\Admin\PluginSettings;
7 use WP_CLI;
8
9 defined( 'ABSPATH' ) || exit;
10
11 class AI {
12 protected const WEB2AGENT_FEATURE_NAME = 'Web2Agent feature';
13 protected const LLMS_TXT_FEATURE_NAME = 'LLMS.txt file generation feature';
14
15 public static function define_command(): void {
16 if ( ! class_exists( 'WP_CLI' ) ) {
17 return;
18 }
19
20 WP_CLI::add_command(
21 'hostinger ai',
22 self::class,
23 array(
24 'shortdesc' => 'Check the status of AI Discovery Features',
25 'longdesc' => 'Available Hostinger AI commands:' . "\n\n" .
26 ' wp hostinger ai llmstxt <0|1>' . "\n" .
27 ' Manage the ' . self::LLMS_TXT_FEATURE_NAME . '. Use 1 to enable and 0 to disable it.' . "\n\n" .
28 ' wp hostinger ai web2agent <0|1>' . "\n" .
29 ' Manage the ' . self::WEB2AGENT_FEATURE_NAME . '. Use 1 to enable and 0 to disable it.' . "\n\n" .
30 ' wp hostinger ai status' . "\n" .
31 ' Display the current status for AI Discovery features.' . "\n\n" .
32 '## EXAMPLES' . "\n\n" .
33 ' wp hostinger ai status' . "\n" .
34 ' Display the current status for AI Discovery features.' . "\n\n" .
35 ' wp hostinger ai llmstxt 0' . "\n" .
36 ' Disables ' . self::LLMS_TXT_FEATURE_NAME . '.' . "\n\n" .
37 ' wp hostinger ai llmstxt 1' . "\n" .
38 ' Enables ' . self::LLMS_TXT_FEATURE_NAME . '.' . "\n",
39
40 )
41 );
42 }
43
44 /**
45 * Command allows enable/disable Web2Agent feature.
46 *
47 * @param array $args
48 *
49 * @return bool
50 * @throws Exception
51 */
52 public function web2agent( array $args ): bool {
53 $plugin_settings = new PluginSettings();
54
55 if ( ! empty( $args ) ) {
56 $this->validate_args( $args );
57 $this->set_setting_status( $plugin_settings, self::WEB2AGENT_FEATURE_NAME, (bool) $args[0] );
58 }
59
60 return $this->get_setting_status( $plugin_settings, self::WEB2AGENT_FEATURE_NAME );
61 }
62
63 /**
64 * Command allows enable/disable LLMS.txt file generation feature.
65 *
66 * @param array $args
67 *
68 * @return bool
69 * @throws Exception
70 */
71 public function llmstxt( array $args ): bool {
72 $plugin_settings = new PluginSettings();
73
74 if ( ! empty( $args ) ) {
75 $this->validate_args( $args );
76 $this->set_setting_status( $plugin_settings, self::LLMS_TXT_FEATURE_NAME, (bool) $args[0] );
77 }
78
79 return $this->get_setting_status( $plugin_settings, self::LLMS_TXT_FEATURE_NAME );
80 }
81
82 /**
83 * Get the current status of AI Discovery features.
84 * @return string
85 */
86 public function status(): string {
87 $plugin_settings = new PluginSettings();
88 $plugin_options = $plugin_settings->get_plugin_settings();
89
90 $data = array(
91 'llmstxt' => $plugin_options->get_enable_llms_txt(),
92 'web2agent' => $plugin_options->get_optin_mcp(),
93 );
94
95 $status = wp_json_encode( $data );
96 WP_CLI::line( $status );
97 return $status;
98 }
99
100 private function set_setting_status( PluginSettings $plugin_settings, string $setting, bool $is_enabled ): void {
101 $plugin_options = $plugin_settings->get_plugin_settings();
102
103 switch ( $setting ) {
104 case self::WEB2AGENT_FEATURE_NAME:
105 $plugin_options->set_optin_mcp( $is_enabled );
106 break;
107 case self::LLMS_TXT_FEATURE_NAME:
108 $plugin_options->set_enable_llms_txt( $is_enabled );
109 break;
110 default:
111 throw new Exception( 'Invalid setting' );
112 }
113
114 $saved_settings = $plugin_settings->save_plugin_settings( $plugin_options );
115 $this->clear_lightspeed_cache();
116
117 do_action( 'hostinger_tools_settings_saved', $saved_settings->to_array() );
118 }
119
120 private function get_setting_status( PluginSettings $plugin_settings, string $setting ): bool {
121 $plugin_options = $plugin_settings->get_plugin_settings();
122 switch ( $setting ) {
123 case self::WEB2AGENT_FEATURE_NAME:
124 $is_enabled = $plugin_options->get_optin_mcp();
125 break;
126 case self::LLMS_TXT_FEATURE_NAME:
127 $is_enabled = $plugin_options->get_enable_llms_txt();
128 break;
129 default:
130 throw new Exception( 'Invalid setting' );
131 }
132
133 $enabled = $is_enabled ? 'ENABLED' : 'DISABLED';
134
135 WP_CLI::success( $setting . ' ' . $enabled );
136 return $is_enabled;
137 }
138
139 private function validate_args( mixed $args ): void {
140 if ( $args[0] !== '0' && $args[0] !== '1' ) {
141 throw new Exception( 'Invalid argument. Use 0 or 1' );
142 }
143 }
144
145 private function clear_lightspeed_cache(): void {
146 if ( has_action( 'litespeed_purge_all' ) ) {
147 do_action( 'litespeed_purge_all' );
148 }
149 }
150 }
151