WPSEO_Product_Upsell_Notice

Represents the upsell notice.

Defined (1)

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

/admin/class-product-upsell-notice.php  
  1. class WPSEO_Product_Upsell_Notice { 
  2.  
  3. const USER_META_DISMISSED = 'wpseo-remove-upsell-notice'; 
  4.  
  5. const OPTION_NAME = 'wpseo'; 
  6.  
  7. /** @var array */ 
  8. protected $options; 
  9.  
  10. /** 
  11. * Sets the options, because they always have to be there on instance. 
  12. */ 
  13. public function __construct() { 
  14. $this->options = $this->get_options(); 
  15.  
  16. /** 
  17. * Checks if the notice should be added or removed. 
  18. */ 
  19. public function initialize() { 
  20. if ( $this->is_notice_dismissed() ) { 
  21. $this->remove_notification(); 
  22.  
  23. return; 
  24.  
  25. if ( $this->should_add_notification() ) { 
  26. $this->add_notification(); 
  27.  
  28. /** 
  29. * Sets the upgrade notice. 
  30. */ 
  31. public function set_upgrade_notice() { 
  32.  
  33. if ( $this->has_first_activated_on() ) { 
  34. return; 
  35.  
  36. $this->set_first_activated_on(); 
  37. $this->add_notification(); 
  38.  
  39. /** 
  40. * Listener for the upsell notice. 
  41. */ 
  42. public function dismiss_notice_listener() { 
  43. if ( filter_input( INPUT_GET, 'yoast_dismiss' ) !== 'upsell' ) { 
  44. return; 
  45.  
  46. $this->dismiss_notice(); 
  47.  
  48. wp_redirect( admin_url( 'admin.php?page=wpseo_dashboard' ) ); 
  49. exit; 
  50.  
  51. /** 
  52. * When the notice should be shown. 
  53. * @return bool 
  54. */ 
  55. protected function should_add_notification() { 
  56. return ( $this->options['first_activated_on'] < strtotime( '-2weeks' ) ); 
  57.  
  58. /** 
  59. * Checks if the options has a first activated on date value. 
  60. */ 
  61. protected function has_first_activated_on() { 
  62. return $this->options['first_activated_on'] !== false; 
  63.  
  64. /** 
  65. * Sets the first activated on. 
  66. */ 
  67. protected function set_first_activated_on() { 
  68. $this->options['first_activated_on'] = strtotime( '-2weeks' ); 
  69.  
  70. $this->save_options(); 
  71.  
  72. /** 
  73. * Adds a notification to the notification center. 
  74. */ 
  75. protected function add_notification() { 
  76. $notification_center = Yoast_Notification_Center::get(); 
  77. $notification_center->add_notification( $this->get_notification() ); 
  78.  
  79. /** 
  80. * Adds a notification to the notification center. 
  81. */ 
  82. protected function remove_notification() { 
  83. $notification_center = Yoast_Notification_Center::get(); 
  84. $notification_center->remove_notification( $this->get_notification() ); 
  85.  
  86. /** 
  87. * Returns a premium upsell section if using the free plugin. 
  88. * @return string 
  89. */ 
  90. protected function get_premium_upsell_section() { 
  91. $features = new WPSEO_Features(); 
  92. if ( $features->is_free() ) { 
  93. return sprintf( 
  94. /** translators: %1$s expands anchor to premium plugin page, %2$s expands to </a> */ 
  95. __( 'By the way, did you know we also have a %1$sPremium plugin%2$s? It offers advanced features, like a redirect manager and support for multiple keywords. It also comes with 24/7 personal support.' , 'wordpress-seo' ),  
  96. "<a href='" . WPSEO_Shortlinker::get( 'https://yoa.st/premium-notification' ) . "'>",  
  97. '</a>' 
  98. ); 
  99.  
  100. return ''; 
  101.  
  102. /** 
  103. * Gets the notification value. 
  104. * @return Yoast_Notification 
  105. */ 
  106. protected function get_notification() { 
  107. $message = sprintf( 
  108. /** translators: %1$s expands to Yoast SEO, %2$s is a link start tag to the plugin page on WordPress.org, %3$s is the link closing tag. */ 
  109. __( 'We\'ve noticed you\'ve been using %1$s for some time now; we hope you love it! We\'d be thrilled if you could %2$sgive us a 5 stars rating on WordPress.org%3$s!', 'wordpress-seo' ),  
  110. 'Yoast SEO',  
  111. '<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/rate-yoast-seo' ) . '">',  
  112. '</a>' 
  113. ) . "\n\n"; 
  114.  
  115. $message .= sprintf( 
  116. /** translators: %1$s is a link start tag to the bugreport guidelines on the Yoast knowledge base, %2$s is the link closing tag. */ 
  117. __( 'If you are experiencing issues, %1$splease file a bug report%2$s and we\'ll do our best to help you out.', 'wordpress-seo' ),  
  118. '<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/bugreport' ) . '">',  
  119. '</a>' 
  120. ) . "\n\n"; 
  121.  
  122. $message .= $this->get_premium_upsell_section() . "\n\n"; 
  123.  
  124. $message .= sprintf( 
  125. /** translators: %1$s is the notification dismissal link start tag, %2$s is the link closing tag. */ 
  126. __( '%1$sPlease don\'t show me this notification anymore%2$s', 'wordpress-seo' ),  
  127. '<a class="button" href="' . admin_url( '?page=' . WPSEO_Admin::PAGE_IDENTIFIER . '&yoast_dismiss=upsell' ) . '">',  
  128. '</a>' 
  129. ); 
  130.  
  131. $notification = new Yoast_Notification( 
  132. $message,  
  133. array( 
  134. 'type' => Yoast_Notification::WARNING,  
  135. 'id' => 'wpseo-upsell-notice',  
  136. 'capabilities' => 'manage_options',  
  137. 'priority' => 0.8,  
  138. ); 
  139.  
  140. return $notification; 
  141.  
  142. /** 
  143. * Dismisses the notice. 
  144. * @return string 
  145. */ 
  146. protected function is_notice_dismissed() { 
  147. return get_user_meta( get_current_user_id(), self::USER_META_DISMISSED, true ) === '1'; 
  148.  
  149. /** 
  150. * Dismisses the notice. 
  151. */ 
  152. protected function dismiss_notice() { 
  153. update_user_meta( get_current_user_id(), self::USER_META_DISMISSED, true ); 
  154.  
  155. /** 
  156. * Returns the set options 
  157. * @return mixed|void 
  158. */ 
  159. protected function get_options() { 
  160. return get_option( self::OPTION_NAME ); 
  161.  
  162. /** 
  163. * Saves the options to the database. 
  164. */ 
  165. protected function save_options() { 
  166. update_option( self::OPTION_NAME, $this->options );