PluginProbe ʕ •ᴥ•ʔ
Blocks Animation: CSS Animations for Gutenberg Blocks / 3.2.0
Blocks Animation: CSS Animations for Gutenberg Blocks v3.2.0
3.2.0 3.1.11 3.1.10 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 trunk 1.0.0 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4
blocks-animation / vendor / codeinwp / themeisle-sdk / src / Modules / Welcome.php
blocks-animation / vendor / codeinwp / themeisle-sdk / src / Modules Last commit date
About_us.php 1 week ago Abstract_Migration.php 1 month ago Announcements.php 1 month ago Compatibilities.php 1 year ago Dashboard_widget.php 1 week ago Featured_plugins.php 1 month ago Float_widget.php 1 year ago Licenser.php 1 month ago Logger.php 8 months ago Migrator.php 1 month ago Notification.php 1 year ago Promotions.php 1 week ago Recommendation.php 1 year ago Review.php 8 months ago Rollback.php 1 year ago Script_loader.php 8 months ago Translate.php 1 year ago Translations.php 8 months ago Uninstall_feedback.php 1 week ago Welcome.php 1 year ago
Welcome.php
195 lines
1 <?php
2 /**
3 * The welcome model class for ThemeIsle SDK
4 *
5 * Here's how to hook it in your plugin or theme:
6 * ```php
7 * add_filter( '<product_slug>_welcome_metadata', function() {
8 * return [
9 * 'is_enabled' => <condition_if_pro_available>,
10 * 'pro_name' => 'Product PRO name',
11 * 'logo' => '<path_to_logo>',
12 * 'cta_link' => tsdk_utmify( 'https://link_to_upgrade.with/?discount=<discountCode>')
13 * ];
14 * } );
15 * ```
16 *
17 * @package ThemeIsleSDK
18 * @subpackage Modules
19 * @copyright Copyright (c) 2023, Bogdan Preda
20 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
21 * @since 1.0.0
22 */
23
24 namespace ThemeisleSDK\Modules;
25
26 // Exit if accessed directly.
27 use ThemeisleSDK\Common\Abstract_Module;
28 use ThemeisleSDK\Loader;
29
30 if ( ! defined( 'ABSPATH' ) ) {
31 exit;
32 }
33
34 /**
35 * Promotions module for ThemeIsle SDK.
36 */
37 class Welcome extends Abstract_Module {
38
39 /**
40 * Debug mode.
41 *
42 * @var bool
43 */
44 private $debug = false;
45
46 /**
47 * Welcome metadata.
48 *
49 * @var array
50 */
51 private $welcome_discounts = array();
52
53 /**
54 * Check that we can load this module.
55 *
56 * @param \ThemeisleSDK\Product $product The product.
57 *
58 * @return bool
59 */
60 public function can_load( $product ) {
61 $this->debug = apply_filters( 'themeisle_sdk_welcome_debug', $this->debug );
62 $welcome_metadata = apply_filters( $product->get_key() . '_welcome_metadata', array() );
63
64 $is_welcome_enabled = $this->is_welcome_meta_valid( $welcome_metadata );
65
66 if ( $is_welcome_enabled ) {
67 $this->welcome_discounts[ $product->get_key() ] = $welcome_metadata;
68 }
69
70 return $this->debug || $is_welcome_enabled;
71 }
72
73 /**
74 * Check that the metadata is valid and the welcome is enabled.
75 *
76 * @param array $welcome_metadata The metadata to validate.
77 *
78 * @return bool
79 */
80 private function is_welcome_meta_valid( $welcome_metadata ) {
81 return ! empty( $welcome_metadata ) && isset( $welcome_metadata['is_enabled'] ) && $welcome_metadata['is_enabled'];
82 }
83
84 /**
85 * Load the module.
86 *
87 * @param \ThemeisleSDK\Product $product The product.
88 *
89 * @return $this
90 */
91 public function load( $product ) {
92 if ( ! current_user_can( 'install_plugins' ) ) {
93 return;
94 }
95
96 $this->product = $product;
97 if ( ! $this->is_time_to_show_welcome() && $this->debug === false ) {
98 return;
99 }
100
101 add_filter( 'themeisle_sdk_registered_notifications', [ $this, 'add_notification' ], 99, 1 );
102
103 return $this;
104 }
105
106 /**
107 * Check if it's time to show the welcome.
108 *
109 * @return bool
110 */
111 private function is_time_to_show_welcome() {
112 // if 7 days from install have not passed, don't show the welcome.
113 if ( $this->product->get_install_time() + 7 * DAY_IN_SECONDS > time() ) {
114 return false;
115 }
116
117 // if 12 days from install have passed, don't show the welcome ( after 7 days for 5 days ).
118 if ( $this->product->get_install_time() + 12 * DAY_IN_SECONDS < time() ) {
119 return false;
120 }
121
122 return true;
123 }
124
125 /**
126 * Add the welcome notification.
127 * Will block all other notifications if a welcome notification is present.
128 *
129 * @return array
130 */
131 public function add_notification( $all_notifications ) {
132 if ( empty( $this->welcome_discounts ) ) {
133 return $all_notifications;
134 }
135
136 if ( ! isset( $this->welcome_discounts[ $this->product->get_key() ] ) ) {
137 return $all_notifications;
138 }
139
140 // filter out the notifications that are not welcome upsells
141 // if we arrived here we will have at least one welcome upsell
142 $all_notifications = array_filter(
143 $all_notifications,
144 function ( $notification ) {
145 return strpos( $notification['id'], '_welcome_upsell_flag' ) !== false;
146 }
147 );
148
149 $offer = $this->welcome_discounts[ $this->product->get_key() ];
150
151 $response = [];
152 $logo = isset( $offer['logo'] ) ? $offer['logo'] : '';
153 $pro_name = isset( $offer['pro_name'] ) ? $offer['pro_name'] : $this->product->get_friendly_name() . ' PRO';
154
155 $link = $offer['cta_link'];
156
157 $message = apply_filters( $this->product->get_key() . '_welcome_upsell_message', Loader::$labels['welcome']['message'] );
158
159 $button_submit = apply_filters( $this->product->get_key() . '_feedback_review_button_do', Loader::$labels['welcome']['ctay'] );
160 $button_cancel = apply_filters( $this->product->get_key() . '_feedback_review_button_cancel', Loader::$labels['welcome']['ctan'] );
161 $message = str_replace(
162 [ '{product}', '{pro_product}', '{cta_link}' ],
163 [
164 $this->product->get_friendly_name(),
165 $pro_name,
166 $link,
167 ],
168 $message
169 );
170
171 $all_notifications[] = [
172 'id' => $this->product->get_key() . '_welcome_upsell_flag',
173 'message' => $message,
174 'img_src' => $logo,
175 'ctas' => [
176 'confirm' => [
177 'link' => $link,
178 'text' => $button_submit,
179 ],
180 'cancel' => [
181 'link' => '#',
182 'text' => $button_cancel,
183 ],
184 ],
185 'type' => 'info',
186 ];
187
188 $key = array_rand( $all_notifications );
189 $response[] = $all_notifications[ $key ];
190
191 return $response;
192 }
193
194 }
195