Advertisement
miriamdepaula

WordPress: Adicionando upload no campo Imagem na opção Links

Aug 28th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. // adiciciona o thickbox no campo imagem
  2. add_action( 'admin_footer', 'wpmidia_link_image_scripts' );
  3. function wpmidia_link_image_scripts(){
  4.     global $current_screen;
  5.    
  6.     if( $current_screen->id == 'link' ):   
  7.     add_thickbox();
  8. ?>
  9. <script type="text/javascript">
  10.     jQuery(document).ready(function($) {
  11.        
  12.         var fileInput;
  13.         var header_clicked = false;
  14.        
  15.         $('#link_image').click(function() {
  16.             fileInput = $('#link_image');
  17.             //formfield = jQuery('#upload_image').attr('name');
  18.             //post_id = jQuery('#post_ID').val();
  19.             tb_show('', 'media-upload.php?type=image&TB_iframe=true');
  20.             header_clicked = true;
  21.             return false;
  22.         });
  23.    
  24.         window.original_send_to_editor = window.send_to_editor;
  25.         window.send_to_editor = function(html){
  26.            
  27.             if (fileInput) { console.log(html);
  28.                 fileurl = $('img',html).attr('src');
  29.                 //fileurl = $(html).attr('src');
  30.                 console.log(fileurl);
  31.    
  32.                 fileInput.val(fileurl);
  33.                 header_clicked = false;
  34.                 tb_remove();
  35.    
  36.             } else {
  37.                 window.original_send_to_editor(html);
  38.             }
  39.         };
  40.  
  41.     });
  42. </script>
  43. <?php
  44.     endif;
  45. }
  46.  
  47.  
  48. /********************************************************
  49. Shortcode
  50. Como usar: dentro do post ou página, coloque:
  51. [links]
  52. Se quiser escolher qual categoria de links, coloque:
  53. [links category=1] -- 1, 2 ou 3... será o ID da categoria de links =)
  54. ********************************************************/
  55.  
  56. function wpmidia_links_shortcode( $atts ){
  57.     extract( shortcode_atts(
  58.           array( 'category' => 2 ), $atts
  59.         )
  60.     );
  61.    
  62.     $bookmark = get_bookmarks(array('category' => $category));
  63.    
  64.     if( $bookmark ){
  65.         echo '<div class="bookmark clearfix">';
  66.        
  67.         foreach( $bookmark as $link ){
  68.            
  69.             echo '<div class="link">';
  70.            
  71.             if( !empty($link->link_image) ){
  72.                 echo '  <div class="link_image"><img src="'.$link->link_image.'" width="150px" height="150px" /></div>';   
  73.             }
  74.            
  75.             echo '  <div class="link_desc"><p>'.$link->link_description.'</p><p>Link: <a href="'.$link->link_url.'" target="_blank">'.$link->link_name.'</a></p></div>';   
  76.            
  77.             echo '</div>';
  78.         }
  79.        
  80.         echo '</div>'; 
  81.    
  82.     } else {
  83.         // mensagem se não houver links cadastrados...
  84.         echo __('<p>Nenhum link cadastrado na base de dados</p>', 'labterra'); 
  85.     }
  86.    
  87. }
  88. add_shortcode( 'links', 'wpmidia_links_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement