Last active
December 20, 2015 18:39
-
-
Save clifgriffin/6177034 to your computer and use it in GitHub Desktop.
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 | |
function pntil_quote_source_activate() { | |
flush_rewrite_rules(); | |
} | |
register_activation_hook( __FILE__, 'quote_source_activate' ); | |
add_action( 'init', 'film_journal_activate', 0 ); | |
add_action('admin_init', 'meta_box_loader'); | |
function meta_box_loader() { | |
if ( get_post_format($_GET['id']) == "format" ) { | |
add_action( 'add_meta_boxes', 'pntil_quote_source_meta_box' ); | |
} | |
} | |
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</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