admin-dashboard.js
6 years ago
admin-post.js
6 years ago
admin-quick-edit.js
6 years ago
admin-settings.js
6 years ago
admin-widgets.js
6 years ago
chart.min.js
6 years ago
frontend.js
6 years ago
gutenberg.min.js
6 years ago
admin-quick-edit.js
65 lines
| 1 | ( function( $ ) { |
| 2 | |
| 3 | // we create a copy of the WP inline edit post function |
| 4 | var $wp_inline_edit = inlineEditPost.edit; |
| 5 | |
| 6 | // and then we overwrite the function with our own code |
| 7 | inlineEditPost.edit = function( id ) { |
| 8 | console.log( 'edit' ); |
| 9 | // call the original WP edit function |
| 10 | // we don't want to leave WordPress hanging |
| 11 | $wp_inline_edit.apply( this, arguments ); |
| 12 | |
| 13 | // get the post ID |
| 14 | var $post_id = 0; |
| 15 | |
| 16 | if ( typeof ( id ) == 'object' ) |
| 17 | $post_id = parseInt( this.getId( id ) ); |
| 18 | |
| 19 | if ( $post_id > 0 ) { |
| 20 | // define the edit row |
| 21 | var $edit_row = $( '#edit-' + $post_id ), |
| 22 | $post_row = $( '#post-' + $post_id ); |
| 23 | |
| 24 | // get the data |
| 25 | var $post_views = $( '.column-post_views', $post_row ).text(); |
| 26 | |
| 27 | // populate the data |
| 28 | $( ':input[name="post_views"]', $edit_row ).val( $post_views ); |
| 29 | $( ':input[name="current_post_views"]', $edit_row ).val( $post_views ); |
| 30 | } |
| 31 | |
| 32 | return false; |
| 33 | }; |
| 34 | |
| 35 | $( document ).on( 'click', '#bulk_edit', function() { |
| 36 | console.log( 'bulk edit' ); |
| 37 | // define the bulk edit row |
| 38 | var $bulk_row = $( '#bulk-edit' ); |
| 39 | |
| 40 | // get the selected post ids that are being edited |
| 41 | var $post_ids = new Array(); |
| 42 | |
| 43 | $bulk_row.find( '#bulk-titles' ).children().each( function() { |
| 44 | $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) ); |
| 45 | } ); |
| 46 | |
| 47 | // get the data |
| 48 | var $post_views = $bulk_row.find( 'input[name="post_views"]' ).val(); |
| 49 | |
| 50 | // save the data |
| 51 | $.ajax( { |
| 52 | url: ajaxurl, // this is a variable that WordPress has already defined for us |
| 53 | type: 'post', |
| 54 | async: false, |
| 55 | cache: false, |
| 56 | data: { |
| 57 | action: 'save_bulk_post_views', // this is the name of our WP AJAX function that we'll set up next |
| 58 | post_ids: $post_ids, // and these are the 2 parameters we're passing to our function |
| 59 | post_views: $post_views, |
| 60 | current_post_views: $post_views, |
| 61 | } |
| 62 | } ); |
| 63 | } ); |
| 64 | |
| 65 | } )( jQuery ); |