Plugin Directory

Changeset 3486480


Ignore:
Timestamp:
03/19/2026 12:55:17 PM (13 days ago)
Author:
invoked
Message:

added handling on deactivate and uninstall of the plugin
added UI guidance for users after coming on the settings page of the plugin

Location:
biblio-dispatch/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • biblio-dispatch/trunk/bibliodispatch-plugin.php

    r3484529 r3486480  
    33Plugin Name: Print Management with Biblio Dispatch
    44Description: The Print Management with Biblio Dispatch plugin streamlines print services by enabling user registration and login.With seamless integration into your WordPress site, it enhances order management and improves efficiency for your print service operations.
    5 Version: 1.3.2
     5Version: 1.3.3
    66License: GPL2
    77License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3333if (!defined('BIBLIO_PLUGIN_ITEM_REFERENCE')) {
    3434    define('BIBLIO_PLUGIN_ITEM_REFERENCE', 'BIBLIO Plugin');
     35}
     36if (!defined('PLUGIN_DEACTIVATE_URL')) {
     37    define('PLUGIN_DEACTIVATE_URL', 'https://bibliomax.com/authorsuite/wordpressDeactivate');
    3538}
    3639
     
    299302    // Enqueue your custom styles or scripts if needed
    300303    wp_enqueue_style('wc-api-custom-style', plugin_dir_url(__FILE__) . 'css/style.css', array(), $custom_style_version);
     304
     305    wp_enqueue_script('wp-pointer');
     306    wp_enqueue_style('wp-pointer');
     307
     308    $user_id = get_current_user_id();
     309    $clicked = get_option('biblio_portal_clicked_' . $user_id, 0);
     310
     311    if (!$clicked) {
     312        wp_add_inline_script('custom-script', "
     313        jQuery(document).ready(function($){
     314            var target = $('.dispatch-connect').first();
     315            if(target.length){
     316                target.pointer({
     317                    content: '<h3>BiblioDispatch</h3><p>Click here to connect your store to BiblioDispatch portal</p>',
     318                    position: {
     319                        edge: 'left',
     320                        align: 'center'
     321                    }
     322                }).pointer('open');
     323            }
     324        });
     325    ");
     326    }
    301327}
    302328add_action('admin_enqueue_scripts', 'wc_api_key_check_enqueue_custom_styles');
     
    501527
    502528//--------------Remove Webhook Starts  --------------------------------
     529
     530function biblio_send_deactivation_request($event_type = 'deactivate') {
     531
     532    $user_id = get_current_user_id();
     533    $payload = [
     534        'event'        => $event_type, // deactivate | uninstall
     535        'site_url'     => site_url(),
     536        'store_name'   => get_bloginfo('name'),
     537        'admin_email'  => get_option('admin_email'),
     538        'license_key'  => get_option('biblio_dispatch_license_key'),
     539        'timestamp'    => current_time('mysql'),
     540    ];
     541
     542    $args = [
     543        'method'  => 'POST',
     544        'timeout' => 20,
     545        'headers' => [
     546            'Content-Type' => 'application/json',
     547        ],
     548        'body' => wp_json_encode($payload),
     549    ];
     550
     551    $response = wp_remote_post(PLUGIN_DEACTIVATE_URL, $args);
     552
     553    if (is_wp_error($response)) {
     554        error_log('Deactivate API failed: ' . $response->get_error_message());
     555    } else {
     556        error_log('Deactivate API success: ' . wp_remote_retrieve_body($response));
     557    }
     558}
     559
     560// Deactivation hook: triggers when the plugin is uninstalled
    503561register_uninstall_hook(__FILE__, 'remove_webhook_from_woocommerce');
    504 
    505562// Deactivation hook: triggers when the plugin is deactivated
    506563register_deactivation_hook(__FILE__, 'remove_webhook_from_woocommerce');
    507 
    508564function remove_webhook_from_woocommerce() {
    509565    global $wpdb;
    510566    $user_id = get_current_user_id();
     567
     568    //delete_option('biblio_portal_clicked_' . $user_id);
     569    $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'biblio_portal_clicked_%'");
     570    biblio_send_deactivation_request('deactivate');
     571
    511572    $consumer_key_option = 'wc_api_consumer_key_' . $user_id;
    512573    $consumer_secret_option = 'wc_api_consumer_secret_' . $user_id;
     
    821882                                <?php if ( class_exists( 'WooCommerce' ) ) : ?>
    822883                                    <div class="submit">
    823                                         <button type="submit" id="connect" data-flag="<?php echo esc_attr($flag_value); ?>" value="Access Portal" class="button-primary dispatch-connect" style="float:left;">Access BiblioDispatch Portal</button>
     884                                        <button type="submit" id="connect" data-flag="<?php echo esc_attr($flag_value); ?>" value="Access Portal" class=" button-primary dispatch-btn dispatch-connect" style="float:left;">Access BiblioDispatch Portal</button>
    824885                                    </div>
    825886
     
    861922            <div class="submit">
    862923                <div>
    863                     <button type="button" id="save" value="Access Portal" class="button-primary" style="float:left">Save Details</button>
     924                    <button type="button" id="save" value="Access Portal" class="button-primary dispatch-btn" style="float:left">Save Details</button>
    864925                </div>
    865926                <div>
    866                     <button type="submit" id="connect" data-flag="<?php echo esc_attr($flag_value); ?>" value="Access Portal" class="button-primary dispatch-connect" style="float:left;margin-left:5%">Access BiblioDispatch Portal</button>
     927                    <button type="submit" id="connect" data-flag="<?php echo esc_attr($flag_value); ?>" value="Access Portal" class="button-primary dispatch-btn dispatch-connect" style="float:left;margin-left:5%">Access BiblioDispatch Portal</button>
    867928                </div>
    868929
     
    9981059    );
    9991060}
     1061
     1062add_action('wp_ajax_biblio_mark_portal_clicked', 'biblio_mark_portal_clicked');
     1063function biblio_mark_portal_clicked() {
     1064    $user_id = get_current_user_id();
     1065    update_option('biblio_portal_clicked_' . $user_id, 1);
     1066    wp_send_json_success();
     1067}
  • biblio-dispatch/trunk/css/style.css

    r3385792 r3486480  
    5858    border-left: 4px solid #0073aa;
    5959}
     60
     61.wp-pointer-content {
     62    border-radius: 12px !important;
     63    overflow: hidden;
     64}
     65
     66.wp-pointer-content {
     67    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
     68}
     69
     70.wp-pointer-content h3 {
     71    margin: 0;
     72}
     73
     74.wp-pointer-content p {
     75    padding: 12px 16px;
     76}
     77
     78.dispatch-btn {
     79    font-size: larger !important;
     80    padding: .3rem 1rem !important;
     81    border-radius: .5rem !important;
     82}
  • biblio-dispatch/trunk/js/custom-script.js

    r3484529 r3486480  
    11var registerUrl = '<?php echo esc_url(REGISTER_URL); ?>';
    2             // JavaScript to handle tab switching
    3             jQuery(document).ready(function($) {
    4                 document.getElementById('referer').value = document.referrer;
    5                
    6                 // Use localized data from PHP
    7                 const registerUrl = wcApiVars.register_url;
    8                 const apiKeysUrl = wcApiVars.api_keys_url;
    9                
    10                 // updateButtonText();
    11                 $('#generate_keys').on('click', function () {
    12                     // const apiKeysUrl = "<?php echo esc_url(admin_url('admin.php?page=wc-settings&tab=advanced&section=keys')); ?>";
    13                     window.location.href = apiKeysUrl;
     2// JavaScript to handle tab switching
     3jQuery(document).ready(function($) {
     4    document.getElementById('referer').value = window.location.origin;
     5
     6    // Use localized data from PHP
     7    const registerUrl = wcApiVars.register_url;
     8    const apiKeysUrl = wcApiVars.api_keys_url;
     9
     10    // updateButtonText();
     11    $('#generate_keys').on('click', function () {
     12        window.location.href = apiKeysUrl;
     13    });
     14    $('#save').on('click', async function (e) {
     15        e.preventDefault();
     16        await saveData(false);
     17
     18    });
     19
     20    $('.dispatch-connect').on('click', async function (e) {
     21        e.preventDefault();
     22        try {
     23            if ($(this).data('pointer')) {
     24                $(this).pointer('close');
     25            }
     26        } catch (e) {}
     27        var flagValue = $(this).data('flag');
     28        await saveData(true);
     29
     30    });
     31
     32    async function saveData(submitAfterSave)
     33    {
     34        var consumer_key = $('#consumer_key').val();
     35        var consumer_secret = $('#consumer_secret').val();
     36        var store_name = $('#store_name').val();
     37        var site_url = $('#site_url').val();
     38        var platform_id =$("#platform_id").val();
     39        var _wc_api_nonce = $('#_wc_api_nonce').val();
     40
     41        if (consumer_key && consumer_secret) {
     42            try {
     43                const response = await $.ajax({
     44                    url: wcApiVars.ajax_url,
     45                    type: 'POST',
     46                    data: {
     47                        action: 'wc_api_key_check_save_data',
     48                        consumer_key: consumer_key,
     49                        consumer_secret: consumer_secret,
     50                        store_name: store_name,
     51                        site_url: site_url,
     52                        _wc_api_nonce: _wc_api_nonce
     53                    }
    1454                });
    15                 $('#save').on('click', async function (e) {
    16                     e.preventDefault();
    17                     await saveData(false);
     55                if (response.success) {
     56                    toastr.success(response.data.message || 'Configurations saved successfully!');
    1857
    19                 });
     58                    // If save is successful and `submitAfterSave` is true, submit the form
     59                    if (submitAfterSave) {
     60                        $('#biblioDispatchPlugin').trigger('submit');
     61                    }
     62                } else if (response.data.statusCode == 401) {
     63                    toastr.error('Unauthorized: Invalid consumer key or secret.');
     64                } else {
     65                    toastr.error('Error: ' + (response.data.message || 'Something went wrong.'));
     66                }
     67            } catch (error) {
     68                toastr.error('AJAX Error: ' + error);
     69            }
     70        } else {
     71            toastr.warning('Please fill out all required fields.');
     72        }
    2073
    21                 $('.dispatch-connect').on('click', async function (e) {
    22                     e.preventDefault();
    23                     var flagValue = $('.dispatch-connect').data('flag');
    24                     await saveData(true);
     74    }
    2575
    26                 });
    27                
    28                 async function saveData(submitAfterSave)
    29                 {                   
    30                     var consumer_key = $('#consumer_key').val();
    31                     var consumer_secret = $('#consumer_secret').val();
    32                     var store_name = $('#store_name').val();
    33                     var site_url = $('#site_url').val();
    34                     var platform_id =$("#platform_id").val();
    35                     var _wc_api_nonce = $('#_wc_api_nonce').val();
    36                    
    37                      if (consumer_key && consumer_secret) {
    38                         try {
    39                             const response = await $.ajax({
    40                                 url: wcApiVars.ajax_url,
    41                                 type: 'POST',
    42                                 data: {
    43                                     action: 'wc_api_key_check_save_data',
    44                                     consumer_key: consumer_key,
    45                                     consumer_secret: consumer_secret,
    46                                     store_name: store_name,
    47                                     site_url: site_url,
    48                                     _wc_api_nonce: _wc_api_nonce
    49                                 }
    50                             });
    51                             if (response.success) {
    52                                 toastr.success(response.data.message || 'Configurations saved successfully!');
    53                                
    54                                 // If save is successful and `submitAfterSave` is true, submit the form
    55                                 if (submitAfterSave) {
    56                                     $('#biblioDispatchPlugin').trigger('submit');
    57                                 }
    58                             } else if (response.data.statusCode == 401) {
    59                                 toastr.error('Unauthorized: Invalid consumer key or secret.');
    60                             } else {
    61                                 toastr.error('Error: ' + (response.data.message || 'Something went wrong.'));
    62                             }
    63                         } catch (error) {
    64                             toastr.error('AJAX Error: ' + error);
    65                         }
    66                     } else {
    67                         toastr.warning('Please fill out all required fields.');
    68                     }
    69                    
    70                 }
    71             });
     76    jQuery(document).on('click', '.dispatch-connect', function () {
     77        jQuery.ajax({
     78            url: wcApiVars.ajax_url,
     79            method: 'POST',
     80            data: {
     81                action: 'biblio_mark_portal_clicked'
     82            }
     83        });
     84    });
     85
     86});
  • biblio-dispatch/trunk/readme.txt

    r3484529 r3486480  
    143143UI enhancements in plugin settings
    144144
     145= 1.3.3 =
     146added handling on deactivate and uninstall of the plugin
     147added UI guidance for users after coming on the settings page of the plugin
     148
    145149== A brief Markdown Example ==
    146150
Note: See TracChangeset for help on using the changeset viewer.