WPSEO_OnPage_Option

This class handles the data for the option where the OnPage.org data is stored.

Defined (1)

The class is defined in the following location(s).

/admin/onpage/class-onpage-option.php  
  1. class WPSEO_OnPage_Option { 
  2.  
  3. const NOT_FETCHED = 99; 
  4. const IS_INDEXABLE = 1; 
  5. const IS_NOT_INDEXABLE = 0; 
  6. const CANNOT_FETCH = -1; 
  7.  
  8. /** 
  9. * The name of the option where data will be stored 
  10. */ 
  11. const OPTION_NAME = 'wpseo_onpage'; 
  12.  
  13. /** 
  14. * The key of the status in the option 
  15. */ 
  16. const STATUS = 'status'; 
  17.  
  18. /** 
  19. * The key of the last fetch date in the option. 
  20. */ 
  21. const LAST_FETCH = 'last_fetch'; 
  22.  
  23. /** 
  24. * The limit for fetching the status manually. 
  25. */ 
  26. const FETCH_LIMIT = 15; 
  27.  
  28. /** 
  29. * @var array The OnPage.org option stored in the database. 
  30. */ 
  31. private $onpage_option; 
  32.  
  33. /** 
  34. * Setting the object by setting the properties 
  35. */ 
  36. public function __construct() { 
  37. $this->onpage_option = $this->get_option(); 
  38.  
  39. /** 
  40. * Getting the status from the option. 
  41. * @return string 
  42. */ 
  43. public function get_status() { 
  44. if ( array_key_exists( self::STATUS, $this->onpage_option ) ) { 
  45. return $this->onpage_option[ self::STATUS ]; 
  46.  
  47. return self::CANNOT_FETCH; 
  48.  
  49. /** 
  50. * Saving the status to the options. 
  51. * @param string $status The status to save. 
  52. */ 
  53. public function set_status( $status ) { 
  54. $this->onpage_option[ self::STATUS ] = $status; 
  55.  
  56. /** 
  57. * Saving the last fetch timestamp to the options. 
  58. * @param integer $timestamp Timestamp with the new value. 
  59. */ 
  60. public function set_last_fetch( $timestamp ) { 
  61. $this->onpage_option[ self::LAST_FETCH ] = $timestamp; 
  62.  
  63. /** 
  64. * Check if the last fetch is within the time of 60 minutes 
  65. * @return bool 
  66. */ 
  67. public function should_be_fetched() { 
  68. return ( ( time() - $this->onpage_option[ self::LAST_FETCH ] ) > self::FETCH_LIMIT ); 
  69.  
  70. /** 
  71. * Saving the option with the current data 
  72. */ 
  73. public function save_option() { 
  74. update_option( self::OPTION_NAME, $this->onpage_option ); 
  75.  
  76. /** 
  77. * Returns the value of the onpage_enabled status 
  78. * @return bool 
  79. */ 
  80. public function is_enabled() { 
  81. $options = get_option( 'wpseo' ); 
  82.  
  83. return ! empty( $options['onpage_indexability'] ); 
  84.  
  85. /** 
  86. * Getting the option with the OnPage.org data 
  87. * @return array 
  88. */ 
  89. private function get_option() { 
  90. return get_option( self::OPTION_NAME, array( self::STATUS => self::NOT_FETCHED, self::LAST_FETCH => 0 ) ); 
  91.  
  92. /** 
  93. * @deprecated 3.0.2 
  94. * @codeCoverageIgnore 
  95. * Returns the indexable status of the website. 
  96. * @return bool 
  97. */ 
  98. public function is_indexable() { 
  99. _deprecated_function( __METHOD__, 'WPSEO 3.0.2' ); 
  100.  
  101. return self::IS_INDEXABLE === $this->get_status();