0

I've noticed that /wp-admin/js/inline-edit-post.js is used to retrieved the state of input in quick edit mode.

For example the following code :

jQuery(function() {
    if ( typeof mpIds !== 'undefined' ) {
        jQuery.each( mpIds, function(index, id) {
            jQuery("tr#edit-" + id + " .my_class" ).prop({checked: true});
            console.log( id );
        } );
    }

});

Cannot make this work. But when I enter my code in console it does the job so I'm a little bit lost. How would you do to get the same behaviour for a custom input ?

  • I forgot to say mpIds is retrieved by a wp_localize_script(). I send ids. – JMau Dec 27 '15 at 15:37
  • How is your code hooked in? – s_ha_dum Dec 27 '15 at 16:15
  • admin_enqueue_scripts as is should be or maybe I've missed smth ? – JMau Dec 27 '15 at 16:23
  • Nope. That should be right. – s_ha_dum Dec 27 '15 at 16:27
  • what is weird is that I get my IDs in logs, I'm wondering why my prop() does not trigger. – JMau Dec 27 '15 at 16:33
0

Not sure it's the best code but I've tested something here that works :

(function ($) {

    // copy of the WP inline edit post
    var wp_inline_edit = inlineEditPost.edit;

    // override
    inlineEditPost.edit = function (id) {

        // WP edit function
        wp_inline_edit.apply(this, arguments);


        // get post ID
        var post_id = 0;
        if (typeof( id ) === 'object') {
            post_id = parseInt(this.getId(id));
        }

        if (post_id > 0 && typeof mp_data !== 'undefined' && $.inArray( post_id, mp_data.ids ) > -1 ) {

            var edit_row = $('#edit-' + post_id);
            edit_row.find('.my_class').prop('checked', true);
        }

    }

})(jQuery);

It seems you have to do it this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.