暫無描述

Upsell.php 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * Handles displaying promotional text throughout plugin UI
  4. */
  5. class PUM_Upsell {
  6. /**
  7. * Hooks any needed methods
  8. */
  9. public static function init() {
  10. add_filter( 'views_edit-popup', array( __CLASS__, 'addon_tabs' ), 10, 1 );
  11. add_filter( 'views_edit-popup_theme', array( __CLASS__, 'addon_tabs' ), 10, 1 );
  12. add_filter( 'pum_popup_settings_fields', array( __CLASS__, 'popup_promotional_fields' ) );
  13. add_filter( 'pum_theme_settings_fields', array( __CLASS__, 'theme_promotional_fields' ) );
  14. add_action( 'in_admin_header', array( __CLASS__, 'notice_bar_display' ) );
  15. }
  16. /**
  17. * Adds a small notice bar in PM admin areas when not using any extensions
  18. *
  19. * @since 1.14.0
  20. */
  21. public static function notice_bar_display() {
  22. if ( pum_is_all_popups_page() && 0 === count( pum_enabled_extensions() ) ) {
  23. $message = sprintf(
  24. /* translators: %s - Wraps ending in link to pricing page. */
  25. esc_html__( 'You are using the free version of Popup Maker. To get even more value, consider %1$supgrading to our premium plans%2$s.', 'popup-maker' ),
  26. '<a href="https://wppopupmaker.com/pricing/?utm_source=upsell-notice-bar&utm_medium=text-link&utm_campaign=upsell" target="_blank" rel="noopener noreferrer">',
  27. '</a>'
  28. );
  29. ?>
  30. <div class="pum-notice-bar-wrapper">
  31. <div class="pum-notice-bar">
  32. <span class="pum-notice-bar-message">
  33. <?php
  34. echo wp_kses(
  35. $message,
  36. array(
  37. 'a' => array(
  38. 'href' => array(),
  39. 'rel' => array(),
  40. 'target' => array(),
  41. ),
  42. )
  43. );
  44. ?>
  45. </span>
  46. </div>
  47. </div>
  48. <?php
  49. }
  50. }
  51. /**
  52. * Adds messages throughout Popup Settings UI
  53. *
  54. * @param array $tabs The tabs/fields for popup settings.
  55. * @return array
  56. */
  57. public static function popup_promotional_fields( $tabs = array() ) {
  58. if ( ! pum_extension_enabled( 'forced-interaction' ) ) {
  59. /* translators: %s url to product page. */
  60. $message = sprintf( __( 'Want to disable the close button? Check out <a href="%s" target="_blank">Forced Interaction</a>!', 'popup-maker' ), 'https://wppopupmaker.com/extensions/forced-interaction/?utm_source=plugin-theme-editor&utm_medium=text-link&utm_campaign=upsell&utm_content=close-button-settings' );
  61. $tabs['close']['button']['fi_promotion'] = $tabs['close']['forms']['fi_promotion'] = $tabs['close']['alternate_methods']['fi_promotion'] = array(
  62. 'type' => 'html',
  63. 'content' => '<img src="' . pum_asset_url( 'images/upsell-icon-forced-interaction.png' ) . '" />' . $message,
  64. 'priority' => 999,
  65. 'class' => 'pum-upgrade-tip',
  66. );
  67. }
  68. if ( ! pum_extension_enabled( 'advanced-targeting-conditions' ) ) {
  69. /* translators: %s url to product page. */
  70. $message = sprintf( __( 'Need more <a href="%s" target="_blank">advanced targeting</a> options?', 'popup-maker' ), 'https://wppopupmaker.com/extensions/advanced-targeting-conditions/?utm_campaign=upsell&utm_source=plugin-popup-editor&utm_medium=text-link&utm_content=conditions-editor' );
  71. $tabs['targeting']['main']['atc_promotion'] = array(
  72. 'type' => 'html',
  73. 'content' => '<img src="' . pum_asset_url( 'images/logo.png' ) . '" height="28" />' . $message,
  74. 'priority' => 999,
  75. 'class' => 'pum-upgrade-tip',
  76. );
  77. }
  78. return $tabs;
  79. }
  80. /**
  81. * Adds messages throughout Popup Theme UI
  82. *
  83. * @param array $tabs The tabs/fields for popup theme.
  84. * @return array
  85. */
  86. public static function theme_promotional_fields( $tabs = array() ) {
  87. if ( ! pum_extension_enabled( 'advanced-theme-builder' ) && ! class_exists( 'PUM_ATB' ) ) {
  88. foreach ( array( 'overlay', 'container', 'close' ) as $tab ) {
  89. /* translators: %s url to product page. */
  90. $message = __( 'Want to use <a href="%s" target="_blank">background images</a>?', 'popup-maker' );
  91. $tabs[ $tab ]['background']['atc_promotion'] = array(
  92. 'type' => 'html',
  93. 'content' => '<img src="' . pum_asset_url( 'images/upsell-icon-advanted-theme-builder.png' ) . '" height="28" />' . sprintf( $message, 'https://wppopupmaker.com/extensions/advanced-theme-builder/?utm_campaign=upsell&utm_source=plugin-theme-editor&utm_medium=text-link&utm_content=' . $tab . '-settings' ),
  94. 'priority' => 999,
  95. 'class' => 'pum-upgrade-tip',
  96. );
  97. }
  98. }
  99. return $tabs;
  100. }
  101. /**
  102. * When the Popup or Popup Theme list table loads, call the function to view our tabs.
  103. *
  104. * @since 1.8.0
  105. * @param array $views An array of available list table views.
  106. * @return mixed
  107. */
  108. public static function addon_tabs( $views ) {
  109. self::display_addon_tabs();
  110. return $views;
  111. }
  112. /**
  113. * Displays the tabs for 'Popups', 'Popup Themes' and 'Extensions and Integrations'
  114. *
  115. * @since 1.8.0
  116. */
  117. public static function display_addon_tabs() {
  118. $popup_labels = PUM_Types::post_type_labels( __( 'Popup', 'popup-maker' ), __( 'Popups', 'popup-maker' ) );
  119. $theme_labels = PUM_Types::post_type_labels( __( 'Popup Theme', 'popup-maker' ), __( 'Popup Themes', 'popup-maker' ) );
  120. ?>
  121. <style>
  122. .wrap h1.wp-heading-inline + a.page-title-action {
  123. display: none;
  124. }
  125. .edit-php.post-type-popup .wrap .nav-tab-wrapper .page-title-action, .edit-php.post-type-popup_theme .wrap .nav-tab-wrapper .page-title-action, .popup_page_pum-extensions .wrap .nav-tab-wrapper .page-title-action {
  126. top: 7px;
  127. margin-left: 5px
  128. }
  129. @media only screen and (min-width: 0px) and (max-width: 783px) {
  130. .edit-php.post-type-popup .wrap .nav-tab-wrapper .page-title-action, .edit-php.post-type-popup_theme .wrap .nav-tab-wrapper .page-title-action, .popup_page_pum-extensions .wrap .nav-tab-wrapper .page-title-action {
  131. display: none !important
  132. }
  133. }
  134. </style>
  135. <nav class="nav-tab-wrapper">
  136. <?php
  137. $tabs = array(
  138. 'popups' => array(
  139. 'name' => esc_html( $popup_labels['name'] ),
  140. 'url' => admin_url( 'edit.php?post_type=popup' ),
  141. ),
  142. 'themes' => array(
  143. 'name' => esc_html( $theme_labels['name'] ),
  144. 'url' => admin_url( 'edit.php?post_type=popup_theme' ),
  145. ),
  146. 'integrations' => array(
  147. 'name' => esc_html__( 'Upgrade', 'popup-maker' ),
  148. 'url' => admin_url( 'edit.php?post_type=popup&page=pum-extensions&view=integrations' ),
  149. ),
  150. );
  151. $tabs = apply_filters( 'pum_add_ons_tabs', $tabs );
  152. $active_tab = false;
  153. // Calculate which tab is currently active.
  154. if ( isset( $_GET['page'] ) && $_GET['page'] === 'pum-extensions' ) {
  155. $active_tab = 'integrations';
  156. } elseif ( ! isset( $_GET['page'] ) && isset( $_GET['post_type'] ) ) {
  157. switch ( $_GET['post_type'] ) {
  158. case 'popup':
  159. $active_tab = 'popups';
  160. break;
  161. case 'popup_theme':
  162. $active_tab = 'themes';
  163. break;
  164. }
  165. }
  166. // Add each tab, marking the current one as active.
  167. foreach ( $tabs as $tab_id => $tab ) {
  168. $active = $active_tab === $tab_id ? ' nav-tab-active' : '';
  169. ?>
  170. <a href="<?php echo esc_url( $tab['url'] ); ?>" class="nav-tab<?php echo esc_attr( $active ); ?>">
  171. <?php echo $tab['name']; ?>
  172. </a>
  173. <?php
  174. }
  175. ?>
  176. <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=popup' ) ); ?>" class="page-title-action">
  177. <?php echo esc_html( $popup_labels['add_new_item'] ); ?>
  178. </a>
  179. <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=popup_theme' ) ); ?>" class="page-title-action">
  180. <?php echo esc_html( $theme_labels['add_new_item'] ); ?>
  181. </a>
  182. </nav>
  183. <?php
  184. }
  185. }