Created
August 7, 2013 16:27
-
-
Save apatton-cnet/6175663 to your computer and use it in GitHub Desktop.
luketeaford
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: P-Ntil Quote Source | |
Plugin URI: http://luketeaford.com/plugins/pntil-quote-source | |
Description: A plugin to add author and source to quote post formats. Last updated 8/7/2013. | |
Version: 0.1 | |
Author: Luke Teaford | |
Author URI: http://luketeaford.com | |
License: GPL2 | |
*/ | |
// ACTIVATION | |
register_activation_hook( __FILE__, 'quote_source_activate' ); | |
function pntil_quote_source_activate() { | |
flush_rewrite_rules(); | |
} | |
add_action( 'admin_init', 'add_my_meta_box_on_quote' ); | |
function add_my_meta_box_on_quote() { | |
global $post; | |
$format = get_post_format($post->ID); | |
if ($format = 'quote') { | |
function pntil_quote_source_meta_box() { | |
add_meta_box( 'pntil_quote_source_meta_box', | |
'Quote Source', | |
'display_pntil_quote_source_meta_box', | |
'post', 'normal', 'high' | |
); | |
} | |
} | |
} | |
function display_pntil_quote_source_meta_box( $quote ) { | |
$quote_author = esc_html( get_post_meta( $quote->ID, 'quote_author', true ) ); | |
$quote_source = esc_html( get_post_meta( $quote->ID, 'quote_source', true ) );?> | |
<table> | |
<tr> | |
<td>Author/Post</td> | |
<td><input type="text" name="quote_author_name" placeholder="Author" value="<?php echo $quote_author; ?>"></td> | |
</tr> | |
<tr> | |
<td>Source</td> | |
<td><input type="text" name="quote_source_name" placeholder="Source" value="<?php echo $quote_source; ?>"></td> | |
</tr> | |
</table> | |
<?php | |
}//END OF FUNCTION DISPLAY PNTIL QUOTE SOURCE META BOX | |
add_action( 'save_post', 'add_pntil_quote_source_fields', 10, 2 ); | |
function add_pntil_quote_source_fields( $quote_post_id, $quote_post ) { | |
if ( $quote_post->post_type == 'post') {//THIS DOESN'T WORK HOW I WOULD EXPECT (PROBABLY BECAUSE THIS ISN'T IN THE LOOP) | |
if ( isset( $_POST['quote_author_name'] ) && $_POST['quote_author_name'] != '' ) { | |
update_post_meta( $quote_post_id, 'quote_author', $_POST['quote_author_name'] ); | |
} | |
if ( isset( $_POST['quote_source_name'] ) && $_POST['quote_source_name'] != '' ) { | |
update_post_meta( $quote_post_id, 'quote_source', $_POST['quote_source_name'] ); | |
} | |
} | |
} | |
//REGISTER DEACTIVATION HOOK | |
function pntil_quote_source_deactivate() { | |
flush_rewrite_rules(); | |
} | |
register_deactivation_hook( __FILE__, 'pntil_quote_source_deactivate' );?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment