Changeset 2499266
- Timestamp:
- 03/19/2021 08:30:24 AM (5 years ago)
- Location:
- bulk-remove-posts-from-category
- Files:
-
- 8 added
- 3 edited
-
tags/3.2 (added)
-
tags/3.2/css (added)
-
tags/3.2/css/wpbulkremove_style.css (added)
-
tags/3.2/js (added)
-
tags/3.2/js/wpbulkremove.js (added)
-
tags/3.2/license.txt (added)
-
tags/3.2/readme.txt (added)
-
tags/3.2/wpbulkremove.php (added)
-
trunk/js/wpbulkremove.js (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/wpbulkremove.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bulk-remove-posts-from-category/trunk/js/wpbulkremove.js
r2366790 r2499266 7 7 8 8 jQuery(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')) { 21 19 $list.addClass('red'); 22 20 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); 25 23 }); 26 24 } else { 27 25 $list.removeClass('red'); 26 $ininame = $list.prev('input').attr('name'); 28 27 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); 31 30 }); 32 31 } 32 33 }); 33 34 }); 34 35 jQuery(function($){ 35 $( 'body' ).on( 'click', 'input[name="bulk_edit"]', function( ) {36 $( 'body' ).on( 'click', 'input[name="bulk_edit"]', function(e) { 36 37 37 38 $( this ).after('<span class="spinner is-active"></span>'); 39 //$( this ).prop('disabled', true); 38 40 39 var $bulktype = wpbulkremove.wpbulkremove_type;40 var $bulktax = wpbulkremove.wpbulkremove_tax;41 41 var bulk_edit_row = $( 'tr#bulk-edit' ); 42 42 remcat = bulk_edit_row.find( 'input[name="remove_cat"]' ).is(':checked') ? 1 : 0; 43 43 44 44 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 }); 49 56 }); 50 51 57 52 58 bulk_edit_row.find( '#bulk-titles' ).children().each( function() { 53 59 post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) ); 54 60 }); 55 56 61 57 62 $.ajax({ 58 url: ajaxurl,63 url: wpbulkremove.ajax_url, 59 64 type: 'POST', 60 async: true, 65 async: true, 61 66 cache: false, 62 67 data: { 63 68 action: 'masterns_bulk_remove_cat', 64 69 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 } 70 79 }); 71 80 } -
bulk-remove-posts-from-category/trunk/readme.txt
r2369001 r2499266 4 4 Tags: post categories, bulk edit, bulk remove, product categories 5 5 Requires at least: 4.6 6 Tested up to: 5. 57 Stable tag: 3. 1.18 WC tested up to: 4.4.16 Tested up to: 5.7 7 Stable tag: 3.2 8 WC tested up to: 5.1.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 20 20 This plugin extends default Bulk Editor so you can remove Categories from posts. 21 21 22 The plugin works just with default Post type, Woocommerce products and any other Custom Post Type.22 The plugin works with default Post type, Woocommerce products and any other Custom Post Type. Supports multiple taxonomies per post. 23 23 24 24 == Installation == … … 38 38 39 39 == Changelog == 40 41 = 3.2 = 42 * Support for multiple post taxonomies 40 43 41 44 = 3.1.1 = -
bulk-remove-posts-from-category/trunk/wpbulkremove.php
r2368998 r2499266 7 7 * Plugin URI: https://masterns-studio.com/code-factory/wordpress-plugin/bulk-remove-from-category/ 8 8 * Description: Bulk remove posts from category 9 * Version: 3. 1.19 * Version: 3.2 10 10 * Author: MasterNs 11 11 * Author URI: https://masterns-studio.com/ 12 12 * License: GPLv2 or later 13 13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 14 * Tested up to: 5. 514 * Tested up to: 5.7 15 15 * Text Domain: bulk-remove-posts-from-category 16 16 * Domain Path: languages/ 17 17 * 18 * WC tested up to: 4.4.118 * WC tested up to: 5.1.0 19 19 * 20 20 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU … … 39 39 add_action( 'admin_enqueue_scripts', 'wpbulkremove_enqueue' ); 40 40 function wpbulkremove_enqueue($hook) { 41 $screen = get_current_screen();42 $can_run = false;43 $cpt_tax = '';44 41 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){59 42 $my_js_ver = date("ymd.Gis", filemtime( plugin_dir_path( __FILE__ ) . '/js/wpbulkremove.js' )); 60 43 $my_css_ver = date("ymd.Gis", filemtime( plugin_dir_path( __FILE__ ) . '/css/wpbulkremove_style.css' )); … … 64 47 $wpbulkremove_array = array( 65 48 'wpbulkremove_string' => __( 'Remove from category', 'bulk-remove-posts-from-category' ), 66 ' wpbulkremove_type' => $screen->id,67 ' wpbulkremove_tax' => $cpt_tax49 'ajax_url' => admin_url( 'admin-ajax.php' ), 50 'security' => wp_create_nonce( 'brfc_security_nonce' ) 68 51 ); 69 52 wp_localize_script( 'wpbulkremove-js', 'wpbulkremove', $wpbulkremove_array ); 70 } 53 71 54 } 72 55 … … 80 63 function masterns_bulk_remove_cat_edit_hook() { 81 64 65 if ( ! wp_verify_nonce( $_POST['security'], 'brfc_security_nonce' ) ) { 66 wp_send_json_error( 'Invalid security token sent.' ); 67 wp_die(); 68 } 69 82 70 if( empty( $_POST[ 'post_ids' ] ) ) { 83 71 die(); … … 87 75 } 88 76 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 97 78 foreach( $_POST[ 'post_ids' ] as $id ) { 98 79 $post_id = (int)$id; 99 80 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 ); 102 91 } 103 92 }
Note: See TracChangeset
for help on using the changeset viewer.