post_title; else echo 'None'; break; } } /**************************************************** 2. Expand the WordPress Quick Edit Menu After adding our custom column, we are ready to expand our Post Quick Edit menu using the quick_edit_custom_box action hook. Note – The quick_edit_custom_box action hook will not fire unless there are custom columns present. That is why we started by adding a custom column. Line 5 – Only render our Quick Edit extension on the relevant screen. Lines 7 to 25 – Render our custom drop-down menu for selecting widget sets. ****************************************************/ // Add to our admin_init function add_action('quick_edit_custom_box', 'shiba_add_quick_edit', 10, 2); function shiba_add_quick_edit($column_name, $post_type) { if ($column_name != 'widget_set') return; ?>
Widget Set 'widget_set', 'numberposts' => -1, 'post_status' => 'publish') ); ?>
post_type != 'revision')) { $widget_set_id = esc_attr($_POST['post_widget_set']); if ($widget_set_id) update_post_meta( $post_id, 'post_widget', $widget_set_id); else delete_post_meta( $post_id, 'post_widget'); } return $widget_set_id; } /**************************************************** 4. Update the Quick Edit Menu with Javascript Now comes the really fun part – notice that while our new custom input shows up in the Quick Edit menu, it is not properly updated to show which ‘widget_set‘ the current Post object is set to. I.e., our widget set meta-data is not getting through to our custom Quick Edit menu. The set_inline_widget_set javascript function below updates our Quick Edit menu with the relevant meta-data. Lines 5 to 6 – Only add the javascript quick edit function to the Posts screen. Line 13 – Make sure that Quick Edit menu is closed. The revert function (defined in inline-edit-post.js) ensures that our Quick Edit custom inputs are properly updated when we switch Post objects. Lines 15 to 16 – Set nonce value for our custom inputs. If we want, we can expand our save_post function to do a nonce check. Lines 18 to 22 – Set the proper widget set option on our custom Quick Edit drop-down menu. ****************************************************/ // Add to our admin_init function add_action('admin_footer', 'shiba_quick_edit_javascript'); function shiba_quick_edit_javascript() { global $current_screen; if (($current_screen->id != 'edit-post') || ($current_screen->post_type != 'post')) return; ?> id != 'edit-post') || ($current_screen->post_type != 'post')) return $actions; $nonce = wp_create_nonce( 'shiba_widget_set'.$post->ID); $widget_id = get_post_meta( $post->ID, 'post_widget', TRUE); $actions['inline hide-if-no-js'] = '"; $actions['inline hide-if-no-js'] .= __( 'Quick Edit' ); $actions['inline hide-if-no-js'] .= ''; return $actions; }