Initial commit: Atomaste website
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\Cli\Commands;
|
||||
|
||||
use Exception;
|
||||
use Hostinger\Admin\PluginSettings;
|
||||
use WP_CLI;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class AI {
|
||||
protected const WEB2AGENT_FEATURE_NAME = 'Web2Agent feature';
|
||||
protected const LLMS_TXT_FEATURE_NAME = 'LLMS.txt file generation feature';
|
||||
|
||||
public static function define_command(): void {
|
||||
if ( ! class_exists( 'WP_CLI' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
WP_CLI::add_command(
|
||||
'hostinger ai',
|
||||
self::class,
|
||||
array(
|
||||
'shortdesc' => 'Check the status of AI Discovery Features',
|
||||
'longdesc' => 'Available Hostinger AI commands:' . "\n\n" .
|
||||
' wp hostinger ai llmstxt <0|1>' . "\n" .
|
||||
' Manage the ' . self::LLMS_TXT_FEATURE_NAME . '. Use 1 to enable and 0 to disable it.' . "\n\n" .
|
||||
' wp hostinger ai web2agent <0|1>' . "\n" .
|
||||
' Manage the ' . self::WEB2AGENT_FEATURE_NAME . '. Use 1 to enable and 0 to disable it.' . "\n\n" .
|
||||
' wp hostinger ai status' . "\n" .
|
||||
' Display the current status for AI Discovery features.' . "\n\n" .
|
||||
'## EXAMPLES' . "\n\n" .
|
||||
' wp hostinger ai status' . "\n" .
|
||||
' Display the current status for AI Discovery features.' . "\n\n" .
|
||||
' wp hostinger ai llmstxt 0' . "\n" .
|
||||
' Disables ' . self::LLMS_TXT_FEATURE_NAME . '.' . "\n\n" .
|
||||
' wp hostinger ai llmstxt 1' . "\n" .
|
||||
' Enables ' . self::LLMS_TXT_FEATURE_NAME . '.' . "\n",
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Command allows enable/disable Web2Agent feature.
|
||||
*
|
||||
* @param array $args
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function web2agent( array $args ): bool {
|
||||
$plugin_settings = new PluginSettings();
|
||||
|
||||
if ( ! empty( $args ) ) {
|
||||
$this->validate_args( $args );
|
||||
$this->set_setting_status( $plugin_settings, self::WEB2AGENT_FEATURE_NAME, (bool) $args[0] );
|
||||
}
|
||||
|
||||
return $this->get_setting_status( $plugin_settings, self::WEB2AGENT_FEATURE_NAME );
|
||||
}
|
||||
|
||||
/**
|
||||
* Command allows enable/disable LLMS.txt file generation feature.
|
||||
*
|
||||
* @param array $args
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function llmstxt( array $args ): bool {
|
||||
$plugin_settings = new PluginSettings();
|
||||
|
||||
if ( ! empty( $args ) ) {
|
||||
$this->validate_args( $args );
|
||||
$this->set_setting_status( $plugin_settings, self::LLMS_TXT_FEATURE_NAME, (bool) $args[0] );
|
||||
}
|
||||
|
||||
return $this->get_setting_status( $plugin_settings, self::LLMS_TXT_FEATURE_NAME );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current status of AI Discovery features.
|
||||
* @return string
|
||||
*/
|
||||
public function status(): string {
|
||||
$plugin_settings = new PluginSettings();
|
||||
$plugin_options = $plugin_settings->get_plugin_settings();
|
||||
|
||||
$data = array(
|
||||
'llmstxt' => $plugin_options->get_enable_llms_txt(),
|
||||
'web2agent' => $plugin_options->get_optin_mcp(),
|
||||
);
|
||||
|
||||
$status = wp_json_encode( $data );
|
||||
WP_CLI::line( $status );
|
||||
return $status;
|
||||
}
|
||||
|
||||
private function set_setting_status( PluginSettings $plugin_settings, string $setting, bool $is_enabled ): void {
|
||||
$plugin_options = $plugin_settings->get_plugin_settings();
|
||||
|
||||
switch ( $setting ) {
|
||||
case self::WEB2AGENT_FEATURE_NAME:
|
||||
$plugin_options->set_optin_mcp( $is_enabled );
|
||||
break;
|
||||
case self::LLMS_TXT_FEATURE_NAME:
|
||||
$plugin_options->set_enable_llms_txt( $is_enabled );
|
||||
break;
|
||||
default:
|
||||
throw new Exception( 'Invalid setting' );
|
||||
}
|
||||
|
||||
$plugin_settings->save_plugin_settings( $plugin_options );
|
||||
$this->clear_lightspeed_cache();
|
||||
}
|
||||
|
||||
private function get_setting_status( PluginSettings $plugin_settings, string $setting ): bool {
|
||||
$plugin_options = $plugin_settings->get_plugin_settings();
|
||||
switch ( $setting ) {
|
||||
case self::WEB2AGENT_FEATURE_NAME:
|
||||
$is_enabled = $plugin_options->get_optin_mcp();
|
||||
break;
|
||||
case self::LLMS_TXT_FEATURE_NAME:
|
||||
$is_enabled = $plugin_options->get_enable_llms_txt();
|
||||
break;
|
||||
default:
|
||||
throw new Exception( 'Invalid setting' );
|
||||
}
|
||||
|
||||
$enabled = $is_enabled ? 'ENABLED' : 'DISABLED';
|
||||
|
||||
WP_CLI::success( $setting . ' ' . $enabled );
|
||||
return $is_enabled;
|
||||
}
|
||||
|
||||
private function validate_args( mixed $args ): void {
|
||||
if ( $args[0] !== '0' && $args[0] !== '1' ) {
|
||||
throw new Exception( 'Invalid argument. Use 0 or 1' );
|
||||
}
|
||||
}
|
||||
|
||||
private function clear_lightspeed_cache(): void {
|
||||
if ( has_action( 'litespeed_purge_all' ) ) {
|
||||
do_action( 'litespeed_purge_all' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Hostinger\Cli\Commands;
|
||||
|
||||
use Hostinger\Admin\PluginSettings;
|
||||
use WP_CLI;
|
||||
use Hostinger\Settings;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Maintenance {
|
||||
|
||||
public static function define_command(): void {
|
||||
if ( class_exists( '\WP_CLI' ) ) {
|
||||
WP_CLI::add_command(
|
||||
'hostinger',
|
||||
self::class,
|
||||
array(
|
||||
'shortdesc' => 'List of Hostinger commands.',
|
||||
'longdesc' => 'Available Hostinger commands:' . "\n\n" .
|
||||
' wp hostinger maintenance mode <0|1>' . "\n" .
|
||||
' Manage the maintenance mode of the site. Use 1 to enable and 0 to disable maintenance mode.' . "\n\n" .
|
||||
' wp hostinger maintenance status' . "\n" .
|
||||
' Display the current maintenance mode status.' . "\n\n" .
|
||||
'## SUBCOMMANDS' . "\n\n" .
|
||||
'* mode <0|1>' . "\n" .
|
||||
': Enable (1) or disable (0) maintenance mode.' . "\n\n" .
|
||||
'* status' . "\n" .
|
||||
': Display the current maintenance mode status.' . "\n\n" .
|
||||
'## EXAMPLES' . "\n\n" .
|
||||
' wp hostinger maintenance mode 1' . "\n" .
|
||||
' Enables the maintenance mode.' . "\n\n" .
|
||||
' wp hostinger maintenance mode 0' . "\n" .
|
||||
' Disables the maintenance mode.' . "\n\n" .
|
||||
' wp hostinger maintenance status' . "\n" .
|
||||
' Returns whether maintenance mode is enabled or disabled.' . "\n",
|
||||
)
|
||||
);
|
||||
|
||||
WP_CLI::add_command(
|
||||
'hostinger maintenance',
|
||||
self::class,
|
||||
array(
|
||||
'shortdesc' => 'Manage the maintenance mode of the site.',
|
||||
'longdesc' => 'This command allows you to enable or disable maintenance mode for the site.' . "\n\n" .
|
||||
'## OPTIONS' . "\n\n" .
|
||||
'mode <0|1>' . "\n" .
|
||||
': Enable (1) or disable (0) maintenance mode.' . "\n\n" .
|
||||
'## EXAMPLES' . "\n\n" .
|
||||
' wp hostinger maintenance mode 1' . "\n" .
|
||||
' Enables the maintenance mode.' . "\n\n" .
|
||||
' wp hostinger maintenance mode 0' . "\n" .
|
||||
' Disables the maintenance mode.' . "\n\n" .
|
||||
' wp hostinger maintenance status' . "\n" .
|
||||
' Returns whether maintenance mode is enabled or disabled.' . "\n",
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Command allows enable/disable maintenance mode.
|
||||
*
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function mode( array $args ): void {
|
||||
if ( empty( $args ) ) {
|
||||
WP_CLI::error( 'Arguments cannot be empty. Use 0 or 1' );
|
||||
}
|
||||
|
||||
$plugin_settings = new PluginSettings();
|
||||
$plugin_options = $plugin_settings->get_plugin_settings();
|
||||
|
||||
switch ( $args[0] ) {
|
||||
case '1':
|
||||
$plugin_options->set_maintenance_mode( true );
|
||||
WP_CLI::success( 'Maintenance mode ENABLED' );
|
||||
break;
|
||||
case '0':
|
||||
$plugin_options->set_maintenance_mode( false );
|
||||
WP_CLI::success( 'Maintenance mode DISABLED' );
|
||||
break;
|
||||
default:
|
||||
throw new \Exception( 'Invalid maintenance mode value' );
|
||||
}
|
||||
|
||||
$plugin_settings->save_plugin_settings( $plugin_options );
|
||||
|
||||
if ( has_action( 'litespeed_purge_all' ) ) {
|
||||
do_action( 'litespeed_purge_all' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Command return maintenance mode status.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function status(): bool {
|
||||
$plugin_settings = new PluginSettings();
|
||||
$plugin_options = $plugin_settings->get_plugin_settings();
|
||||
|
||||
if ( $plugin_options->get_maintenance_mode() ) {
|
||||
WP_CLI::success( 'Maintenance mode ENABLED' );
|
||||
} else {
|
||||
WP_CLI::success( 'Maintenance mode DISABLED' );
|
||||
}
|
||||
|
||||
return (bool) $plugin_options->get_maintenance_mode();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user