Last active
December 23, 2015 03:58
-
-
Save annalinneajohansson/6576690 to your computer and use it in GitHub Desktop.
Check for featured image on post save
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 | |
function check_for_thumb( $post ){ | |
global $post; | |
$post_type = get_post_type( $post->ID ); | |
$post_thumb = get_post_meta( $post->ID, '_thumbnail_id', true ); | |
if( $post_type === 'bildspel' && isset( $_GET['post'] ) && $_GET['action'] === 'edit' && empty( $post_thumb ) ) { | |
echo "<div class='error'><p>Posten saknar utvald bild</p></div>"; | |
} | |
if( !is_null( $post_thumb ) ) $thumb_meta = wp_get_attachment_metadata( $post_thumb, true ); | |
if( isset($_GET['post'] ) && $_GET['action'] === 'edit' && !empty( $post_thumb ) ) { | |
$width = $thumb_meta['width']; | |
$height = $thumb_meta['height']; | |
if( $width < '485' || $height < '360' ) { | |
echo "<div class='error'><p>Utvald bild bör vara minst <strong>485 x 360 px</strong>. (Nuvarande bild är $width x $height px.)</p></div>"; | |
} | |
} | |
} | |
add_action('admin_notices', 'check_for_thumb'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment