Plugin Directory

Changeset 2532824


Ignore:
Timestamp:
05/17/2021 09:29:27 AM (5 years ago)
Author:
visser
Message:
  • Added: Delete Products by Product Status
  • Added: Setting option to show/hide Delete Permanently Product button and menu item (thanks @eftcolumbus)
  • Added: Opt-in Freemius Plugin usage monitoring
Location:
woocommerce-store-toolkit/trunk
Files:
190 added
8 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-store-toolkit/trunk/includes/admin.php

    r2257020 r2532824  
    131131    }
    132132
     133    // Check Settings option
     134    $permanently_delete_products = woo_st_get_option( 'permanently_delete_products', 1 );
     135    if( empty( $permanently_delete_products ) )
     136        return $actions;
     137
    133138    $actions['permanent_delete'] = '<span class="delete"><a href="' . wp_nonce_url( admin_url( 'edit.php?post_type=product&ids=' . $post->ID . '&action=permanent_delete_product' ), 'woo_st-permanent_delete_' . $post->ID ) . '" title="' . esc_attr__( 'Permanently delete this product', 'woocommerce-store-toolkit' ) . '" rel="permalink">' .  __( 'Delete Permanently', 'woocommerce' ) . '</a></span>';
    134139
     
    175180    }
    176181
    177     $post_status = ( isset( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : false );
    178     if( $post_type == 'product' && ( $post_status <> 'trash' ) ) { ?>
     182    $post_status = ( isset( $_REQUEST['post_status'] ) ? sanitize_text_field( $_REQUEST['post_status'] ) : false );
     183    if(
     184        $post_type == 'product' &&
     185        ( $post_status <> 'trash' )
     186    ) {
     187
     188        // Check Settings option
     189        $permanently_delete_products = woo_st_get_option( 'permanently_delete_products', 1 );
     190        if( empty( $permanently_delete_products ) )
     191            return;
     192
     193?>
    179194<script type="text/javascript">
    180195    jQuery(document).ready(function() {
     196        // Add Delete Permanently to bulk actions menu on the Products screen
    181197        jQuery('<option>').val('permanent_delete').text('<?php _e( 'Delete Permanently' )?>').appendTo("select[name='action']");
    182198        jQuery('<option>').val('permanent_delete').text('<?php _e( 'Delete Permanently' )?>').appendTo("select[name='action2']");
     
    502518
    503519            $products = woo_st_return_count( 'product' );
     520            if( !empty( $products ) ) {
     521                $product_statuses = woo_st_get_product_statuses();
     522            }
    504523            $images = woo_st_return_count( 'product_image' );
    505524            $tags = woo_st_return_count( 'product_tag' );
     
    573592        case 'settings':
    574593            $troubleshooting_url = 'https://www.visser.com.au/documentation/store-toolkit/';
     594
     595            $permanently_delete_products = woo_st_get_option( 'permanently_delete_products', 1 );
     596
    575597            $enable_cron = woo_st_get_option( 'enable_cron', 0 );
    576598            $secret_key = woo_st_get_option( 'secret_key', '' );
  • woocommerce-store-toolkit/trunk/includes/functions.php

    r2390340 r2532824  
    183183
    184184    }
     185   
     186    function woo_st_get_product_statuses() {
     187
     188/*
     189        $product_statuses = get_post_statuses();
     190        // $product_statuses = get_post_stati();
     191        if( !empty( $product_statuses ) ) {
     192            foreach( $product_statuses as $key => $product_status ) {
     193                $product_statuses[$key]->count =
     194            }
     195        }
     196*/
     197        $post_type = 'product';
     198        $product_statuses = wp_count_posts( $post_type );
     199        // Trim off WooCommerce Order Statuses
     200        if( !empty( $product_statuses ) ) {
     201            $product_statuses = (array)$product_statuses;
     202            foreach( $product_statuses as $product_status => $product_count ) {
     203                if(
     204                    strstr( $product_status, 'wc-' ) !== false ||
     205                    strstr( $product_status, 'request-' ) !== false
     206                ) {
     207                    unset( $product_statuses[$product_status] );
     208                }
     209            }
     210        }
     211        return $product_statuses;
     212
     213    }
    185214
    186215    function woo_st_get_order_statuses() {
     
    476505    function woo_st_settings_save() {
    477506
     507        // Permanently Delete Products bulk action
     508        woo_st_update_option( 'permanently_delete_products', ( isset( $_POST['permanently_delete_products'] ) ? absint( (int)$_POST['permanently_delete_products'] ) : 1 ) );
     509
    478510        // CRON settings
    479511        $enable_cron = absint( $_POST['enable_cron'] );
     
    594626                'numberposts' => 100
    595627            );
     628
     629            // Check for Product Status filter
     630            if( !empty( $data['product_status'] ) ) {
     631                $args['post_status'] = $data['product_status'];
     632            }
    596633
    597634            // Allow Plugin/Theme authors to add support for tactical nukes
  • woocommerce-store-toolkit/trunk/readme.txt

    r2509934 r2532824  
    66Requires at least: 2.9.2
    77Tested up to: 5.7
    8 Stable tag: 2.3
     8Stable tag: 2.3.1
    99License: GPLv2 or later
    1010
     
    6464* WooCommerce Logs
    6565* Advanced Google Product Feed
     66* Delete Products by Product Status
    6667* Delete Products by Product Category
    6768* Delete Orders by Order Status
     
    121122
    122123== Changelog ==
     124
     125= 2.3.1 =
     126* Added: Delete Products by Product Status
     127* Added: Setting option to show/hide Delete Permanently Product button and menu item (thanks @eftcolumbus)
     128* Added: Opt-in Freemius Plugin usage monitoring
    123129
    124130= 2.3 =
  • woocommerce-store-toolkit/trunk/store-toolkit.php

    r2509934 r2532824  
    44Plugin URI: https://wordpress.org/plugins/woocommerce-store-toolkit/
    55Description: Store Toolkit includes a growing set of commonly-used WooCommerce administration tools aimed at web developers and store maintainers.
    6 Version: 2.3
     6Version: 2.3.1
    77Author: Visser Labs
    88Author URI: http://www.visser.com.au/about/
     
    1313
    1414WC requires at least: 2.3
    15 WC tested up to: 5.1.0
     15WC tested up to: 5.3.0
    1616*/
    1717
     
    2525include_once( WOO_ST_PATH . 'common/common.php' );
    2626include_once( WOO_ST_PATH . 'includes/functions.php' );
     27include_once( WOO_ST_PATH . 'includes/formatting.php' );
     28include_once( WOO_ST_PATH . 'includes/freemius.php' );
    2729if( defined( 'WP_CLI' ) && WP_CLI )
    2830    include_once( WOO_ST_PATH . 'includes/wp-cli.php' );
     
    8688
    8789                // WooCommerce
    88                 if( isset( $_POST['woo_st_products'] ) )
    89                     $response = woo_st_clear_dataset( 'product' );
     90                if( isset( $_POST['woo_st_products'] ) ) {
     91                    $product_status = ( isset( $_POST['woo_st_products_status'] ) ? array_map( 'sanitize_text_field', $_POST['woo_st_products_status'] ) : false );
     92                    $args = array(
     93                        'product_status' => array_values( $product_status )
     94                    );
     95                    $response = woo_st_clear_dataset( 'product', $args );
     96                }
    9097                if( isset( $_POST['woo_st_products_category'] ) ) {
    9198                    $categories = $_POST['woo_st_products_category'];
  • woocommerce-store-toolkit/trunk/templates/admin/tabs-nuke.php

    r1962510 r2532824  
    11<ul class="subsubsub">
    22    <li><a href="#empty-woocommerce-tables"><?php _e( 'Empty WooCommerce Tables', 'woocommerce-store-toolkit' ); ?></a> |</li>
     3    <li><a href="#empty-product-by-status"><?php _e( 'Delete Products by Product Status', 'woocommerce-store-toolkit' ); ?></a> |</li>
    34    <li><a href="#empty-product-by-category"><?php _e( 'Delete Products by Product Category', 'woocommerce-store-toolkit' ); ?></a> |</li>
    45    <li><a href="#delete-sales-by-sale-status"><?php _e( 'Delete Orders by Order Status', 'woocommerce-store-toolkit' ); ?></a> |</li>
     
    248249        <!-- .postbox -->
    249250
     251        <div id="empty-product-by-status" class="postbox">
     252            <h3 class="hndle"><?php _e( 'Delete Products by Product Status', 'woocommerce-store-toolkit' ); ?></h3>
     253            <div class="inside">
     254<?php if( $products ) { ?>
     255                <p class="description"><?php _e( 'Remove Products based on the Product Status by selecting the the Product Status below, then click Remove to permanently remove those Products.', 'woocommerce-store-toolkit' ); ?></p>
     256                <ul>
     257<?php if( $product_statuses ) { ?>
     258    <?php foreach( $product_statuses as $product_status => $product_count ) { ?>
     259                    <li>
     260                        <label>
     261                            <input type="checkbox" name="woo_st_products_status[<?php echo $product_status; ?>]" value="<?php echo $product_status; ?>"<?php if( $product_count == 0 ) { ?> disabled="disabled"<?php } ?> />
     262                            <?php echo woo_st_format_post_status( $product_status ); ?> (<?php echo $product_count; ?>)
     263                        </label>
     264                    </li>
     265    <?php } ?>
     266<?php } else { ?>
     267                <li><?php _e( 'No Product Status\'s were found.', 'woocommerce-store-toolkit' ); ?></li>
     268<?php } ?>
     269                </ul>
     270                <p class="submit">
     271                    <input type="button" id="empty-products-by-status-remove" value="<?php _e( 'Remove', 'woocommerce-store-toolkit' ); ?>" class="button-primary confirm-button" data-confirm="<?php _e( 'This will permanently remove Products matching the selected Product Status. Are you sure you want to proceed?', 'woocommerce-store-toolkit' ); ?>" />
     272                </p>
     273<?php } else { ?>
     274                <p><?php _e( 'No Products were found.', 'woocommerce-store-toolkit' ); ?></p>
     275<?php } ?>
     276            </div>
     277        </div>
     278        <!-- .postbox -->
    250279        <div id="empty-product-by-category" class="postbox">
    251280            <h3 class="hndle"><?php _e( 'Delete Products by Product Category', 'woocommerce-store-toolkit' ); ?></h3>
  • woocommerce-store-toolkit/trunk/templates/admin/tabs-overview.php

    r1962510 r2532824  
    33<ul class="ul-disc">
    44    <li><a href="<?php echo esc_url( add_query_arg( 'tab', 'nuke' ) ); ?>#empty-woocommerce-tables"><?php _e( 'Empty WooCommerce Tables', 'woocommerce-store-toolkit' ); ?></a></li>
     5    <li><a href="<?php echo esc_url( add_query_arg( 'tab', 'nuke' ) ); ?>#empty-product-by-status"><?php _e( 'Delete Products by Product Status', 'woocommerce-store-toolkit' ); ?></a></li>
    56    <li><a href="<?php echo esc_url( add_query_arg( 'tab', 'nuke' ) ); ?>#empty-product-by-category"><?php _e( 'Delete Products by Product Category', 'woocommerce-store-toolkit' ); ?></a></li>
    67    <li><a href="<?php echo esc_url( add_query_arg( 'tab', 'nuke' ) ); ?>#delete-sales-by-sale-status"><?php _e( 'Delete Orders by Order Status', 'woocommerce-store-toolkit' ); ?></a></li>
  • woocommerce-store-toolkit/trunk/templates/admin/tabs-settings.php

    r1577286 r2532824  
    11<ul class="subsubsub">
     2    <li><a href="#general-settings"><?php _e( 'General Settings', 'woocommerce-store-toolkit' ); ?></a> |</li>
    23    <li><a href="#cron-nuke"><?php _e( 'CRON Nuke', 'woocommerce-store-toolkit' ); ?></a></li>
    34</ul>
     
    89    <table class="form-table">
    910        <tbody>
     11
     12            <tr id="general-settings">
     13                <td colspan="2" style="padding:0;">
     14                    <h3><div class="dashicons dashicons-admin-settings"></div>&nbsp;<?php _e( 'General Settings', 'woocommerce-store-toolkit' ); ?></h3>
     15                    <p class="description"><?php _e( 'Manage options across Store Toolkit from this screen.', 'woocommerce-store-toolkit' ); ?></p>
     16                </td>
     17            </tr>
     18            <tr>
     19                <th>
     20                    <label for="permanently_delete_products"><?php _e( 'Products bulk action: Delete Permanently', 'woocommerce-store-importer' ); ?></label>
     21                </th>
     22                <td>
     23                    <select id="permanently_delete_products" name="permanently_delete_products">
     24                        <option value="1"<?php selected( $permanently_delete_products, 1 ); ?>><?php _e( 'Show Delete Permanently button and menu item', 'woocommerce-store-importer' ); ?></option>
     25                        <option value="0"<?php selected( $permanently_delete_products, 0 ); ?>><?php _e( 'Hide Delete Permanently button and menu item', 'woocommerce-store-importer' ); ?></option>
     26                    </select>
     27                    <p class="description"><?php _e( 'Store Toolkit adds a Delete Permanently button and Bulk actions menu item to the Products screen. By default this option is turned on.', 'woocommerce-store-toolkit' ); ?></p>
     28                </td>
     29            </tr>
    1030
    1131            <tr id="cron-exports">
  • woocommerce-store-toolkit/trunk/templates/admin/toolkit.js

    r1890655 r2532824  
    2424    });
    2525
     26    $j('#empty-products-by-status-remove').click(function (e) {
     27        var checked_items = $j('#empty-product-by-status input:checked').length;
     28        if( !checked_items ) {
     29            alert( 'At least one Product Status needs to be selected.' );
     30            e.stopImmediatePropagation();
     31            return;
     32        }
     33        $j('#products').attr('checked', true);
     34    });
    2635    $j('#empty-product-by-category-remove').click(function () {
    2736        var checked_items = $j('#empty-product-by-category input:checked').length;
Note: See TracChangeset for help on using the changeset viewer.