PluginProbe
Hostinger Tools / 3.0.79
Hostinger Tools v3.0.79
3.0.79 3.0.78 3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 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 All 110 releases
hostinger / includes / Activator.php

Activator.php in Hostinger Tools 3.0.79, at includes/Activator.php

55 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hostinger;
4
5 use Hostinger\Admin\PluginSettings;
6 use Hostinger\LlmsTxtGenerator\LlmsTxtFileHelper;
7 use Hostinger\LlmsTxtGenerator\LlmsTxtGenerator;
8 use Hostinger\LlmsTxtGenerator\LlmsTxtParser;
9 use Hostinger\LlmsTxtGenerator\LlmsTxtSummaryProvider;
10
11 defined( 'ABSPATH' ) || exit;
12
13 class Activator {
14 public const INSTALLATION_OPTION_NAME = 'hts_new_installation';
15
16 public static function activate(): void {
17 $plugin_settings = new PluginSettings();
18
19 $options = new DefaultOptions( $plugin_settings );
20 $options->add_options();
21
22 self::generate_llms_txt( $plugin_settings );
23 self::update_installation_state_on_activation();
24 }
25
26 /**
27 * The generator's own self-heal on `init` only runs for a logged-in administrator, so a site
28 * provisioned headlessly would serve no llms.txt until someone opened wp-admin.
29 */
30 private static function generate_llms_txt( PluginSettings $plugin_settings ): void {
31 $file_helper = new LlmsTxtFileHelper();
32
33 if ( $file_helper->llmstxt_file_exists() ) {
34 return;
35 }
36
37 $llms_txt_parser = new LlmsTxtParser( new LlmsTxtSummaryProvider() );
38 $generator = new LlmsTxtGenerator( $plugin_settings, $file_helper, $llms_txt_parser );
39 $generator->generate();
40 }
41
42 /**
43 * Saves installation state.
44 *
45 * @return void
46 */
47 public static function update_installation_state_on_activation(): void {
48 $installation_state = get_option( self::INSTALLATION_OPTION_NAME, false );
49
50 if ( $installation_state !== 'old' ) {
51 add_option( self::INSTALLATION_OPTION_NAME, 'new' );
52 }
53 }
54 }
55