class-wpseo-installation.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Internals
  6. * @since 3.6
  7. */
  8. /**
  9. * This class checks if the wpseo option doesn't exists. In the case it doesn't it will set a property that is
  10. * accessible via a method to check if the installation is fresh.
  11. */
  12. class WPSEO_Installation {
  13. /**
  14. * Checks if Yoast SEO is installed for the first time.
  15. */
  16. public function __construct() {
  17. $is_first_install = $this->is_first_install();
  18. if ( $is_first_install && WPSEO_Utils::is_api_available() ) {
  19. add_action( 'wpseo_activate', [ $this, 'set_first_install_options' ] );
  20. }
  21. }
  22. /**
  23. * When the option doesn't exist, it should be a new install.
  24. *
  25. * @return bool
  26. */
  27. private function is_first_install() {
  28. return ( get_option( 'wpseo' ) === false );
  29. }
  30. /**
  31. * Sets the options on first install for showing the installation notice and disabling of the settings pages.
  32. */
  33. public function set_first_install_options() {
  34. $options = get_option( 'wpseo' );
  35. $options['show_onboarding_notice'] = true;
  36. $options['first_activated_on'] = time();
  37. update_option( 'wpseo', $options );
  38. }
  39. }