-
-
Save billerickson/c54e9c2abf760c74d97ec81979bdaa84 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 | |
/** | |
* Featured Image Display | |
* | |
* Adds checkbox to Featured Image metabox to automatically add it to post header | |
* | |
* @package CoreFunctionality | |
* @author Bill Erickson | |
* @since 1.0.0 | |
* @license GPL-2.0+ | |
**/ | |
function ea_featured_image_display_settings( $content, $post_id ) { | |
if( 'post' != get_post_type( $post_id ) ) | |
return $content; | |
$field_id = 'ea_featured_image_display'; | |
$field_value = esc_attr( get_post_meta( $post_id, $field_id, true ) ); | |
$field_text = esc_html__( 'Display featured image at top of post.', 'ea' ); | |
$field_state = checked( $field_value, 1, false); | |
$field_label = sprintf( | |
'<p><label for="%1$s"><input type="checkbox" name="%1$s" id="%1$s" value="%2$s" %3$s> %4$s</label></p>', | |
$field_id, $field_value, $field_state, $field_text | |
); | |
return $content .= $field_label; | |
} | |
add_filter( 'admin_post_thumbnail_html', 'ea_featured_image_display_settings', 10, 2 ); | |
function ea_save_featured_image_display_settings( $post_ID, $post, $update ) { | |
$field_id = 'ea_featured_image_display'; | |
$field_value = isset( $_REQUEST[ $field_id ] ) ? 1 : 0; | |
update_post_meta( $post_ID, $field_id, $field_value ); | |
} | |
add_action( 'save_post', 'ea_save_featured_image_display_settings', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment