ryte_option = $this->get_option(); } /** * Getting the status from the option. * * @return integer|string */ public function get_status() { if ( array_key_exists( self::STATUS, $this->ryte_option ) ) { return $this->ryte_option[ self::STATUS ]; } return self::CANNOT_FETCH; } /** * Saving the status to the options. * * @param string $status The status to save. */ public function set_status( $status ) { $this->ryte_option[ self::STATUS ] = $status; } /** * Saving the last fetch timestamp to the options. * * @param int $timestamp Timestamp with the new value. */ public function set_last_fetch( $timestamp ) { $this->ryte_option[ self::LAST_FETCH ] = $timestamp; } /** * Determines whether the indexability status should be fetched. * * If LAST_FETCH isn't set, we assume the indexability status hasn't been fetched * yet and return true. Then, we check whether the last fetch is within the * FETCH_LIMIT time interval (15 seconds) to avoid too many consecutive API calls. * * @return bool Whether the indexability status should be fetched. */ public function should_be_fetched() { if ( ! isset( $this->ryte_option[ self::LAST_FETCH ] ) ) { return true; } return ( ( time() - $this->ryte_option[ self::LAST_FETCH ] ) > self::FETCH_LIMIT ); } /** * Saving the option with the current data. */ public function save_option() { update_option( self::OPTION_NAME, $this->ryte_option ); } /** * Returns the value of the onpage_enabled status. * * @return bool */ public function is_enabled() { return WPSEO_Options::get( 'ryte_indexability' ); } /** * Getting the option with the Ryte data. * * @return array */ private function get_option() { $default = [ self::STATUS => self::NOT_FETCHED, self::LAST_FETCH => 0, ]; return get_option( self::OPTION_NAME, $default ); } }