Plugin Directory

Changeset 3297309


Ignore:
Timestamp:
05/20/2025 11:25:41 AM (9 months ago)
Author:
bitcraftx
Message:

Contributors fixes

Location:
product-purchase-notifications
Files:
44 added
2 edited

Legend:

Unmodified
Added
Removed
  • product-purchase-notifications/trunk/product-purchase-notifications.php

    r3297270 r3297309  
    22
    33/**
    4  *
    54 * Plugin Name: Product Purchase Notifications
    6  * Version: 1.1.2
     5 * Version: 1.1.3
    76 * Description: Generate Notifications for latest order Placed on the site
    87 * Author: Bitcraftx
     
    1312 * License: GPLv2 or later
    1413 */
    15 
    16 use function PHPSTORM_META\type;
    17 
    18 if (!defined('ABSPATH')) {
     14if (! defined('ABSPATH')) {
    1915    exit; // Exit if accessed directly
    2016}
    21 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
     17require_once ABSPATH.'wp-admin/includes/plugin.php';
    2218
    2319/**
    2420 * check for WooCommerce activation.
    2521 */
    26 if (!(in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))) {
     22if (! (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))) {
    2723    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    }
    3127    function bitcx_ppn_sample_admin_notice__error()
    3228    {
     
    4036{
    4137    private $bitcx_ppn_notifyMe_nonce;
    42     private $plugin_version = '1.1.2';
     38
     39    private $plugin_version = '1.1.3';
     40
    4341    /**
    4442     * constructor
    4543     */
    46     function __construct()
     44    public function __construct()
    4745    {
    4846        $this->bitcx_ppn_setup();
    4947    }
    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
    6262    /**
    6363     * activate plugin
    6464     */
    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
    7677    /**
    7778     * enqueue script and styles sheet
    7879     */
    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
    8688    /**
    8789     * callback for ajax request it fetch data from the database about recent order placed across the site.
    8890     */
    89     function bitcx_ppn_generatepopup()
     91    public function bitcx_ppn_generatepopup()
    9092    {
    9193        $shownIds = [];
    9294
    9395        $raw_ids = filter_input(INPUT_POST, 'ids', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    94         if (null === $raw_ids) {
     96        if ($raw_ids === null) {
    9597            $raw_ids = filter_input(INPUT_GET, 'ids', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    9698        }
     
    101103        }
    102104
    103 
    104105        $nonce = isset($_REQUEST['nonce']) ? sanitize_text_field(wp_unslash($_REQUEST['nonce'])) : '';
    105         if (!is_array($shownIds)) {
     106        if (! is_array($shownIds)) {
    106107            wp_send_json('');
    107108        }
    108109        if (wp_verify_nonce($nonce, 'notifyMe_nonce')) {
    109110            $resp = [];
    110             $resp["items"] = [];
     111            $resp['items'] = [];
    111112            $oneProduct = [];
    112113            $counter = 0;
    113             $TotalLatestOrder = 5; //how many record to show
     114            $TotalLatestOrder = 5; // how many record to show
    114115            // 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);
    117118            $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,
    121122                '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 record
    130 
    131             if (!empty($last_order_id)) {
    132                 //meta fetching
    133                 $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 detail
     123                '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
    142143
    143144                $order = wc_get_order($last_order_id[$randomNumber]);
     
    151152                        $lastName = $order->get_billing_last_name();
    152153                        if ($firstName && $lastName) {
    153                             $buyerName = $firstName . ' ' . $lastName;
     154                            $buyerName = $firstName.' '.$lastName;
    154155                        } else {
    155156                            $user = $order->get_user();
     
    157158                                $buyerName = $user->user_nicename;
    158159                            } else {
    159                                 $buyerName = "SomeOne";
     160                                $buyerName = 'SomeOne';
    160161                            }
    161162                        }
     
    163164                        $get_billing_city = $order->get_billing_city();
    164165                        if ($order->get_items()) {
    165                             foreach ($order->get_items() as $item_id => $item) { //fetch each product
     166                            foreach ($order->get_items() as $item_id => $item) { // fetch each product
    166167                                $oneProduct[$counter]['product_name'] = $item->get_name();
    167168                                $oneProduct[$counter]['quantity'] = $item->get_quantity();
     
    174175                        }
    175176                    }
    176                     //Generate time String to show on banner.
     177                    // Generate time String to show on banner.
    177178                    if ($PlacedAt) {
    178179                        $interval = $this->bitcx_ppn_makeTimeStirngMsg($PlacedAt);
    179180                    }
    180181
    181                     //check how much items are in one order.
     182                    // check how much items are in one order.
    182183                    if ($oneProduct) {
    183                         $TotelProductInOneOrder = sizeof($oneProduct);
     184                        $TotelProductInOneOrder = count($oneProduct);
    184185                        $randomProductinOrder = random_int(0, $TotelProductInOneOrder - 1);
    185186                    }
    186187
    187                     //Add data to array
    188                     //OrderDetails
    189                     $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 Notification
    196                     $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 Details
    205                     $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']];
    208209                    if ($notify_toggle_img == 1) {
    209                         $resp["items"] += ["imgurl" => $oneProduct[$randomProductinOrder]['imgurl']];
     210                        $resp['items'] += ['imgurl' => $oneProduct[$randomProductinOrder]['imgurl']];
    210211                    }
    211                     $resp["items"] += ["Permalink" => $oneProduct[$randomProductinOrder]['Permalink']];
     212                    $resp['items'] += ['Permalink' => $oneProduct[$randomProductinOrder]['Permalink']];
    212213
    213214                    wp_send_json($resp);
     
    218219        }
    219220
    220         die();
    221     }
     221        exit();
     222    }
     223
    222224    /**
    223225     * make a string to display on front-end with notification.
    224226     */
    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;
    229231
    230232        $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         //month
     233        $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
    238240        $timeArray = [];
    239241        if ($months != '0') {
     
    245247            array_push($timeArray, $months);
    246248        }
    247         //days
     249        // days
    248250        if ($days != '0') {
    249251            if ($days == '1') {
     
    254256            array_push($timeArray, $days);
    255257        }
    256         //hours
     258        // hours
    257259        if ($hours != '0') {
    258260            if ($hours == '1') {
     
    263265            array_push($timeArray, $hours);
    264266        }
    265         //minutes
     267        // minutes
    266268        if ($minutes != '0') {
    267269            if ($minutes == '1') {
     
    276278            if ($seconds >= '15' || $timeArray != []) {
    277279                $seconds = "$seconds Seconds";
    278             } else if ($seconds <= '15' && $timeArray == []) {
    279                 $seconds = "Just Now";
     280            } elseif ($seconds <= '15' && $timeArray == []) {
     281                $seconds = 'Just Now';
    280282            }
    281283            array_push($timeArray, $seconds);
    282284        }
    283         if (sizeof($timeArray) > 3) {
     285        if (count($timeArray) > 3) {
    284286            $timeArray = array_slice($timeArray, 0, 3);
    285287        }
     
    289291        }
    290292        if (isset($timeArray[1])) {
    291             $timeString .= ", " . $timeArray[1];
     293            $timeString .= ', '.$timeArray[1];
    292294        }
    293295        if (isset($timeArray[2])) {
    294             $timeString .= ", And " . $timeArray[2];
    295         }
    296         $timeString .= " Ago";
     296            $timeString .= ', And '.$timeArray[2];
     297        }
     298        $timeString .= ' Ago';
     299
    297300        return $timeString;
    298301    }
     302
    299303    /**
    300304     * Display a setting button along with the a Activate/Deactivate Plugin button on plugin Menu-page.
    301305     */
    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')) {
    305309            /*
    306310             * Insert the link at the beginning.
    307311             */
    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>';
    309313            array_unshift($links, $in);
    310314        }
     315
    311316        return $links;
    312317    }
     
    319324        if (plugin_basename(__FILE__) === $file) {
    320325            // Check if 'Description' key exists, initialize if not
    321             if (!isset($data['Description'])) {
     326            if (! isset($data['Description'])) {
    322327                $data['Description'] = '';
    323328            }
     
    331336}
    332337
    333 include_once plugin_dir_path(__FILE__) . 'admin/option_page.php';
    334 new bitcx_notify_me();
    335 new bitcx_notify_me_setting();
     338include_once plugin_dir_path(__FILE__).'admin/option_page.php';
     339new bitcx_notify_me;
     340new bitcx_notify_me_setting;
  • product-purchase-notifications/trunk/readme.txt

    r3297270 r3297309  
    11=== Product Purchase Notifications ===
    2 Contributors: Ali Hussain, Talha Umar
     2Contributors: bitcraftx
    33Donate link: https://bitcraftx.com/
    44Tags:  woocommerce, store, sales, woo commerce addons, notifications
    55Requires at least: 6.0
    66Tested up to: 6.8
    7 Stable tag: 1.1.2
     7Stable tag: 1.1.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5454
    5555== Changelog ==
     56= 1.1.3 =
     57* Contributors fixes.
     58
    5659= 1.1.2 =
    5760* Fix Buyer name hide and show issue.
Note: See TracChangeset for help on using the changeset viewer.