class-premium-popup.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Class WPSEO_Premium_popup.
  9. */
  10. class WPSEO_Premium_Popup {
  11. /**
  12. * An unique identifier for the popup
  13. *
  14. * @var string
  15. */
  16. private $identifier = '';
  17. /**
  18. * The heading level of the title of the popup.
  19. *
  20. * @var String
  21. */
  22. private $heading_level = '';
  23. /**
  24. * The title of the popup.
  25. *
  26. * @var String
  27. */
  28. private $title = '';
  29. /**
  30. * The content of the popup.
  31. *
  32. * @var String
  33. */
  34. private $content = '';
  35. /**
  36. * The URL for where the button should link to.
  37. *
  38. * @var String
  39. */
  40. private $url = '';
  41. /**
  42. * Wpseo_Premium_Popup constructor.
  43. *
  44. * @param String $identifier An unique identifier for the popup.
  45. * @param String $heading_level The heading level for the title of the popup.
  46. * @param String $title The title of the popup.
  47. * @param String $content The content of the popup.
  48. * @param String $url The URL for where the button should link to.
  49. */
  50. public function __construct( $identifier, $heading_level, $title, $content, $url ) {
  51. $this->identifier = $identifier;
  52. $this->heading_level = $heading_level;
  53. $this->title = $title;
  54. $this->content = $content;
  55. $this->url = $url;
  56. }
  57. /**
  58. * Returns the premium popup as an HTML string.
  59. *
  60. * @param bool $popup Show this message as a popup show it straight away.
  61. *
  62. * @return string
  63. */
  64. public function get_premium_message( $popup = true ) {
  65. // Don't show in Premium.
  66. if ( defined( 'WPSEO_PREMIUM_FILE' ) ) {
  67. return '';
  68. }
  69. $assets_uri = trailingslashit( plugin_dir_url( WPSEO_FILE ) );
  70. /* translators: %s expands to Yoast SEO Premium */
  71. $cta_text = esc_html( sprintf( __( 'Get %s', 'wordpress-seo' ), 'Yoast SEO Premium' ) );
  72. $new_tab_message = '<span class="screen-reader-text">' . esc_html__( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>';
  73. $caret_icon = '<span aria-hidden="true" class="yoast-button-upsell__caret"></span>';
  74. $classes = '';
  75. if ( $popup ) {
  76. $classes = ' hidden';
  77. }
  78. $micro_copy = __( '1 year free support and updates included!', 'wordpress-seo' );
  79. $popup = <<<EO_POPUP
  80. <div id="wpseo-{$this->identifier}-popup" class="wpseo-premium-popup wp-clearfix$classes">
  81. <img class="alignright wpseo-premium-popup-icon" src="{$assets_uri}images/Yoast_SEO_Icon.svg" width="150" height="150" alt="Yoast SEO"/>
  82. <{$this->heading_level} id="wpseo-contact-support-popup-title" class="wpseo-premium-popup-title">{$this->title}</{$this->heading_level}>
  83. {$this->content}
  84. <a id="wpseo-{$this->identifier}-popup-button" class="yoast-button-upsell" href="{$this->url}" target="_blank">
  85. {$cta_text} {$new_tab_message} {$caret_icon}
  86. </a><br/>
  87. <small>{$micro_copy}</small>
  88. </div>
  89. EO_POPUP;
  90. return $popup;
  91. }
  92. }