Skip to content
Permalink
Browse files

Deleting product boxes now works on both front-end and in db

  • Loading branch information...
MJGrant committed Jun 13, 2019
1 parent 105d8c1 commit 56823a70d2d5576558ccf96aa1e78be0501900ce
Showing with 32 additions and 3 deletions.
  1. +11 −2 amazin-product-box/amazin-product-box.php
  2. +21 −1 amazin-product-box/scripts.js
@@ -13,8 +13,11 @@
if ( is_admin() ){ // admin actions
add_action( 'admin_menu', 'amazin_plugin_menu' );
add_action( 'init', 'create_post_type' );
add_action( 'wp_ajax_amazin_delete_post', 'amazin_delete_post' );
$jsurl = plugin_dir_url(__FILE__) . 'scripts.js';
wp_enqueue_script('scripts', $jsurl, array('jquery'), 1.05);
wp_enqueue_script('scripts', $jsurl, array('jquery'), 1.21);
wp_localize_script('scripts', 'MyAjax', array('ajaxurl' => admin_url('admin-ajax.php') ) );
} else {
// non-admin enqueues, actions, and filters
}
@@ -104,7 +107,7 @@ function amazin_render_table() {
foreach ($productBoxes as $productBox):
$id=$productBox->ID;
?>
<tr>
<tr id="<?php echo "row-" . $id; ?>">
<!-- for loop through saved boxes -->
<td>[shortcode here]</td>
<td><?php echo get_the_title($id); ?></td>
@@ -172,4 +175,10 @@ function post_new_product_box() {
}
}
}
function amazin_delete_post( ) {
wp_delete_post($_REQUEST['id']);
echo 'success';
die();
}
?>
@@ -2,7 +2,27 @@ jQuery ( document ).ready ( function ( $ ) {
'use strict';
$ ( '#admin-table').on( 'click', '.delete-button', function(e) {
console.log("Gonna delete a product box with ID:", e.target.id);
} );
var id = e.target.id;
var tableRow = "#row-"+id;

$.ajax({
type: 'post',
url: MyAjax.ajaxurl,
data: {
action: 'amazin_delete_post',
id: id
},
success: function ( result ) {
if ( result === 'success' ) {
$ ( tableRow ).fadeOut( function() {
tableRow.remove();
});
console.log("successfully removed post");
}
}
});
return false;
});

$ ( '#admin-table').on( 'click', '.edit-button', function(e) {
console.log("Gonna edit a product box with ID:", e.target.id);

0 comments on commit 56823a7

Please sign in to comment.
You can’t perform that action at this time.