PluginProbe
MyRewards / trunk
MyRewards vtrunk
5.7.8 5.7.7 5.7.6 trunk 1.2.2 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.1 2.2.0 2.3.0 2.4.0 2.4.1 2.5.0 2.6.4 2.6.6 3.0.0.0 3.1.0 3.1.2 3.1.2.1 3.10.4 3.10.9 All 165 releases
woorewards / woorewards.php

woorewards.php in MyRewards trunk, at woorewards.php

646 lines 24.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: MyRewards
5 * Description: Improve your customers experience with Rewards, Levels and Achievements. Use it with WooCommerce to set up a loyalty program.
6 * Plugin URI: https://plugins.longwatchstudio.com/product/woorewards/
7 * Author: Long Watch Studio
8 * Author URI: https://longwatchstudio.com
9 * Version: 5.7.8
10 * License: GPLv2 or later
11 * Text Domain: woorewards-lite
12 * Domain Path: /languages
13 * WC requires at least: 7.3.0
14 * WC tested up to: 10.9
15 *
16 *
17 */
18
19
20 // don't call the file directly
21 if (!defined('ABSPATH')) exit();
22
23 /** That class holds the entire plugin. */
24 final class LWS_WooRewards
25 {
26
27 public static function init()
28 {
29 static $instance = false;
30 if (!$instance) {
31 $instance = new self();
32 $instance->defineConstants();
33 \add_action('after_setup_theme', function() {
34 // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound, WordPress.WP.DeprecatedParameters.Load_plugin_textdomainParam2Found
35 \load_plugin_textdomain('woorewards-lite', false, \plugin_basename(\dirname(__FILE__)) . '/languages/');
36 });
37
38 \add_action('before_woocommerce_init', function() { // HPOS support
39 if (\class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
40 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
41 }
42 });
43
44 \add_action('lws_adminpanel_register', array($instance, 'register'));
45
46 if (\is_admin()) {
47 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($instance, 'extensionListActions'), 10, 2);
48 add_filter('lws_adminpanel_purchase_url_woorewards', array($instance, 'addPurchaseUrl'), 10, 1);
49 add_filter('lws_adm_trialend_msg', array($instance, 'getTrialEndMessage'), 10, 4);
50 add_filter('lws_adm_trialstart_msg', array($instance, 'getTrialStartMessage'), 10, 3);
51 foreach (array('', '.customers', '.loyalty', '.settings') as $page)
52 add_filter('lws_adminpanel_plugin_version_' . LWS_WOOREWARDS_PAGE . $page, array($instance, 'addPluginVersion'), 10, 1);
53 add_filter('lws_adminpanel_documentation_url_woorewards', array($instance, 'addDocUrl'), 10, 1);
54
55 if (!(defined('DOING_AJAX') && DOING_AJAX)) {
56 require_once LWS_WOOREWARDS_INCLUDES . '/updater.php';
57 // piority as soon as possible, But sad bug from WP.
58 // Trying to get property of non-object in ./wp-includes/post.php near line 3917: $feeds = $wp_rewrite->feeds;
59 // cannot do it sooner.
60 add_action('setup_theme', array('\LWS\WOOREWARDS\Updater', 'checkUpdate'), -100);
61 add_action('setup_theme', array($instance, 'forceVisitLicencePage'), 0);
62 }
63 }
64
65 add_action('lws_woorewards_daily_event', function () {
66 \update_option('lws_woorewards_last_cron_time', \time());
67 });
68
69 $instance->install();
70
71 register_activation_hook(__FILE__, 'LWS_WooRewards::activation');
72 }
73 return $instance;
74 }
75
76 function forceVisitLicencePage()
77 {
78 if (\get_option('lws_woorewards_redirect_to_licence', 0) > 0) {
79 $page = array('page' => LWS_WOOREWARDS_PAGE);
80 if (defined('LWS_WIZARD_SUMMONER')) {
81 $page = array('page' => LWS_WIZARD_SUMMONER . LWS_WOOREWARDS_PAGE);
82 }
83 $page = \apply_filters('lws_woorewards_redirect_after_install_url', $page);
84 \update_option('lws_woorewards_redirect_to_licence', 0);
85
86 if ($page) {
87 $exit = \wp_safe_redirect(\add_query_arg($page, admin_url('admin.php')));
88 if ($exit)
89 exit;
90 }
91 }
92 }
93
94 public function v()
95 {
96 static $version = '';
97 if (empty($version)) {
98 if (!function_exists('get_plugin_data')) require_once(ABSPATH . 'wp-admin/includes/plugin.php');
99 $data = \get_plugin_data(__FILE__, false, false);
100 $version = (isset($data['Version']) ? $data['Version'] : '0');
101 }
102 return $version;
103 }
104
105 /**
106 * Define the plugin constants
107 *
108 * @return void
109 */
110 private function defineConstants()
111 {
112 define('LWS_WOOREWARDS_VERSION', '5.7.8');
113 define('LWS_WOOREWARDS_FILE', __FILE__);
114 define('LWS_WOOREWARDS_DOMAIN', 'woorewards-lite');
115 define('LWS_WOOREWARDS_PAGE', 'woorewards');
116 define('LWS_WOOREWARDS_UUID', '072f0512659060939ec5047e24ef2be3');
117
118 define('LWS_WOOREWARDS_PATH', dirname(LWS_WOOREWARDS_FILE));
119 define('LWS_WOOREWARDS_INCLUDES', LWS_WOOREWARDS_PATH . '/include');
120 define('LWS_WOOREWARDS_SNIPPETS', LWS_WOOREWARDS_PATH . '/snippets');
121 define('LWS_WOOREWARDS_ASSETS', LWS_WOOREWARDS_PATH . '/assets');
122
123 define('LWS_WOOREWARDS_URL', plugins_url('', LWS_WOOREWARDS_FILE));
124 define('LWS_WOOREWARDS_JS', plugins_url('/js', LWS_WOOREWARDS_FILE));
125 define('LWS_WOOREWARDS_CSS', plugins_url('/styling/css', LWS_WOOREWARDS_FILE));
126 define('LWS_WOOREWARDS_IMG', plugins_url('/img', LWS_WOOREWARDS_FILE));
127
128 global $wpdb;
129 $wpdb->lwsWooRewardsHistoric = $wpdb->base_prefix . 'lws_wr_historic';
130 }
131
132 public function extensionListActions($links, $file)
133 {
134 $label = __('Settings', 'woorewards-lite');
135 $url = add_query_arg(array('page' => LWS_WOOREWARDS_PAGE . '.loyalty'), admin_url('admin.php'));
136 array_unshift($links, "<a href='$url'>$label</a>");
137 $label = __('Help', 'woorewards-lite');
138 $url = esc_attr($this->addDocUrl(''));
139 $links[] = "<a href='$url'>$label</a>";
140 return $links;
141 }
142
143 public function addPurchaseUrl($url)
144 {
145 return __("https://plugins.longwatchstudio.com/product/woorewards/", 'woorewards-lite');
146 }
147
148 public function addPluginVersion($url)
149 {
150 return '5.7.8';
151 }
152
153 public function addDocUrl($url)
154 {
155 return \LWS\WOOREWARDS\DocLinks::get('home');
156 }
157
158 function register()
159 {
160 require_once LWS_WOOREWARDS_INCLUDES . '/ui/admin.php';
161 new \LWS\WOOREWARDS\Ui\Admin();
162 }
163
164 /** Add elements we need on this plugin to work
165 * Run once at activation */
166 public static function activation()
167 {
168 require_once dirname(__FILE__) . '/include/updater.php';
169 \LWS\WOOREWARDS\Updater::activate();
170 self::setupCron();
171 }
172
173 public static function setupCron()
174 {
175 $hook = 'lws_woorewards_daily_event';
176 if (\wp_next_scheduled($hook)) // allows reset on re-activation
177 \wp_clear_scheduled_hook($hook);
178
179 $d = \date_create('now', self::getSiteTimezone())->setTime(0, 0);
180 $d->add(new \DateInterval('P1D')); // start tomorow
181
182 $ref = \intval(\get_option($hook . '_reference_hour', '1')); // prefer 1am by default
183 if ($ref) {
184 $shift = new \DateInterval('PT' . \abs($ref) . 'H');
185 if ($ref > 0) $d->add($shift);
186 else $d->sub($shift);
187 }
188
189 \wp_schedule_event(
190 $d->getTimestamp(),
191 \apply_filters('lws_woorewards_main_event_period', 'daily'),
192 $hook
193 );
194 }
195
196 /** autoload WooRewards core and collection classes. */
197 public function autoload($class)
198 {
199 if (substr($class, 0, 15) == 'LWS\WOOREWARDS\\') {
200 $rest = substr($class, 15);
201 $publicNamespaces = array(
202 'Collections', 'Abstracts', 'Core', 'Unlockables', 'Events',
203 );
204 $publicClasses = array(
205 'Ui\Editlists\MultiFormList',
206 'Ui\Editlists\EventList', 'Ui\Editlists\UnlockableList',
207 'Wizard', 'Wizards\Subwizard', 'Ui\Widget',
208 );
209
210 if (in_array(explode('\\', $rest, 2)[0], $publicNamespaces) || in_array($rest, $publicClasses)) {
211 $basename = str_replace('\\', '/', strtolower($rest));
212 $filepath = LWS_WOOREWARDS_INCLUDES . '/' . $basename . '.php';
213 @include_once $filepath;
214 return true;
215 }
216 }
217 }
218
219 /** @deprecated use \LWS\Adminpanel\Tools\Conveniences::isWC() instead. */
220 static public function isWC($false = false)
221 {
222 return function_exists('wc');
223 }
224
225 /** If another name/symbol should be used instead of point.
226 * @param int $count to return singular or plural form. */
227 static public function getPointSymbol($count = 1, $poolName = '')
228 {
229 $sym = \apply_filters('lws_woorewards_point_symbol_translation', false, $count, $poolName);
230 if ($sym === false) // default symbol
231 {
232 $sym = (\apply_filters('lws_woorewards_should_use_singular', 1 === (int)$count, $count) ? __("Point", 'woorewards-lite') : __("Points", 'woorewards-lite'));
233 }
234 return $sym;
235 }
236
237 static public function formatPointsWithSymbol($points, $poolName)
238 {
239 $sym = self::getPointSymbol($points, $poolName);
240 return \apply_filters('lws_woorewards_point_with_symbol_format', sprintf("%s %s", $points, $sym), $points, $sym, $poolName);
241 }
242
243 static public function formatPoints($points, $poolName)
244 {
245 return \apply_filters('lws_woorewards_point_format', $points, $points, $poolName);
246 }
247
248 static public function symbolFilter($symbol = '', $count = 1, $poolName = '')
249 {
250 return self::getPointSymbol($count, $poolName);
251 }
252
253 public function blocksLoaded()
254 {
255 require_once LWS_WOOREWARDS_INCLUDES . '/ui/blocks/integration.php';
256 require_once LWS_WOOREWARDS_INCLUDES . '/ui/blocks/extension.php';
257
258 \add_action('woocommerce_blocks_cart_block_registration', function($integration_registry) {
259 $integration_registry->register(new \LWS\WOOREWARDS\Ui\Blocks\Integration());
260 });
261 \add_action('woocommerce_blocks_checkout_block_registration', function($integration_registry) {
262 $integration_registry->register(new \LWS\WOOREWARDS\Ui\Blocks\Integration());
263 });
264 \LWS\WOOREWARDS\Ui\Blocks\Extension::install();
265 }
266
267 /** Take care WP_Post manipulation is hazardous before hook 'setup_theme' (since global $wp_rewrite is not already set) */
268 private function install()
269 {
270 spl_autoload_register(array($this, 'autoload'));
271 \add_filter('lws_woorewards_point_symbol', array(__CLASS__, 'symbolFilter'), 10, 3);
272 // include obviously required classes
273 require_once LWS_WOOREWARDS_INCLUDES . '/doclinks.php';
274 require_once LWS_WOOREWARDS_INCLUDES . '/conveniencies.php';
275 require_once LWS_WOOREWARDS_INCLUDES . '/abstracts/icategorisable.php';
276 require_once LWS_WOOREWARDS_INCLUDES . '/abstracts/iregistrable.php';
277 require_once LWS_WOOREWARDS_INCLUDES . '/abstracts/collection.php';
278 require_once LWS_WOOREWARDS_INCLUDES . '/abstracts/unlockable.php';
279 require_once LWS_WOOREWARDS_INCLUDES . '/abstracts/event.php';
280 require_once LWS_WOOREWARDS_INCLUDES . '/core/pointstack.php';
281 require_once LWS_WOOREWARDS_INCLUDES . '/core/pool.php';
282
283 require_once LWS_WOOREWARDS_INCLUDES . '/core/sponsorship.php';
284 \LWS\WOOREWARDS\Core\Sponsorship::register();
285 require_once LWS_WOOREWARDS_INCLUDES . '/ui/shortcodes/referrallink.php';
286 \LWS\WOOREWARDS\Ui\ShortCodes\ReferralLink::install();
287
288 // register events and unlockables
289 require_once LWS_WOOREWARDS_INCLUDES . '/registration.php';
290
291 \add_action('init', function() {
292 \add_image_size('lws_wr_thumbnail', 96, 96);
293 \add_image_size('lws_wr_thumbnail_small', 42, 42);
294 });
295 \add_filter('image_size_names_choose', function ($sizes) {
296 return array_merge($sizes, array(
297 'lws_wr_thumbnail' => __("MyRewards Thumbnail", 'woorewards-lite'),
298 'lws_wr_thumbnail_small' => __("MyRewards Thumbnail Small", 'woorewards-lite')
299 ));
300 });
301
302 \add_filter('lws_adminpanel_wizards', function ($wizards) {
303 $wizards[LWS_WOOREWARDS_PAGE] = '\LWS\WOOREWARDS\Wizard';
304 return $wizards;
305 });
306
307 // anyway, load all pools and install configured events. Do it as soon as possible but let anywho to hook before.
308 \add_action('setup_theme', array(__CLASS__, 'installPool'));
309 \add_action('init', array($this, 'registerPostTypes'));
310
311 \add_filter('lws_woorewards_order_events', array($this, 'getOrderValidationStates'));
312
313 \LWS\WOOREWARDS\Conveniences::install();
314 require_once LWS_WOOREWARDS_INCLUDES . '/options.php';
315 new \LWS\WOOREWARDS\Options();
316 require_once LWS_WOOREWARDS_INCLUDES . '/ui/achievement.php';
317 new \LWS\WOOREWARDS\Ui\Achievement();
318 require_once LWS_WOOREWARDS_INCLUDES . '/core/ajax.php';
319 new \LWS\WOOREWARDS\Core\Ajax();
320 require_once LWS_WOOREWARDS_INCLUDES . '/unlockables/coupon.php';
321 \LWS\WOOREWARDS\Unlockables\Coupon::addUiFilters();
322
323 // Shortcodes
324 require_once LWS_WOOREWARDS_INCLUDES . '/ui/shortcodes/pointsbalance.php';
325 \LWS\WOOREWARDS\Ui\Shortcodes\PointsBalance::install();
326 require_once LWS_WOOREWARDS_INCLUDES . '/ui/shortcodes/availablecoupons.php';
327 \LWS\WOOREWARDS\Ui\Shortcodes\AvailableCoupons::install();
328 require_once LWS_WOOREWARDS_INCLUDES . '/ui/shortcodes/pointsvalue.php';
329 \LWS\WOOREWARDS\Ui\Shortcodes\PointsValue::install();
330 require_once LWS_WOOREWARDS_INCLUDES . '/ui/shortcodes/userpointshistory.php';
331 \LWS\WOOREWARDS\Ui\Shortcodes\UserPointsHistory::install();
332
333 require_once LWS_WOOREWARDS_INCLUDES . '/pointdiscount.php';
334 \LWS\WOOREWARDS\PointDiscount::install();
335
336 require_once LWS_WOOREWARDS_INCLUDES . '/ui/widget.php';
337 if (\LWS\WOOREWARDS\Conveniences::instance()->isLegacyShown('4.7.0')) {
338 require_once LWS_WOOREWARDS_INCLUDES . '/ui/legacy/pointsdisplayer.php';
339 \LWS\WOOREWARDS\Ui\Legacy\PointsDisplayer::install();
340 }
341
342 // WooCommerce
343 require_once LWS_WOOREWARDS_INCLUDES . '/ui/woocommerce/pointsoncart.php';
344 \LWS\WOOREWARDS\Ui\Woocommerce\PointsOnCart::install();
345 require_once LWS_WOOREWARDS_INCLUDES . '/ui/woocommerce/cartcheckoutcontent.php';
346 \LWS\WOOREWARDS\Ui\Woocommerce\CartCheckoutContent::install();
347 require_once LWS_WOOREWARDS_INCLUDES . '/core/ordernote.php';
348 \LWS\WOOREWARDS\Core\OrderNote::install();
349 require_once LWS_WOOREWARDS_INCLUDES . '/ui/woocommerce/ordernote.php';
350 \LWS\WOOREWARDS\Ui\Woocommerce\OrderNote::install();
351 require_once LWS_WOOREWARDS_INCLUDES . '/ui/woocommerce/ordersbulk.php';
352 \LWS\WOOREWARDS\Ui\Woocommerce\OrdersBulk::install();
353
354 // blocks
355 \add_action('woocommerce_blocks_loaded', [$this, 'blocksLoaded']);
356 \add_action('block_categories_all', function($categories) {
357 return \array_merge($categories, [[
358 'slug' => 'lws-wr-blocks',
359 'title' => __("WooRewards Blocks", 'woorewards-lite'),
360 ]]);
361 }, 10, 2);
362
363 // Email template
364 require_once LWS_WOOREWARDS_INCLUDES . '/mails/newreward.php';
365 new \LWS\WOOREWARDS\Mails\NewReward();
366
367 // Compatibility Classes
368 \add_action('plugins_loaded', function () {
369 if (\class_exists('UM')) {
370 require_once LWS_WOOREWARDS_INCLUDES . '/compatibility/ultimatemember.php';
371 \LWS\WOOREWARDS\Compatibility\UltimateMember::install();
372 }
373 });
374
375 // styling
376 \add_action('wp_enqueue_scripts', array($this, 'enqueueGlobalStyles'));
377 \add_action('admin_enqueue_scripts', array($this, 'enqueueGlobalStyles'));
378 \add_action('wp_head', function() {
379 require_once LWS_WOOREWARDS_INCLUDES . '/ui/adminscreens/styling.php';
380 if ($style = \LWS\WOOREWARDS\Ui\AdminScreens\Styling::getInline())
381 echo wp_kses($style, [
382 'style' => [
383 'id' => true,
384 'type' => true,
385 'media' => true,
386 ],
387 ]);
388 });
389
390 // hide some meta from admin
391 if (\get_option('lws_woorewards_hide_internal_meta', 'on')) {
392 \add_action('is_protected_meta', function($protected, $key, $type) {
393 if (!$protected && 'post' == $type && 'lws_' == \substr($key, 0, 4)) {
394 if ('lws_woorewards_core_pool-' == \substr($key, 0, 25))
395 $protected = true;
396 elseif ('lws_woorewards_points_refunded' == $key)
397 $protected = true;
398 }
399 return $protected;
400 }, 10, 3);
401 }
402
403 // import/export
404 require_once LWS_WOOREWARDS_INCLUDES . '/pointsflow/action.php';
405 \LWS\WOOREWARDS\PointsFlow\Action::register();
406
407 if ('fr' === \substr((string)\get_locale(), 0, 2)) {
408 \add_filter('lws_woorewards_should_use_singular', function($yes, $count) {
409 return \is_numeric($count) && 1 >= \abs((int)$count);
410 }, 10, 2);
411 }
412
413 \do_action('lws_woorewards_init');
414 }
415
416 function enqueueGlobalStyles()
417 {
418 \wp_enqueue_style('wr-frontend-elements', LWS_WOOREWARDS_CSS . '/wr-elements.min.css', array(), LWS_WOOREWARDS_VERSION);
419 }
420
421 function getOrderValidationStates($status)
422 {
423 $status = \get_option('lws_woorewards_points_distribution_status', false);
424 if (false === $status) {
425 // legacy
426 $status = array('processing', 'completed');
427 if (\get_option('lws_woorewards_coupon_state', false)) // checked: Points on 'Complete' order only
428 $status = array('completed');
429 } else if ($status && !\is_array($status)) {
430 $status = array('processing', 'completed');
431 }
432 return ($status && \is_array($status)) ? $status : array();
433 }
434
435 function registerPostTypes()
436 {
437 \register_post_type(\LWS\WOOREWARDS\Core\Pool::POST_TYPE, array(
438 'show_in_rest' => true,
439 'hierarchical' => true,
440 'labels' => array(
441 'name' => __("Loyalty Systems", 'woorewards-lite'),
442 'singular_name' => __("Loyalty System", 'woorewards-lite')
443 ),
444 'supports' => array('title', 'custom-fields'),
445 ));
446 \register_post_type(\LWS\WOOREWARDS\Abstracts\Event::POST_TYPE, array(
447 'show_in_rest' => true,
448 'hierarchical' => true,
449 'labels' => array(
450 'name' => __("Earning Points Methods", 'woorewards-lite'),
451 'singular_name' => __("Earning Points Method", 'woorewards-lite')
452 ),
453 'supports' => array('title', 'custom-fields'),
454 ));
455 \register_post_type(\LWS\WOOREWARDS\Abstracts\Unlockable::POST_TYPE, array(
456 'show_in_rest' => true,
457 'hierarchical' => true,
458 'labels' => array(
459 'name' => __("Rewards", 'woorewards-lite'),
460 'singular_name' => __("Reward", 'woorewards-lite')
461 ),
462 'supports' => array('title', 'custom-fields'),
463 ));
464
465 $metas = \apply_filters('lws_woorewards_register_custom_post_metas', array(
466 \LWS\WOOREWARDS\Core\Pool::POST_TYPE => array(
467 'wre_pool_direct_reward_point_rate' => true,
468 ),
469 ));
470 foreach ($metas as $type => $meta) {
471 foreach ($meta as $key => $single) {
472 \register_meta('post', $key, array(
473 'object_subtype' => $type,
474 'show_in_rest' => true,
475 'single' => $single,
476 ));
477 }
478 }
479 }
480
481 static function installPool()
482 {
483 $pools = self::getPrefabPools()->install();
484 self::getInstalledPool($pools->first());
485 \do_action('lws_woorewards_pools_loaded', $pools);
486 }
487
488 static function getPrefabPools($enabledOnly=true)
489 {
490 $args = array(
491 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- required for pool identification
492 array(
493 'key' => 'wre_pool_prefab',
494 'value' => 'yes',
495 'compare' => 'LIKE'
496 ),
497 array(
498 'key' => 'wre_pool_type',
499 'value' => \LWS\WOOREWARDS\Core\Pool::T_STANDARD,
500 'compare' => 'LIKE'
501 )
502 )
503 );
504 if ($enabledOnly)
505 $args['post_status'] = array('publish', 'private');
506 return \LWS\WOOREWARDS\Collections\Pools::instanciate()->load($args);
507 }
508
509 static function getInstalledPool($_pool=false)
510 {
511 static $save = false;
512 if ($_pool)
513 $save = $_pool;
514 return $save;
515 }
516
517 /** Should be called inside an admin_notice hook.
518 * Call only if a premium was installed but plugin downgraded to free. */
519 function testPoolCompletion()
520 {
521 require_once LWS_WOOREWARDS_INCLUDES . '/updater.php';
522 if (current_user_can('manage_options') && \LWS\WOOREWARDS\Updater::isMissingPrefabEventsAndUnlockables()) {
523 echo "<div class='notice notice-error lws-adminpanel-notice is-dismissible'><p>";
524 echo "<form id='lws-wr-missing-form' name='lws-wr-missing-form' method='post'>";
525 \wp_nonce_field('lws-wr-missing-form', 'lws-wr-missing-nonce', true, true);
526 echo "<input type='hidden' name='lws-wr-missing-restore' value='restore'/>";
527 esc_html_e("We detect a MyRewards licence downgrade: Click here to restore missing configuration.", 'woorewards-lite');
528 echo "<input type='submit' value='" . esc_attr(__("Restore", 'woorewards-lite')) . "' class='lws-adm-btn lws-wr-missing-restore-submit'/>";
529 echo "</form></p></div>";
530 }
531 }
532
533 /** is pool completion requested, then do it @see \LWS\WOOREWARDS\Updater::addMissingPrefabEventsAndUnlockables */
534 function parseQueryForPoolCompletion()
535 {
536 $formId = 'lws-wr-missing-form';
537 if (
538 isset($_POST['lws-wr-missing-restore']) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
539 && 'restore' === \sanitize_text_field(\wp_unslash($_POST['lws-wr-missing-restore'])) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
540 && isset($_POST['lws-wr-missing-nonce']) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
541 && \wp_verify_nonce(\sanitize_text_field(\wp_unslash($_POST['lws-wr-missing-nonce'])), $formId) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
542 && \check_admin_referer($formId, 'lws-wr-missing-nonce')
543 && current_user_can('manage_options')
544 ) {
545 require_once LWS_WOOREWARDS_INCLUDES . '/updater.php';
546 \LWS\WOOREWARDS\Updater::addMissingPrefabEventsAndUnlockables();
547 }
548 }
549
550 /** Display an achievement on the page (backend or frontend).
551 * $param options (array)
552 * or an array for custom achievement widget with:
553 * * 'title' (string) At least a title is required for custom achievement.
554 * * 'message' (string) optional, display a custom achievement with that message.
555 * * 'image' (url) Achievement icon, if no url given, a default image is picked.
556 * * 'user' (int) recipient user id.
557 * * 'origin' (mixed, optional) source of the achievement. */
558 public static function achievement($options = array())
559 {
560 require_once LWS_WOOREWARDS_INCLUDES . '/ui/achievement.php';
561 \LWS\WOOREWARDS\Ui\Achievement::push($options);
562 }
563
564 /** That usefull function exists since 5.3
565 * But we keep a 4.9 compatibility. */
566 static function getSiteTimezone()
567 {
568 if (function_exists('wp_timezone'))
569 return \wp_timezone();
570 else
571 return new \DateTimeZone(self::getSiteTimezoneString());
572 }
573
574 /** That usefull function exists since 5.3
575 * But we keep a 4.9 compatibility. */
576 static function getSiteTimezoneString()
577 {
578 if (function_exists('wp_timezone_string'))
579 return \wp_timezone_string();
580
581 $timezone_string = get_option('timezone_string');
582
583 if ($timezone_string) {
584 return $timezone_string;
585 }
586
587 $offset = (float) get_option('gmt_offset');
588 $hours = (int) $offset;
589 $minutes = ($offset - $hours);
590
591 $sign = ($offset < 0) ? '-' : '+';
592 $abs_hour = abs($hours);
593 $abs_mins = abs($minutes * 60);
594 $tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins);
595
596 return $tz_offset;
597 }
598
599 function getTrialEndMessage($msg, $slug, $date, $link)
600 {
601 if ('woorewards' != $slug)
602 return $msg;
603 $msg = "<h2>" . __('Your MyRewards Premium trial period is about to expire', 'woorewards-lite') . "</h2>";
604 /* translators: %s: trial end date */
605 $msg .= "<p>" . sprintf(__('Thank you for trying MyRewards Premium. The trial period will end on <b>%s</b>', 'woorewards-lite'), $date) . "</p>";
606 /* translators: %s: purchase link */
607 $msg .= "<h4><b>" . sprintf(__('If you want to keep using all Pro Features, please purchase a %s License', 'woorewards-lite'), $link) . "</b></h4>";
608 $msg .= "<p>" . __('Premium Version features include :', 'woorewards-lite') . "</p>";
609 $msg .= "<ul style='list-style-type:square;padding-left:20px;'><li>" . __('Referrals', 'woorewards-lite') . "</li>";
610 $msg .= "<li>" . __('Free products rewards', 'woorewards-lite') . "</li>";
611 $msg .= "<li>" . __('WooCommerce integration tools', 'woorewards-lite') . "</li>";
612 $msg .= "<li>" . __('Multiple points and rewards systems', 'woorewards-lite') . "</li>";
613 $msg .= "<li>" . __('Lots of widgets and shortcodes', 'woorewards-lite') . "</li>";
614 $msg .= "<li>" . __('And a lot more ...', 'woorewards-lite') . "</li>";
615 $msg .= "</ul>";
616 $msg .= "<p>" . __('Purchase WooRewads Premium today to keep the most powerful and customizable loyalty program', 'woorewards-lite') . "</p>";
617 return $msg;
618 }
619
620 function getTrialStartMessage($msg, $slug, $date)
621 {
622 if ('woorewards' != $slug)
623 return $msg;
624 $msg = "<h2>" . __('Welcome to your MyRewards Premium trial', 'woorewards-lite') . "</h2>";
625 /* translators: %s: trial end date */
626 $msg .= "<p>" . sprintf(__('Thank you for trying MyRewards Premium. The trial period will end on <b>%s</b>', 'woorewards-lite'), $date) . "</p>";
627 $msg .= "<p>" . __('Premium Version features include :', 'woorewards-lite') . "</p>";
628 $msg .= "<ul style='list-style-type:square;padding-left:20px;'><li>" . __('Referrals', 'woorewards-lite') . "</li>";
629 $msg .= "<li>" . __('Free products rewards', 'woorewards-lite') . "</li>";
630 $msg .= "<li>" . __('WooCommerce integration tools', 'woorewards-lite') . "</li>";
631 $msg .= "<li>" . __('Multiple points and rewards systems', 'woorewards-lite') . "</li>";
632 $msg .= "<li>" . __('Lots of widgets and shortcodes', 'woorewards-lite') . "</li>";
633 $msg .= "<li>" . __('And a lot more ...', 'woorewards-lite') . "</li>";
634 $msg .= "</ul>";
635 $msg .= "<p>" . __('Try all these premium features and create the perfect loyalty program for your website', 'woorewards-lite') . "</p>";
636 $msg .= "<h4><b>" . __('At the end of your trial, consider purchasing a MyRewards License', 'woorewards-lite') . "</b></h4>";
637 return $msg;
638 }
639 }
640
641 LWS_WooRewards::init(); {
642 if (\file_exists($asset = (dirname(__FILE__) . '/assets/lws-adminpanel/lws-adminpanel.php')))
643 include_once $asset;
644 if (\file_exists($asset = (dirname(__FILE__) . '/modules/woorewards-pro/woorewards-pro.php')))
645 include_once $asset;
646 }