Created
July 8, 2015 01:49
-
-
Save daronspence/09e35f616913059de71f to your computer and use it in GitHub Desktop.
Quick Edit Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Quick Edit Pro | |
* Plugin Author: Daron Spence | |
* Version: 0.1 | |
*/ | |
add_action( 'quick_edit_custom_box', function( $column_name, $post_type ){ | |
if ( 'post' === $post_type && 'post_excerpt' === $column_name ){ ?> | |
<fieldset class="inline-edit-col-left inline-edit-custom" style="clear: left;"> | |
<div class="inline-edit-col inline-edit-<?php echo $column_name ?>"> | |
<label><?php _e( 'Excerpt', 'quick-edit-pro' ); ?> | |
<textarea name="<?php echo $column_name; ?>"></textarea> | |
</label> | |
</div> | |
</fieldset> | |
<?php } | |
}, 10, 2 ); | |
add_filter( 'manage_posts_columns', function( $columns ) { | |
return array_merge( $columns, | |
array( 'post_excerpt' => __( 'Excerpt' ) ) ); | |
}, 10, 2 ); | |
add_action( 'manage_posts_custom_column' , function( $column, $post_id ){ | |
if ( 'post_excerpt' === $column ){ | |
$post = get_post( $post_id ); | |
echo $post->post_excerpt; | |
} | |
}, 10, 2 ); | |
add_action('save_post', function($post_id) { | |
// verify if this is an auto save routine. If it is our form has not been submitted, | |
// so we dont want to do anything | |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) | |
return $post_id; | |
$slug = 'post'; | |
if ( $slug !== $_POST['post_type'] ) { | |
return; | |
} | |
if ( !current_user_can( 'edit_post', $post_id ) ) { | |
return; | |
} | |
// checkboxes are submitted if checked, absent if not | |
if ( isset( $_REQUEST['post_excerpt'] ) ) { | |
wp_update_post( array( | |
'ID' => $post_id, | |
'post_excerpt' => esc_html( $_REQUEST['post_excerpt'] ) | |
) ); | |
} | |
return; | |
}, 10 ); | |
add_action( 'admin_print_footer_scripts', function(){ ?> | |
<script type="text/javascript"> | |
(function($) { | |
// we create a copy of the WP inline edit post function | |
var $wp_inline_edit = inlineEditPost.edit; | |
// and then we overwrite the function with our own code | |
inlineEditPost.edit = function( id ) { | |
// "call" the original WP edit function | |
// we don't want to leave WordPress hanging | |
$wp_inline_edit.apply( this, arguments ); | |
// now we take care of our business | |
// get the post ID | |
var $post_id = 0; | |
if ( typeof( id ) == 'object' ) { | |
$post_id = parseInt( this.getId( id ) ); | |
} | |
if ( $post_id > 0 ) { | |
// define the edit row | |
var $edit_row = $( '#edit-' + $post_id ); | |
var $post_row = $( '#post-' + $post_id ); | |
// get the data | |
var $post_excerpt = $( '.column-post_excerpt', $post_row ).text(); | |
// populate the data | |
$( ':input[name="post_excerpt"]', $edit_row ).val( $post_excerpt ); | |
} | |
}; | |
})(jQuery); | |
</script> | |
<?php | |
}, 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment