lolitaloco

check for thumb and thumb size on post save (wordpress)

Apr 23rd, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. function check_for_thumb($post){
  3.     global $post;
  4.     $post_thumb = get_post_meta($post->ID, '_thumbnail_id', true);
  5.     /* GIVE ERROR NOTICE IF POST HAS NO THUMB  ON SAVE */      
  6.     if(isset($_GET['post']) && $_GET['action'] === 'edit' && empty($post_thumb)) {
  7.         echo "<div class='error'><p>Posten saknar utvald bild</p></div>"; // message           
  8.     }
  9.     if(!is_null($post_thumb)) $thumb_meta = wp_get_attachment_metadata($post_thumb, true); 
  10.     if(isset($_GET['post']) && $_GET['action'] === 'edit' && !empty($post_thumb)) {
  11.     /* GIVE ERROR NOTICE IF THUMB (FEATURED IMAGED) DOESN'T MEET REQUIRED WIDTH/HEIGHT ON SAVE */          
  12.         $width = $thumb_meta['width'];
  13.         $height = $thumb_meta['height'];       
  14.         if($width < '485' || $height < '360') {
  15.             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>";
  16.         }          
  17.     }
  18. }
  19. add_action('admin_notices', 'check_for_thumb');
  20. ?>
Add Comment
Please, Sign In to add comment