| 1 |
/* global jQuery, inlineEditPost */ |
| 2 |
|
| 3 |
jQuery( document ).ready( function ( $ ) { |
| 4 |
// it is a copy of the inline edit function |
| 5 |
const wpInlineEditFunction = inlineEditPost.edit; |
| 6 |
// we overwrite the it with our own |
| 7 |
inlineEditPost.edit = function ( postId ) { |
| 8 |
// let's merge arguments of the original function |
| 9 |
wpInlineEditFunction.apply( this, arguments ); |
| 10 |
// get the post ID from the argument |
| 11 |
let id = 0; |
| 12 |
if ( typeof postId === 'object' ) { |
| 13 |
// if it is object, get the ID number |
| 14 |
id = parseInt( this.getId( postId ) ); |
| 15 |
} |
| 16 |
//if post id exists |
| 17 |
if ( id > 0 ) { |
| 18 |
// add rows to variables |
| 19 |
const specificPostEditRow = $( '#edit-' + id ), |
| 20 |
specificPostRow = $( '#post-' + id ), |
| 21 |
productPrice = $( '.column-price', specificPostRow ) |
| 22 |
.text() |
| 23 |
.substring( 1 ); // remove $ sign |
| 24 |
// add rows to variables |
| 25 |
let featuredProduct = false; // let's say by default checkbox is unchecked |
| 26 |
// check if the Featured Product column says Yes |
| 27 |
if ( $( '.column-featured', specificPostRow ).text() === 'Yes' ) |
| 28 |
featuredProduct = true; |
| 29 |
// populate the inputs with column data |
| 30 |
$( ':input[name="price"]', specificPostEditRow ).val( |
| 31 |
productPrice |
| 32 |
); |
| 33 |
$( ':input[name="featured"]', specificPostEditRow ).prop( |
| 34 |
'checked', |
| 35 |
featuredProduct |
| 36 |
); |
| 37 |
} |
| 38 |
}; |
| 39 |
} ); |
| 40 |
|