PluginProbe ʕ •ᴥ•ʔ
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.0
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 19.1 19.10 19.11 19.12 19.13 19.14 19.2 19.3 19.4 19.5 19.5.1 19.6 19.6.1 19.7 19.7.1 19.7.2 19.8 19.9 20.0 20.1 20.10 20.11 20.12 20.13 20.2 20.2.1 20.3 20.4 20.5 20.6 20.7 20.8 20.9 21.0 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 21.8.1 21.9 21.9.1 22.0 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 22.9 23.0 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 24.0 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 24.8.1 24.9 25.0 25.1 25.2 25.3 25.3.1 25.4 25.5 25.6 25.7 25.8 25.9 26.0 26.1 26.1.1 26.2 26.3 26.4 26.5 26.6 26.7 26.8 26.9 27.0 27.1 27.1.1 27.2 27.3 27.4
wordpress-seo / admin / ryte / class-ryte-option.php
wordpress-seo / admin / ryte Last commit date
class-ryte-option.php 5 years ago class-ryte-request.php 5 years ago class-ryte.php 5 years ago
class-ryte-option.php
161 lines
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * This class handles the data for the option where the Ryte data is stored.
10 */
11 class WPSEO_Ryte_Option {
12
13 /**
14 * Indicates the data is not fetched.
15 *
16 * @var int
17 */
18 const NOT_FETCHED = 99;
19
20 /**
21 * Indicates the option is indexable.
22 *
23 * @var int
24 */
25 const IS_INDEXABLE = 1;
26
27 /**
28 * Indicates the option is not indexable.
29 *
30 * @var int
31 */
32 const IS_NOT_INDEXABLE = 0;
33
34 /**
35 * Indicates the data could not be fetched.
36 *
37 * @var int
38 */
39 const CANNOT_FETCH = -1;
40
41 /**
42 * The name of the option where data will be stored.
43 *
44 * @var string
45 */
46 const OPTION_NAME = 'wpseo_ryte';
47
48 /**
49 * The key of the status in the option.
50 *
51 * @var string
52 */
53 const STATUS = 'status';
54
55 /**
56 * The key of the last fetch date in the option.
57 *
58 * @var string
59 */
60 const LAST_FETCH = 'last_fetch';
61
62 /**
63 * The limit for fetching the status manually.
64 *
65 * @var int
66 */
67 const FETCH_LIMIT = 15;
68
69 /**
70 * The Ryte option stored in the database.
71 *
72 * @var array
73 */
74 private $ryte_option;
75
76 /**
77 * Setting the object by setting the properties.
78 */
79 public function __construct() {
80 $this->ryte_option = $this->get_option();
81 }
82
83 /**
84 * Getting the status from the option.
85 *
86 * @return string
87 */
88 public function get_status() {
89 if ( array_key_exists( self::STATUS, $this->ryte_option ) ) {
90 return $this->ryte_option[ self::STATUS ];
91 }
92
93 return self::CANNOT_FETCH;
94 }
95
96 /**
97 * Saving the status to the options.
98 *
99 * @param string $status The status to save.
100 */
101 public function set_status( $status ) {
102 $this->ryte_option[ self::STATUS ] = $status;
103 }
104
105 /**
106 * Saving the last fetch timestamp to the options.
107 *
108 * @param int $timestamp Timestamp with the new value.
109 */
110 public function set_last_fetch( $timestamp ) {
111 $this->ryte_option[ self::LAST_FETCH ] = $timestamp;
112 }
113
114 /**
115 * Determines whether the indexability status should be fetched.
116 *
117 * If LAST_FETCH isn't set, we assume the indexability status hasn't been fetched
118 * yet and return true. Then, we check whether the last fetch is within the
119 * FETCH_LIMIT time interval (15 seconds) to avoid too many consecutive API calls.
120 *
121 * @return bool Whether the indexability status should be fetched.
122 */
123 public function should_be_fetched() {
124 if ( ! isset( $this->ryte_option[ self::LAST_FETCH ] ) ) {
125 return true;
126 }
127
128 return ( ( time() - $this->ryte_option[ self::LAST_FETCH ] ) > self::FETCH_LIMIT );
129 }
130
131 /**
132 * Saving the option with the current data.
133 */
134 public function save_option() {
135 update_option( self::OPTION_NAME, $this->ryte_option );
136 }
137
138 /**
139 * Returns the value of the onpage_enabled status.
140 *
141 * @return bool
142 */
143 public function is_enabled() {
144 return WPSEO_Options::get( 'ryte_indexability' );
145 }
146
147 /**
148 * Getting the option with the Ryte data.
149 *
150 * @return array
151 */
152 private function get_option() {
153 $default = [
154 self::STATUS => self::NOT_FETCHED,
155 self::LAST_FETCH => 0,
156 ];
157
158 return get_option( self::OPTION_NAME, $default );
159 }
160 }
161