Skip to content
Permalink
Browse files

Hooked up console log to edit and delete button, verified post ID is …

…successfully passed to both
  • Loading branch information...
MJGrant committed Jun 12, 2019
1 parent dba8b98 commit 105d8c1a37da866a5aa267d3502b595a2b58dfe2
Showing with 18 additions and 5 deletions.
  1. +7 −5 amazin-product-box/amazin-product-box.php
  2. +11 −0 amazin-product-box/scripts.js
@@ -13,6 +13,8 @@
if ( is_admin() ){ // admin actions
add_action( 'admin_menu', 'amazin_plugin_menu' );
add_action( 'init', 'create_post_type' );
$jsurl = plugin_dir_url(__FILE__) . 'scripts.js';
wp_enqueue_script('scripts', $jsurl, array('jquery'), 1.05);
} else {
// non-admin enqueues, actions, and filters
}
@@ -75,7 +77,6 @@ function amazin_render_form() {

<input type="submit" name="submit"/>
</form>

</div>
<?php
return;
@@ -87,7 +88,7 @@ function amazin_render_table() {
);
$productBoxes = get_posts($args);
?>
<table>
<table id="admin-table">
<thead>
<tr>
<th>Shortcode</th>
@@ -101,14 +102,15 @@ function amazin_render_table() {
<?php
if ($productBoxes):
foreach ($productBoxes as $productBox):
$id=$productBox->ID;
?>
<tr>
<!-- for loop through saved boxes -->
<td>[shortcode here]</td>
<td><?php echo get_the_title($productBox->ID); ?></td>
<td><?php echo get_the_title($id); ?></td>
<td><?php echo get_the_author_meta( 'display_name', $productBox->post_author ); ?></td>
<td><?php echo get_the_modified_time('M d, Y h:i:s A', $productBox->ID ); ?></td>
<td><button>Edit</button> <button>Delete</button></td>
<td><?php echo get_the_modified_time('M d, Y h:i:s A', $id ); ?></td>
<td><input type="button" id="<?php echo $id; ?>" class="edit-button" value="Edit"/> <input type="button" id="<?php echo $id; ?>" class="delete-button" value="Delete"/></td>
</tr>
<?php endforeach; wp_reset_postdata(); ?>
<?php endif; ?>
@@ -0,0 +1,11 @@
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);
} );

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

} );

0 comments on commit 105d8c1

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