Changeset 3253191
- Timestamp:
- 03/10/2025 09:25:50 AM (13 months ago)
- Location:
- woorewards/trunk
- Files:
-
- 1 added
- 10 edited
-
assets/lws-adminpanel/include/pages/field/input.php (modified) (1 diff)
-
assets/lws-adminpanel/include/pages/head.php (modified) (2 diffs)
-
assets/lws-adminpanel/include/tools/conveniences.php (modified) (1 diff)
-
assets/lws-adminpanel/include/tools/dates.php (added)
-
assets/lws-adminpanel/include/tools/request.php (modified) (1 diff)
-
assets/lws-adminpanel/lws-adminpanel.php (modified) (2 diffs)
-
include/conveniencies.php (modified) (1 diff)
-
include/ui/admin.php (modified) (7 diffs)
-
include/ui/shortcodes/availablecoupons.php (modified) (5 diffs)
-
readme.txt (modified) (3 diffs)
-
woorewards.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woorewards/trunk/assets/lws-adminpanel/include/pages/field/input.php
r3188612 r3253191 44 44 $others = $this->getDomAttributes(); 45 45 46 return "<input name='$name' value='$value'$attrs{$others}$id$size>"; 46 $datalist = ''; 47 if (isset($this->extra['datalist']) && $this->extra['datalist']) { 48 if (!($this->extra['list_id'] ?? false)) { 49 static $unicifier = 0; 50 $this->extra['list_id'] = \md5(\serialize($this->extra['datalist'])) . '_' . ($unicifier++); 51 } 52 if (\is_array($this->extra['datalist'])) { 53 $datalist = sprintf('<datalist id="%s">', \esc_attr($this->extra['list_id'])); 54 foreach ($this->extra['datalist'] as $label) { 55 $datalist .= sprintf('<option value="%s"%s>', \esc_attr((string)$label), $value === $label ? ' selected' : ''); 56 } 57 $datalist .= '</datalist>'; 58 } else { 59 $datalist = $this->extra['datalist']; 60 } 61 } 62 if ($this->extra['list_id'] ?? false) { 63 $attrs .= sprintf(' list="%s"', \esc_attr($this->extra['list_id'])); 64 } 65 66 return "<input name='$name' value='$value'$attrs{$others}$id$size>" . $datalist; 47 67 } 48 68 } -
woorewards/trunk/assets/lws-adminpanel/include/pages/head.php
r3234695 r3253191 178 178 'id' => $level->getId(), 179 179 'title' => $level->getPageTitle(), 180 'url' => $level->getLink($tabPath),180 'url' => \apply_filters('lws_adminpanel_breadcrums_particle_url', $level->getLink($tabPath), $level), 181 181 'siblings' => array(), 182 182 ); … … 185 185 'id' => $level['id'], 186 186 'title' => $level['title'], 187 'url' => $this->page->getLink($tabPath),187 'url' => \apply_filters('lws_adminpanel_breadcrums_particle_url', $this->page->getLink($tabPath), $level), 188 188 'siblings' => array(), 189 189 ); -
woorewards/trunk/assets/lws-adminpanel/include/tools/conveniences.php
r3234695 r3253191 660 660 \add_action($hook, $callable, $priority); 661 661 } 662 663 /** @return string the associated capability if the current user role is in the given array $roles, 664 * or fallback on $capability. */ 665 public static function getCapOnRole($capability, array $roles = ['administrator' => 'manage_options']): string 666 { 667 $user = \wp_get_current_user(); 668 if ($user) { 669 if (!$roles) $roles = ['administrator' => 'manage_options']; 670 $cross = \array_intersect_key($roles, \array_fill_keys((array)$user->roles, true)); 671 if ($cross) { 672 return (string)\reset($cross); 673 } 674 } 675 return (string)($capability ?? 'manage_options'); 676 } 677 678 /** @param $roles array of array [role => [capability]] */ 679 public static function updateRolesCapabilities(array $roles) 680 { 681 foreach ($roles as $slug => $caps) { 682 $role = \get_role($slug); 683 if (!$role) continue; 684 foreach ($caps as $cap) { 685 if (!$role->has_cap($cap)) $role->add_cap($cap); 686 } 687 } 688 } 662 689 } -
woorewards/trunk/assets/lws-adminpanel/include/tools/request.php
r3234695 r3253191 287 287 } 288 288 289 $ret = $wpdb->query($sql); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPressDotOrg.sniffs.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL.NotPrepared 290 return $ret ? $wpdb->insert_id : false; 289 return $wpdb->query($sql); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPressDotOrg.sniffs.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL.NotPrepared 291 290 } 292 291 -
woorewards/trunk/assets/lws-adminpanel/lws-adminpanel.php
r3234695 r3253191 6 6 * Author: Long Watch Studio 7 7 * Author URI: https://longwatchstudio.com 8 * Version: 5.5.1 68 * Version: 5.5.18 9 9 * Text Domain: lws-adminpanel 10 10 * … … 58 58 59 59 add_filter('lws_adminpanel_versions', function($versions){ 60 $versions['5.5.1 6'] = __FILE__;60 $versions['5.5.18'] = __FILE__; 61 61 return $versions; 62 62 }); -
woorewards/trunk/include/conveniencies.php
r3227529 r3253191 69 69 70 70 /* Get Available WooCommerce coupons for the provided user */ 71 public function getCoupons($userId )71 public function getCoupons($userId, $where=false) 72 72 { 73 73 $user = \get_user_by('ID', $userId); 74 if (empty($user->user_email)) 75 return array(); 76 $todayDate = strtotime(date('Y-m-d')); 74 if (!$user->user_email) return []; 75 77 76 global $wpdb; 78 $query = <<<EOT 79 SELECT p.ID, p.post_content, p.post_title, p.post_excerpt, e.meta_value AS expiry_date 80 FROM {$wpdb->posts} as p 81 INNER JOIN {$wpdb->postmeta} as m ON p.ID = m.post_id AND m.meta_key='customer_email' 82 LEFT JOIN {$wpdb->postmeta} as l ON p.ID = l.post_id AND l.meta_key='usage_limit' 83 LEFT JOIN {$wpdb->postmeta} as u ON p.ID = u.post_id AND u.meta_key='usage_count' 84 LEFT JOIN {$wpdb->postmeta} as e ON p.ID = e.post_id AND e.meta_key='date_expires' 85 WHERE m.meta_value=%s AND post_type = 'shop_coupon' AND post_status = 'publish' 86 AND (e.meta_value is NULL OR e.meta_value = '' OR e.meta_value >= '{$todayDate}') 87 AND (u.meta_value < l.meta_value OR u.meta_value IS NULL OR l.meta_value IS NULL OR l.meta_value=0) 88 EOT; 89 $result = $wpdb->get_results($wpdb->prepare($query, serialize(array($user->user_email))), OBJECT_K); 90 if (empty($result)) 91 return $result; 77 $query = \LWS\Adminpanel\Tools\Request::from($wpdb->posts, 'p'); 78 $query->select(['p.ID', 'p.post_content', 'p.post_title', 'p.post_excerpt', 'MAX(e.meta_value) AS expiry_date']); 79 $query->group('p.ID'); 80 $query->innerJoin($wpdb->postmeta, 'm', ["p.ID = m.post_id AND m.meta_key='customer_email'"]); 81 $query->leftJoin($wpdb->postmeta, 'l', ["l.post_id = m.post_id AND l.meta_key='usage_limit'"]); 82 $query->leftJoin($wpdb->postmeta, 'u', ["u.post_id = m.post_id AND u.meta_key='usage_count'"]); 83 $query->leftJoin($wpdb->postmeta, 'e', ["e.post_id = m.post_id AND e.meta_key='date_expires'"]); 84 $query->where([ 85 "m.meta_value = %s", 86 "post_type = 'shop_coupon'", 87 "post_status = 'publish'", 88 "(e.meta_value is NULL OR e.meta_value = '' OR e.meta_value >= %s)", 89 "(u.meta_value < l.meta_value OR u.meta_value IS NULL OR l.meta_value IS NULL OR l.meta_value=0)", 90 ]); 91 $query->arg(\serialize([$user->user_email])); 92 $query->arg(\strtotime(\date('Y-m-d'))); 93 if ($where) { 94 $query->where($where); 95 } 96 97 $result = $query->getResults(OBJECT_K); 98 if (!$result) return []; 92 99 93 100 $ids = implode(",", array_map('intval', array_keys($result))); -
woorewards/trunk/include/ui/admin.php
r3188612 r3253191 174 174 'title' => __("MyRewards", 'woorewards-lite'), 175 175 'id' => LWS_WOOREWARDS_PAGE, 176 'rights' => 'manage_rewards',176 'rights' => \LWS\Adminpanel\Tools\Conveniences::getCapOnRole('manage_rewards'), 177 177 'dashicons' => '', 178 178 'index' => 57, … … 207 207 'title' => __("Customers", 'woorewards-lite'), 208 208 'id' => LWS_WOOREWARDS_PAGE . '.customers', 209 'rights' => 'manage_rewards',209 'rights' => \LWS\Adminpanel\Tools\Conveniences::getCapOnRole('manage_rewards'), 210 210 'color' => '#A8CE38', 211 211 'image' => LWS_WOOREWARDS_IMG . '/r-customers.png', … … 237 237 return array( 238 238 'title' => __("Settings", 'woorewards-lite'), 239 'rights' => 'manage_rewards',239 'rights' => \LWS\Adminpanel\Tools\Conveniences::getCapOnRole('manage_rewards'), 240 240 'id' => LWS_WOOREWARDS_PAGE . '.loyalty', 241 241 'color' => '#526981', … … 265 265 'subtitle' => __("Wizard", 'woorewards-lite'), 266 266 'id' => LWS_WIZARD_SUMMONER . LWS_WOOREWARDS_PAGE, 267 'rights' => 'manage_rewards',267 'rights' => \LWS\Adminpanel\Tools\Conveniences::getCapOnRole('manage_rewards'), 268 268 'color' => '#00B7EB', 269 269 'image' => LWS_WOOREWARDS_IMG . '/r-wizard.png', … … 445 445 'subtitle' => __("Appearance", 'woorewards-lite'), 446 446 'id' => LWS_WOOREWARDS_PAGE . '.appearance', 447 'rights' => 'manage_rewards',448 'color' => '#4CBB41',449 'image' => LWS_WOOREWARDS_IMG . '/r-appearance.png',447 'rights' => \LWS\Adminpanel\Tools\Conveniences::getCapOnRole('manage_rewards'), 448 'color' => '#4CBB41', 449 'image' => LWS_WOOREWARDS_IMG . '/r-appearance.png', 450 450 'description' => __("Use this page to display loyalty content to your customers on your website", 'woorewards-lite'), 451 451 'tabs' => array( … … 474 474 'subtitle' => __("System", 'woorewards-lite'), 475 475 'id' => LWS_WOOREWARDS_PAGE . '.system', 476 'rights' => 'manage_rewards',477 'color' => '#7958A5',478 'image' => LWS_WOOREWARDS_IMG . '/r-system.png',476 'rights' => \LWS\Adminpanel\Tools\Conveniences::getCapOnRole('manage_rewards'), 477 'color' => '#7958A5', 478 'image' => LWS_WOOREWARDS_IMG . '/r-system.png', 479 479 'description' => __("Export or import your customers points, process past orders in this page", 'woorewards-lite'), 480 480 'delayedFunction' => array($this, 'showCronStatus'), … … 630 630 'pagetitle' => __("Pro Version", 'woorewards-lite'), 631 631 'id' => LWS_WOOREWARDS_PAGE . '-proversion', 632 'rights' => 'manage_options',633 'color' => '#4f9bbf',634 'nosave' => true,635 'image' => LWS_WOOREWARDS_IMG . '/r-pro.png',632 'rights' => \LWS\Adminpanel\Tools\Conveniences::getCapOnRole('manage_rewards'), 633 'color' => '#4f9bbf', 634 'nosave' => true, 635 'image' => LWS_WOOREWARDS_IMG . '/r-pro.png', 636 636 'description' => __("Unlock this plugin's full potential by switching to the pro version. Check all the features and discover how to install it", 'woorewards-lite'), 637 637 ); -
woorewards/trunk/include/ui/shortcodes/availablecoupons.php
r3188612 r3253191 8 8 class AvailableCoupons 9 9 { 10 CONST SLUG = 'wr_available_coupons'; 10 11 11 12 static function install() … … 13 14 $me = new self(); 14 15 /** Shortcode */ 15 \add_shortcode( 'wr_available_coupons', array($me, 'shortcode'));16 \add_shortcode(self::SLUG, array($me, 'shortcode')); 16 17 /** Admin */ 17 18 \add_filter('lws_woorewards_shortcodes', array($me, 'admin')); … … 95 96 'desc' => __("(Optional) Override the expiration label if any. Use the <b>%s</b> placeholder for the date. You can set an empty string to display nothing.", 'woorewards-lite'), 96 97 'example' => '[wr_available_coupons expire-html=" (Expires on %s)"]' 98 ), 99 array( 100 'option' => 'in-the-last', 101 'desc' => [ 102 __("(Optional) Show only coupons created in the last given period.", 'woorewards-lite'), 103 __("A period is defined by a number and a duration unit.", 'woorewards-lite'), 104 __("Accepted units are:", 'woorewards-lite'), ['tag' => 'ul', 105 ['D', __("for Days", 'woorewards-lite')], 106 ['W', __("for Weeks", 'woorewards-lite')], 107 ['M', __("for Months", 'woorewards-lite')], 108 ['Y', __("for Years", 'woorewards-lite')], 109 ], 110 ], 111 'example' => '[wr_available_coupons in-the-last="1M"]' 112 ), 113 array( 114 'option' => 'reset-day', 115 'desc' => [ 116 sprintf(__("(Optional) Works with %s attribute to build an incremental period instead the default shift date.", 'woorewards-lite'), '`<i>in-the-last</i>`'), 117 __("Expect the day of the month the period should reset within the original rolling period.", 'woorewards-lite'), 118 __("The value is automatically clamped to the last day of the month if necessary.", 'woorewards-lite'), 119 ], 120 'example' => '[wr_available_coupons in-the-last="1Y" reset-day="1"]' 97 121 ), 98 122 ), … … 129 153 return ''; 130 154 } 131 if (!$userId = \get_current_user_id()) { 155 $userId = \apply_filters('lws_woorewards_shortcode_current_user_id', \get_current_user_id(), $atts, self::SLUG); 156 if (!$userId) { 132 157 return \do_shortcode((string)$content); 133 158 } 134 if (empty($data = \LWS\WOOREWARDS\Conveniences::instance()->getCoupons($userId))) { 135 return \do_shortcode((string)$content); 136 } 159 137 160 $atts = \LWS\Adminpanel\Tools\Conveniences::sanitizeAttr(\wp_parse_args($atts, array( 138 161 'buttons' => false, … … 141 164 'element' => 'line', 142 165 'expire-html' => false, 166 'in-the-last' => false, 167 'min-date' => false, 168 'reset-day' => false, 143 169 ))); 170 $where = $this->checkDateFilters($atts); 171 172 $data = \LWS\WOOREWARDS\Conveniences::instance()->getCoupons($userId, $where); 173 if (!$data) { 174 return \do_shortcode((string)$content); 175 } 176 144 177 $this->enqueueScripts(); 145 178 return $this->getContent($atts, $data); 179 } 180 181 /** merge $atts to set a 'reset-date' entry to filter coupon by min creation date. 182 * @param $atts array inout 183 * @return array sql where filter @see \LWS\WOOREWARDS\Conveniences\getCoupons */ 184 private function checkDateFilters(array &$atts): array 185 { 186 if ($atts['min-date']) { 187 $atts['min-date'] = \date_create_immutable($atts['min-date'], \wp_timezone()); 188 } 189 190 if ($atts['in-the-last']) { 191 $atts['reset-day'] = (int)$atts['reset-day']; 192 193 // test a valid format 194 $pattern = '/(\d+)\s*([ymdw])/i'; 195 if (\preg_match_all($pattern, $atts['in-the-last'], $matches, PREG_SET_ORDER)) { 196 $period = ['_' =>'P']; 197 foreach ($matches as $match) { 198 $u = \strtoupper($match[2]); 199 $period[$u] = $match[1] . $u; 200 } 201 202 $interval = new \DateInterval(\implode('', $period)); 203 $date = \date_create_immutable('now', \wp_timezone())->sub($interval); 204 205 if ($atts['reset-day']) { 206 $coming = \LWS\Adminpanel\Tools\Dates::replace($date, ['day' => $atts['reset-day']]); 207 if ($coming->setTime(0, 0) < $date->setTime(0, 0)) { 208 $coming = \LWS\Adminpanel\Tools\Dates::addMonths($coming, 1, $atts['reset-day']); 209 } 210 $atts['min-date'] = $coming; 211 } else { 212 $atts['min-date'] = $date; 213 } 214 } else { 215 $atts['in-the-last'] = false; 216 } 217 } 218 219 if ($atts['min-date']) { 220 return [ 221 sprintf( 222 "p.post_date_gmt >= '%s'", 223 $atts['min-date']->setTime(0, 0)->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s') 224 ), 225 ]; 226 } else { 227 return []; 228 } 146 229 } 147 230 -
woorewards/trunk/readme.txt
r3234695 r3253191 5 5 Tested up to: 6.7 6 6 Requires PHP: 7.0.0 7 Stable tag: 5.4. 87 Stable tag: 5.4.9 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 110 110 == Changelog == 111 111 112 = 5.4.8 == 112 = 5.4.9 = 113 * Tag - WooCommerce 9.7 114 * Feature - new attributes for wr_available_coupons shortcode 115 116 = 5.4.8 = 113 117 * MyRewards Pro : 114 118 * Fix - single free product reward with WC new cart bloc 115 119 116 = 5.4.7 = =120 = 5.4.7 = 117 121 * Tag - WooCommerce 9.6 118 122 * Update - translations … … 121 125 * Feature - new attributes for wr_available_rewards shortcode 122 126 123 = 5.4.6 = =127 = 5.4.6 = 124 128 * Fix - WordPress 6.7 Delay translation time 125 129 -
woorewards/trunk/woorewards.php
r3234695 r3253191 7 7 * Author: Long Watch Studio 8 8 * Author URI: https://longwatchstudio.com 9 * Version: 5.4. 89 * Version: 5.4.9 10 10 * License: Copyright LongWatchStudio 2022 11 11 * Text Domain: woorewards-lite 12 12 * Domain Path: /languages 13 13 * WC requires at least: 7.1.0 14 * WC tested up to: 9. 614 * WC tested up to: 9.7 15 15 * 16 16 * Copyright (c) 2022 Long Watch Studio (email: plugins@longwatchstudio.com). All rights reserved. … … 111 111 private function defineConstants() 112 112 { 113 define('LWS_WOOREWARDS_VERSION', '5.4. 8');113 define('LWS_WOOREWARDS_VERSION', '5.4.9'); 114 114 define('LWS_WOOREWARDS_FILE', __FILE__); 115 115 define('LWS_WOOREWARDS_DOMAIN', 'woorewards-lite'); … … 149 149 public function addPluginVersion($url) 150 150 { 151 return '5.4. 8';151 return '5.4.9'; 152 152 } 153 153
Note: See TracChangeset
for help on using the changeset viewer.