PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / inc / options / class-wpseo-option-llmstxt.php

class-wpseo-option-llmstxt.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at inc/options/class-wpseo-option-llmstxt.php

126 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Internals\Options
6 */
7
8 /**
9 * Option: wpseo_llmstxt.
10 */
11 class WPSEO_Option_Llmstxt extends WPSEO_Option {
12
13 private const OTHER_INCLUDED_PAGES_LIMIT = 100;
14
15 /**
16 * Option name.
17 *
18 * @var string
19 */
20 public $option_name = 'wpseo_llmstxt';
21
22 /**
23 * Array of defaults for the option.
24 *
25 * Shouldn't be requested directly, use $this->get_defaults();
26 *
27 * @var array<string, int|string|array<int>>
28 */
29 protected $defaults = [
30 'llms_txt_selection_mode' => 'auto',
31 'about_us_page' => 0,
32 'contact_page' => 0,
33 'terms_page' => 0,
34 'privacy_policy_page' => 0,
35 'shop_page' => 0,
36 'other_included_pages' => [],
37 ];
38
39 /**
40 * Get the singleton instance of this class.
41 *
42 * @return object
43 */
44 public static function get_instance() {
45 if ( ! ( self::$instance instanceof self ) ) {
46 self::$instance = new self();
47 }
48
49 return self::$instance;
50 }
51
52 /**
53 * All concrete classes must contain a validate_option() method which validates all
54 * values within the option.
55 *
56 * @param array $dirty New value for the option.
57 * @param array $clean Clean value for the option, normally the defaults.
58 * @param array $old Old value of the option.
59 *
60 * @return array The clean option with the saved value.
61 */
62 protected function validate_option( $dirty, $clean, $old ) {
63
64 foreach ( $clean as $key => $value ) {
65 switch ( $key ) {
66 case 'other_included_pages':
67 if ( isset( $dirty[ $key ] ) ) {
68 $items = $dirty[ $key ];
69 if ( ! is_array( $items ) ) {
70 $items = json_decode( $dirty[ $key ], true );
71 }
72
73 if ( is_array( $items ) ) {
74 $items = array_slice( $items, 0, $this->get_other_included_pages_limit() );
75 foreach ( $items as $item ) {
76 $validated_id = WPSEO_Utils::validate_int( $item );
77
78 if ( $validated_id === false || $validated_id === 0 ) {
79 continue;
80 }
81
82 $clean[ $key ][] = $validated_id;
83 }
84 }
85 }
86
87 break;
88 case 'about_us_page':
89 case 'contact_page':
90 case 'terms_page':
91 case 'privacy_policy_page':
92 case 'shop_page':
93 if ( isset( $dirty[ $key ] ) ) {
94 $int = WPSEO_Utils::validate_int( $dirty[ $key ] );
95 if ( $int !== false && $int >= 0 ) {
96 $clean[ $key ] = $int;
97 }
98 }
99 elseif ( isset( $old[ $key ] ) ) {
100 $int = WPSEO_Utils::validate_int( $old[ $key ] );
101 if ( $int !== false && $int >= 0 ) {
102 $clean[ $key ] = $int;
103 }
104 }
105 break;
106 case 'llms_txt_selection_mode':
107 if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], [ 'auto', 'manual' ], true ) ) {
108 $clean[ $key ] = $dirty[ $key ];
109 }
110 break;
111 }
112 }
113
114 return $clean;
115 }
116
117 /**
118 * Gets the limit for the other included pages.
119 *
120 * @return int The limit for the other included pages.
121 */
122 public function get_other_included_pages_limit() {
123 return self::OTHER_INCLUDED_PAGES_LIMIT;
124 }
125 }
126