Changeset 3297309
- Timestamp:
- 05/20/2025 11:25:41 AM (9 months ago)
- Location:
- product-purchase-notifications
- Files:
-
- 44 added
- 2 edited
-
tags/1.1.2 (added)
-
tags/1.1.2/admin (added)
-
tags/1.1.2/admin/js (added)
-
tags/1.1.2/admin/js/script.js (added)
-
tags/1.1.2/admin/option_page.php (added)
-
tags/1.1.2/admin/style (added)
-
tags/1.1.2/admin/style/style.css (added)
-
tags/1.1.2/admin/temple (added)
-
tags/1.1.2/assets (added)
-
tags/1.1.2/assets/banner-772x250.png (added)
-
tags/1.1.2/assets/icon-128x128.png (added)
-
tags/1.1.2/assets/icon-256x256.png (added)
-
tags/1.1.2/assets/screenshot-1.png (added)
-
tags/1.1.2/assets/screenshot-2.png (added)
-
tags/1.1.2/index.php (added)
-
tags/1.1.2/product-purchase-notifications.php (added)
-
tags/1.1.2/public (added)
-
tags/1.1.2/public/css (added)
-
tags/1.1.2/public/css/banner-style.css (added)
-
tags/1.1.2/public/js (added)
-
tags/1.1.2/public/js/script.js (added)
-
tags/1.1.2/readme.txt (added)
-
tags/1.1.3 (added)
-
tags/1.1.3/admin (added)
-
tags/1.1.3/admin/js (added)
-
tags/1.1.3/admin/js/script.js (added)
-
tags/1.1.3/admin/option_page.php (added)
-
tags/1.1.3/admin/style (added)
-
tags/1.1.3/admin/style/style.css (added)
-
tags/1.1.3/admin/temple (added)
-
tags/1.1.3/assets (added)
-
tags/1.1.3/assets/banner-772x250.png (added)
-
tags/1.1.3/assets/icon-128x128.png (added)
-
tags/1.1.3/assets/icon-256x256.png (added)
-
tags/1.1.3/assets/screenshot-1.png (added)
-
tags/1.1.3/assets/screenshot-2.png (added)
-
tags/1.1.3/index.php (added)
-
tags/1.1.3/product-purchase-notifications.php (added)
-
tags/1.1.3/public (added)
-
tags/1.1.3/public/css (added)
-
tags/1.1.3/public/css/banner-style.css (added)
-
tags/1.1.3/public/js (added)
-
tags/1.1.3/public/js/script.js (added)
-
tags/1.1.3/readme.txt (added)
-
trunk/product-purchase-notifications.php (modified) (16 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
product-purchase-notifications/trunk/product-purchase-notifications.php
r3297270 r3297309 2 2 3 3 /** 4 *5 4 * Plugin Name: Product Purchase Notifications 6 * Version: 1.1. 25 * Version: 1.1.3 7 6 * Description: Generate Notifications for latest order Placed on the site 8 7 * Author: Bitcraftx … … 13 12 * License: GPLv2 or later 14 13 */ 15 16 use function PHPSTORM_META\type; 17 18 if (!defined('ABSPATH')) { 14 if (! defined('ABSPATH')) { 19 15 exit; // Exit if accessed directly 20 16 } 21 require_once (ABSPATH . 'wp-admin/includes/plugin.php');17 require_once ABSPATH.'wp-admin/includes/plugin.php'; 22 18 23 19 /** 24 20 * check for WooCommerce activation. 25 21 */ 26 if (! (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))) {22 if (! (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))) { 27 23 deactivate_plugins(plugin_basename(__FILE__)); 28 if (isset($_GET['activate']) && isset($_GET['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'activate-plugin_' .plugin_basename(__FILE__))) {29 unset($_GET['activate']);30 }24 if (isset($_GET['activate']) && isset($_GET['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'activate-plugin_'.plugin_basename(__FILE__))) { 25 unset($_GET['activate']); 26 } 31 27 function bitcx_ppn_sample_admin_notice__error() 32 28 { … … 40 36 { 41 37 private $bitcx_ppn_notifyMe_nonce; 42 private $plugin_version = '1.1.2'; 38 39 private $plugin_version = '1.1.3'; 40 43 41 /** 44 42 * constructor 45 43 */ 46 function __construct()44 public function __construct() 47 45 { 48 46 $this->bitcx_ppn_setup(); 49 47 } 50 function bitcx_ppn_setup() 51 { 52 register_activation_hook(__FILE__, array($this, 'bitcx_ppn_nm_activate')); 53 add_action("wp_enqueue_scripts", array($this, 'bitcx_ppn_enqueue_scripts')); 54 55 add_filter('plugin_action_links', array($this, 'bitcx_ppn_settingPagelink'), 10, 2); //setting option in plugin with active/deactivate. 56 add_filter('plugin_row_meta', array($this, 'bitcx_ppn_add_support_link'), 10, 2); 57 58 add_action('wp_ajax_generatepopup', array($this, 'bitcx_ppn_generatepopup')); 59 60 add_action('wp_ajax_nopriv_generatepopup', array($this, 'bitcx_ppn_generatepopup')); 61 } 48 49 public function bitcx_ppn_setup() 50 { 51 register_activation_hook(__FILE__, [$this, 'bitcx_ppn_nm_activate']); 52 add_action('wp_enqueue_scripts', [$this, 'bitcx_ppn_enqueue_scripts']); 53 54 add_filter('plugin_action_links', [$this, 'bitcx_ppn_settingPagelink'], 10, 2); // setting option in plugin with active/deactivate. 55 add_filter('plugin_row_meta', [$this, 'bitcx_ppn_add_support_link'], 10, 2); 56 57 add_action('wp_ajax_generatepopup', [$this, 'bitcx_ppn_generatepopup']); 58 59 add_action('wp_ajax_nopriv_generatepopup', [$this, 'bitcx_ppn_generatepopup']); 60 } 61 62 62 /** 63 63 * activate plugin 64 64 */ 65 function bitcx_ppn_nm_activate() 66 { 67 update_option("notify_time", 5); 68 update_option("notify_toggle_img", 1); 69 update_option("notify_showOrHideName", 1); 70 update_option("notify_positionOfTheBanner", 1); 71 update_option("notify_color_title", '#050505'); 72 update_option("notify_color_text", "#b1afaf"); 73 update_option("notify_color_background", "#ffffff"); 74 update_option("notify_color_shadow", "#a1a1a1"); 75 } 65 public function bitcx_ppn_nm_activate() 66 { 67 update_option('notify_time', 5); 68 update_option('notify_toggle_img', 1); 69 update_option('notify_showOrHideName', 1); 70 update_option('notify_positionOfTheBanner', 1); 71 update_option('notify_color_title', '#050505'); 72 update_option('notify_color_text', '#b1afaf'); 73 update_option('notify_color_background', '#ffffff'); 74 update_option('notify_color_shadow', '#a1a1a1'); 75 } 76 76 77 /** 77 78 * enqueue script and styles sheet 78 79 */ 79 function bitcx_ppn_enqueue_scripts() 80 { 81 wp_enqueue_script('bitcx_ppn_script', plugin_dir_url(__FILE__) . 'public/js/script.js', ['jquery'], $this->plugin_version, true); 82 wp_enqueue_style('bitcx_ppn_style', plugin_dir_url(__FILE__) . 'public/css/banner-style.css', null, $this->plugin_version, 'all'); 83 $this->bitcx_ppn_notifyMe_nonce = wp_create_nonce("notifyMe_nonce"); 84 wp_localize_script("bitcx_ppn_script", "localizedData", ["url" => admin_url("admin-ajax.php"), 'timeDisapear' => 5000, 'nonce' => $this->bitcx_ppn_notifyMe_nonce, 'action' => "generatepopup"]); 85 } 80 public function bitcx_ppn_enqueue_scripts() 81 { 82 wp_enqueue_script('bitcx_ppn_script', plugin_dir_url(__FILE__).'public/js/script.js', ['jquery'], $this->plugin_version, true); 83 wp_enqueue_style('bitcx_ppn_style', plugin_dir_url(__FILE__).'public/css/banner-style.css', null, $this->plugin_version, 'all'); 84 $this->bitcx_ppn_notifyMe_nonce = wp_create_nonce('notifyMe_nonce'); 85 wp_localize_script('bitcx_ppn_script', 'localizedData', ['url' => admin_url('admin-ajax.php'), 'timeDisapear' => 5000, 'nonce' => $this->bitcx_ppn_notifyMe_nonce, 'action' => 'generatepopup']); 86 } 87 86 88 /** 87 89 * callback for ajax request it fetch data from the database about recent order placed across the site. 88 90 */ 89 function bitcx_ppn_generatepopup()91 public function bitcx_ppn_generatepopup() 90 92 { 91 93 $shownIds = []; 92 94 93 95 $raw_ids = filter_input(INPUT_POST, 'ids', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); 94 if ( null === $raw_ids) {96 if ($raw_ids === null) { 95 97 $raw_ids = filter_input(INPUT_GET, 'ids', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); 96 98 } … … 101 103 } 102 104 103 104 105 $nonce = isset($_REQUEST['nonce']) ? sanitize_text_field(wp_unslash($_REQUEST['nonce'])) : ''; 105 if (! is_array($shownIds)) {106 if (! is_array($shownIds)) { 106 107 wp_send_json(''); 107 108 } 108 109 if (wp_verify_nonce($nonce, 'notifyMe_nonce')) { 109 110 $resp = []; 110 $resp[ "items"] = [];111 $resp['items'] = []; 111 112 $oneProduct = []; 112 113 $counter = 0; 113 $TotalLatestOrder = 5; // how many record to show114 $TotalLatestOrder = 5; // how many record to show 114 115 // wp_send_json('');die; 115 $totalOrders = wc_get_orders( array('limit' => -1, 'return' => 'ids'));116 $totalOrders = sizeof($totalOrders);116 $totalOrders = wc_get_orders(['limit' => -1, 'return' => 'ids']); 117 $totalOrders = count($totalOrders); 117 118 $offset = count($shownIds); // number of already shown orders 118 $last_order_id = wc_get_orders( array(119 'limit' => $TotalLatestOrder,120 'offset' => $offset,119 $last_order_id = wc_get_orders([ 120 'limit' => $TotalLatestOrder, 121 'offset' => $offset, 121 122 'orderby' => 'date', 122 'order' => 'DESC',123 'return' => 'ids'124 ));125 126 if ( sizeof($last_order_id) < $TotalLatestOrder) {127 $TotalLatestOrder = sizeof($last_order_id);128 } 129 $randomNumber = random_int(0, $TotalLatestOrder - 1); // counter to fetch random record130 131 if (! empty($last_order_id)) {132 // meta fetching133 $notify_time = get_option( "notify_time");134 $notify_toggle_img = get_option( "notify_toggle_img");135 $notify_showOrHideName = get_option( "notify_showOrHideName");136 $notify_positionOfTheBanner = get_option( "notify_positionOfTheBanner");137 $notify_color_title = get_option( "notify_color_title");138 $notify_color_text = get_option( "notify_color_text");139 $notify_color_background = get_option( "notify_color_background");140 $notify_color_shadow = get_option( "notify_color_shadow");141 // Fetch Order's detail123 'order' => 'DESC', 124 'return' => 'ids', 125 ]); 126 127 if (count($last_order_id) < $TotalLatestOrder) { 128 $TotalLatestOrder = count($last_order_id); 129 } 130 $randomNumber = random_int(0, $TotalLatestOrder - 1); // counter to fetch random record 131 132 if (! empty($last_order_id)) { 133 // meta fetching 134 $notify_time = get_option('notify_time'); 135 $notify_toggle_img = get_option('notify_toggle_img'); 136 $notify_showOrHideName = get_option('notify_showOrHideName'); 137 $notify_positionOfTheBanner = get_option('notify_positionOfTheBanner'); 138 $notify_color_title = get_option('notify_color_title'); 139 $notify_color_text = get_option('notify_color_text'); 140 $notify_color_background = get_option('notify_color_background'); 141 $notify_color_shadow = get_option('notify_color_shadow'); 142 // Fetch Order's detail 142 143 143 144 $order = wc_get_order($last_order_id[$randomNumber]); … … 151 152 $lastName = $order->get_billing_last_name(); 152 153 if ($firstName && $lastName) { 153 $buyerName = $firstName . ' ' .$lastName;154 $buyerName = $firstName.' '.$lastName; 154 155 } else { 155 156 $user = $order->get_user(); … … 157 158 $buyerName = $user->user_nicename; 158 159 } else { 159 $buyerName = "SomeOne";160 $buyerName = 'SomeOne'; 160 161 } 161 162 } … … 163 164 $get_billing_city = $order->get_billing_city(); 164 165 if ($order->get_items()) { 165 foreach ($order->get_items() as $item_id => $item) { // fetch each product166 foreach ($order->get_items() as $item_id => $item) { // fetch each product 166 167 $oneProduct[$counter]['product_name'] = $item->get_name(); 167 168 $oneProduct[$counter]['quantity'] = $item->get_quantity(); … … 174 175 } 175 176 } 176 // Generate time String to show on banner.177 // Generate time String to show on banner. 177 178 if ($PlacedAt) { 178 179 $interval = $this->bitcx_ppn_makeTimeStirngMsg($PlacedAt); 179 180 } 180 181 181 // check how much items are in one order.182 // check how much items are in one order. 182 183 if ($oneProduct) { 183 $TotelProductInOneOrder = sizeof($oneProduct);184 $TotelProductInOneOrder = count($oneProduct); 184 185 $randomProductinOrder = random_int(0, $TotelProductInOneOrder - 1); 185 186 } 186 187 187 // Add data to array188 // OrderDetails189 $resp += [ "id"=> $id];190 $resp += [ "totalOrders"=> $totalOrders];191 $resp += [ "shownIDs" => sizeof($shownIds)];192 $resp += [ "buyer"=> $buyerName];193 $resp += [ "get_billing_city"=> $get_billing_city];194 $resp += [ "PlacedAt"=> $interval];195 // Styling,times and position to show the Notification196 $resp += [ "notify_time"=> $notify_time];197 $resp += [ "notify_toggle_img"=> $notify_toggle_img];198 $resp += [ "notify_showOrHideName"=> $notify_showOrHideName];199 $resp += [ "notify_positionOfTheBanner"=> $notify_positionOfTheBanner];200 $resp += [ "notify_color_title"=> $notify_color_title];201 $resp += [ "notify_color_text"=> $notify_color_text];202 $resp += [ "notify_color_background"=> $notify_color_background];203 $resp += [ "notify_color_shadow"=> $notify_color_shadow];204 // Product Details205 $resp[ "items"] += ["product_name"=> $oneProduct[$randomProductinOrder]['product_name']];206 $resp[ "items"] += ["quantity"=> $oneProduct[$randomProductinOrder]['quantity']];207 $resp[ "items"] += ["product_type"=> $oneProduct[$randomProductinOrder]['product_type']];188 // Add data to array 189 // OrderDetails 190 $resp += ['id' => $id]; 191 $resp += ['totalOrders' => $totalOrders]; 192 $resp += ['shownIDs' => count($shownIds)]; 193 $resp += ['buyer' => $buyerName]; 194 $resp += ['get_billing_city' => $get_billing_city]; 195 $resp += ['PlacedAt' => $interval]; 196 // Styling,times and position to show the Notification 197 $resp += ['notify_time' => $notify_time]; 198 $resp += ['notify_toggle_img' => $notify_toggle_img]; 199 $resp += ['notify_showOrHideName' => $notify_showOrHideName]; 200 $resp += ['notify_positionOfTheBanner' => $notify_positionOfTheBanner]; 201 $resp += ['notify_color_title' => $notify_color_title]; 202 $resp += ['notify_color_text' => $notify_color_text]; 203 $resp += ['notify_color_background' => $notify_color_background]; 204 $resp += ['notify_color_shadow' => $notify_color_shadow]; 205 // Product Details 206 $resp['items'] += ['product_name' => $oneProduct[$randomProductinOrder]['product_name']]; 207 $resp['items'] += ['quantity' => $oneProduct[$randomProductinOrder]['quantity']]; 208 $resp['items'] += ['product_type' => $oneProduct[$randomProductinOrder]['product_type']]; 208 209 if ($notify_toggle_img == 1) { 209 $resp[ "items"] += ["imgurl"=> $oneProduct[$randomProductinOrder]['imgurl']];210 $resp['items'] += ['imgurl' => $oneProduct[$randomProductinOrder]['imgurl']]; 210 211 } 211 $resp[ "items"] += ["Permalink"=> $oneProduct[$randomProductinOrder]['Permalink']];212 $resp['items'] += ['Permalink' => $oneProduct[$randomProductinOrder]['Permalink']]; 212 213 213 214 wp_send_json($resp); … … 218 219 } 219 220 220 die(); 221 } 221 exit(); 222 } 223 222 224 /** 223 225 * make a string to display on front-end with notification. 224 226 */ 225 function bitcx_ppn_makeTimeStirngMsg($DateObj)226 { 227 228 $currentTime = new DateTime ();227 public function bitcx_ppn_makeTimeStirngMsg($DateObj) 228 { 229 230 $currentTime = new DateTime; 229 231 230 232 $timeInterval = date_diff($DateObj, $currentTime); 231 $months = (int) $timeInterval->format('%m');232 $days = (int) $timeInterval->format('%d');233 $hours = (int) $timeInterval->format('%h');234 $minutes = (int) $timeInterval->format('%i');235 $seconds = (int) $timeInterval->format('%s');236 237 // month233 $months = (int) $timeInterval->format('%m'); 234 $days = (int) $timeInterval->format('%d'); 235 $hours = (int) $timeInterval->format('%h'); 236 $minutes = (int) $timeInterval->format('%i'); 237 $seconds = (int) $timeInterval->format('%s'); 238 239 // month 238 240 $timeArray = []; 239 241 if ($months != '0') { … … 245 247 array_push($timeArray, $months); 246 248 } 247 // days249 // days 248 250 if ($days != '0') { 249 251 if ($days == '1') { … … 254 256 array_push($timeArray, $days); 255 257 } 256 // hours258 // hours 257 259 if ($hours != '0') { 258 260 if ($hours == '1') { … … 263 265 array_push($timeArray, $hours); 264 266 } 265 // minutes267 // minutes 266 268 if ($minutes != '0') { 267 269 if ($minutes == '1') { … … 276 278 if ($seconds >= '15' || $timeArray != []) { 277 279 $seconds = "$seconds Seconds"; 278 } else if ($seconds <= '15' && $timeArray == []) {279 $seconds = "Just Now";280 } elseif ($seconds <= '15' && $timeArray == []) { 281 $seconds = 'Just Now'; 280 282 } 281 283 array_push($timeArray, $seconds); 282 284 } 283 if ( sizeof($timeArray) > 3) {285 if (count($timeArray) > 3) { 284 286 $timeArray = array_slice($timeArray, 0, 3); 285 287 } … … 289 291 } 290 292 if (isset($timeArray[1])) { 291 $timeString .= ", " .$timeArray[1];293 $timeString .= ', '.$timeArray[1]; 292 294 } 293 295 if (isset($timeArray[2])) { 294 $timeString .= ", And " . $timeArray[2]; 295 } 296 $timeString .= " Ago"; 296 $timeString .= ', And '.$timeArray[2]; 297 } 298 $timeString .= ' Ago'; 299 297 300 return $timeString; 298 301 } 302 299 303 /** 300 304 * Display a setting button along with the a Activate/Deactivate Plugin button on plugin Menu-page. 301 305 */ 302 function bitcx_ppn_settingPagelink($links, $file)303 { 304 if ($file == plugin_basename(dirname(__FILE__) .'/product-purchase-notifications.php')) {306 public function bitcx_ppn_settingPagelink($links, $file) 307 { 308 if ($file == plugin_basename(dirname(__FILE__).'/product-purchase-notifications.php')) { 305 309 /* 306 310 * Insert the link at the beginning. 307 311 */ 308 $in = '<a href="options-general.php?page=bitcx_ppn_notify_me">' . __('Settings', 'product-purchase-notifications') .'</a>';312 $in = '<a href="options-general.php?page=bitcx_ppn_notify_me">'.__('Settings', 'product-purchase-notifications').'</a>'; 309 313 array_unshift($links, $in); 310 314 } 315 311 316 return $links; 312 317 } … … 319 324 if (plugin_basename(__FILE__) === $file) { 320 325 // Check if 'Description' key exists, initialize if not 321 if (! isset($data['Description'])) {326 if (! isset($data['Description'])) { 322 327 $data['Description'] = ''; 323 328 } … … 331 336 } 332 337 333 include_once plugin_dir_path(__FILE__) .'admin/option_page.php';334 new bitcx_notify_me ();335 new bitcx_notify_me_setting ();338 include_once plugin_dir_path(__FILE__).'admin/option_page.php'; 339 new bitcx_notify_me; 340 new bitcx_notify_me_setting; -
product-purchase-notifications/trunk/readme.txt
r3297270 r3297309 1 1 === Product Purchase Notifications === 2 Contributors: Ali Hussain, Talha Umar2 Contributors: bitcraftx 3 3 Donate link: https://bitcraftx.com/ 4 4 Tags: woocommerce, store, sales, woo commerce addons, notifications 5 5 Requires at least: 6.0 6 6 Tested up to: 6.8 7 Stable tag: 1.1. 27 Stable tag: 1.1.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 54 54 55 55 == Changelog == 56 = 1.1.3 = 57 * Contributors fixes. 58 56 59 = 1.1.2 = 57 60 * Fix Buyer name hide and show issue.
Note: See TracChangeset
for help on using the changeset viewer.