Plugin Directory

Changeset 2499266


Ignore:
Timestamp:
03/19/2021 08:30:24 AM (5 years ago)
Author:
frile
Message:

Version 3.2

Location:
bulk-remove-posts-from-category
Files:
8 added
3 edited

Legend:

Unmodified
Added
Removed
  • bulk-remove-posts-from-category/trunk/js/wpbulkremove.js

    r2366790 r2499266  
    77
    88jQuery(document).on('change', '#remcat input', function() {
    9     var $bulktype = wpbulkremove.wpbulkremove_type;
    10     var $bulktax = wpbulkremove.wpbulkremove_tax;
    11         if($bulktype == 'edit-post'){
    12             var $ini = 'post_category[]';
    13         } else if($bulktype == 'edit-product') {
    14             var $ini = 'tax_input[product_cat][]';
    15         } else {
    16             var $ini = 'tax_input['+$bulktax+'][]';
    17         }
    18  var $repl = 'post_out_category';
    19  var $list = jQuery(this).closest('.inline-edit-col').find('ul.cat-checklist');
    20         if (jQuery(this).is(':checked')) {
     9
     10    $this = jQuery(this);
     11   
     12    var $repl = 'post_out_category';
     13    var $wraper = $this.closest('.inline-edit-col');
     14   
     15    jQuery('.cat-checklist', $wraper).each(function (t, ul) {       
     16            $list = jQuery(ul);
     17   
     18        if ($this.is(':checked')) {
    2119            $list.addClass('red');
    2220            jQuery('#remcat').addClass('red');
    23             $list.find('input').each(function() {
    24                 jQuery(this).attr('name',$repl);
     21            $list.find('input').each(function(i, li) {
     22                jQuery(li).attr('name',$repl);
    2523            });
    2624        } else {
    2725            $list.removeClass('red');
     26            $ininame = $list.prev('input').attr('name');
    2827            jQuery('#remcat').removeClass('red');
    29             $list.find('input').each(function() {
    30                 jQuery(this).attr('name',$ini);
     28            $list.find('input').each(function(i, li) {
     29                jQuery(li).attr('name',$ininame);
    3130            });
    3231        }
     32       
     33    });
    3334});
    3435jQuery(function($){
    35     $( 'body' ).on( 'click', 'input[name="bulk_edit"]', function() {
     36    $( 'body' ).on( 'click', 'input[name="bulk_edit"]', function(e) {
    3637       
    3738        $( this ).after('<span class="spinner is-active"></span>');
     39        //$( this ).prop('disabled', true);
    3840 
    39         var $bulktype = wpbulkremove.wpbulkremove_type;
    40         var $bulktax = wpbulkremove.wpbulkremove_tax;
    4141        var bulk_edit_row = $( 'tr#bulk-edit' );
    4242        remcat = bulk_edit_row.find( 'input[name="remove_cat"]' ).is(':checked') ? 1 : 0;
    4343   
    4444        if(remcat == 1){
    45                 post_ids = new Array();
    46                 catout = new Array();
    47                 bulk_edit_row.find('input[name="post_out_category"]:checked').each(function() {
    48                    catout.push($(this).val());
     45                var post_ids = new Array();
     46                var catout = new Array();
     47                $('#bulk-edit .inline-edit-categories .cat-checklist').each(function(i, li) {
     48                    taxname = $(li).prev().attr('name');
     49                            $(li).find('li label input[name="post_out_category"]:checked').each(function(ii, cat) {                           
     50                                var cat_id_add = $(cat).val();
     51                                    catout.push({
     52                                        'taxonomy': taxname,
     53                                        'taxonomy_id': cat_id_add
     54                                    });
     55                            });
    4956                });
    50                
    5157     
    5258                bulk_edit_row.find( '#bulk-titles' ).children().each( function() {
    5359                    post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) );
    5460                });
    55                
    56                
     61                       
    5762                $.ajax({
    58                     url: ajaxurl,
     63                    url: wpbulkremove.ajax_url,
    5964                    type: 'POST',
    60                     async: true,
     65                    async: true,                   
    6166                    cache: false,
    6267                    data: {
    6368                        action: 'masterns_bulk_remove_cat',
    6469                        post_ids: post_ids,
    65                         catout: catout,
    66                         remcat: remcat,
    67                         type: $bulktype,
    68                         taxonomy: $bulktax
    69                     }               
     70                        catout: catout,
     71                        security: wpbulkremove.security,
     72                    },
     73                    success:function(data) {
     74                        return false;
     75                    },
     76                    error: function(errorThrown){
     77                        console.log(errorThrown);
     78                    }
    7079                });
    7180        }
  • bulk-remove-posts-from-category/trunk/readme.txt

    r2369001 r2499266  
    44Tags: post categories, bulk edit, bulk remove, product categories
    55Requires at least: 4.6
    6 Tested up to: 5.5
    7 Stable tag: 3.1.1
    8 WC tested up to: 4.4.1
     6Tested up to: 5.7
     7Stable tag: 3.2
     8WC tested up to: 5.1.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2020This plugin extends default Bulk Editor so you can remove Categories from posts.
    2121
    22 The plugin works just with default Post type, Woocommerce products and any other Custom Post Type.
     22The plugin works with default Post type, Woocommerce products and any other Custom Post Type. Supports multiple taxonomies per post.
    2323
    2424== Installation ==
     
    3838
    3939== Changelog ==
     40
     41= 3.2 =
     42* Support for multiple post taxonomies
    4043
    4144= 3.1.1 =
  • bulk-remove-posts-from-category/trunk/wpbulkremove.php

    r2368998 r2499266  
    77 * Plugin URI:   https://masterns-studio.com/code-factory/wordpress-plugin/bulk-remove-from-category/
    88 * Description: Bulk remove posts from category
    9  * Version: 3.1.1
     9 * Version: 3.2
    1010 * Author: MasterNs
    1111 * Author URI: https://masterns-studio.com/
    1212 * License: GPLv2 or later
    1313 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    14  * Tested up to: 5.5
     14 * Tested up to: 5.7
    1515 * Text Domain: bulk-remove-posts-from-category
    1616 * Domain Path: languages/
    1717 *
    18  * WC tested up to: 4.4.1
     18 * WC tested up to: 5.1.0
    1919 *
    2020 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
     
    3939add_action( 'admin_enqueue_scripts', 'wpbulkremove_enqueue' );
    4040function wpbulkremove_enqueue($hook) {
    41     $screen = get_current_screen();
    42     $can_run = false;
    43     $cpt_tax = '';
    4441   
    45     if (( 'edit-post' === $screen->id )||('edit-product' === $screen->id)) {
    46         $can_run = true;   
    47     } else {
    48         $post_type = $screen->post_type;
    49         $taxonomies = get_object_taxonomies($post_type, 'objects');
    50             foreach($taxonomies as $tax){
    51                 if($tax->hierarchical){
    52                     $can_run = true;
    53                     $cpt_tax = $tax->name;
    54                 }
    55             }
    56     }
    57    
    58     if($can_run){
    5942        $my_js_ver  = date("ymd.Gis", filemtime( plugin_dir_path( __FILE__ ) . '/js/wpbulkremove.js' ));
    6043        $my_css_ver = date("ymd.Gis", filemtime( plugin_dir_path( __FILE__ ) . '/css/wpbulkremove_style.css' ));
     
    6447        $wpbulkremove_array = array(
    6548            'wpbulkremove_string' => __( 'Remove from category', 'bulk-remove-posts-from-category' ),
    66             'wpbulkremove_type' => $screen->id,
    67             'wpbulkremove_tax' => $cpt_tax
     49            'ajax_url'  => admin_url( 'admin-ajax.php' ),       
     50            'security'  => wp_create_nonce( 'brfc_security_nonce' )
    6851        );
    6952        wp_localize_script( 'wpbulkremove-js', 'wpbulkremove', $wpbulkremove_array );
    70     }
     53
    7154}
    7255
     
    8063function masterns_bulk_remove_cat_edit_hook() {
    8164
     65    if ( ! wp_verify_nonce( $_POST['security'], 'brfc_security_nonce' ) ) {
     66        wp_send_json_error( 'Invalid security token sent.' );       
     67        wp_die();   
     68    }
     69   
    8270    if( empty( $_POST[ 'post_ids' ] ) ) {
    8371        die();
     
    8775    }
    8876   
    89     if( $_POST[ 'type' ] == 'edit-post' ) {
    90         $bulktax = 'category';
    91     } elseif($_POST[ 'type' ] == 'edit-product') {
    92         $bulktax = 'product_cat';
    93     } else {
    94         $bulktax = $_POST[ 'taxonomy' ];
    95     }
    96  
     77
    9778    foreach( $_POST[ 'post_ids' ] as $id ) {
    9879        $post_id = (int)$id;
    9980        foreach( $_POST[ 'catout' ] as $cat ) {
    100             $cat_id = (int)$cat;           
    101             $rem = wp_remove_object_terms( $post_id, $cat_id, $bulktax );
     81            $cat_tax = str_replace("[]", "", $cat['taxonomy']);
     82                if (strpos($cat_tax, 'tax_input[') !== false) {
     83                    $cat_tax = str_replace("tax_input[", "", $cat_tax);
     84                    $cat_tax = str_replace("]", "", $cat_tax);
     85                }
     86                if($cat_tax == 'post_category'){
     87                    $cat_tax = 'category';
     88                }
     89            $cat_id = (int)$cat['taxonomy_id'];
     90            $rem = wp_remove_object_terms( $post_id, $cat_id, $cat_tax );
    10291        }
    10392    }
Note: See TracChangeset for help on using the changeset viewer.