Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/12/2014, 13:00
Avatar de satanson123
satanson123
 
Fecha de Ingreso: julio-2012
Mensajes: 217
Antigüedad: 11 años, 8 meses
Puntos: 2
Respuesta: crear la opcion de subir una imagen desde el area de perfil

Bueno amigo lo coloque de esta forma pero no me funciona, me puedes decir donde me equivoco?

Código PHP:
Ver original
  1. //Imagen de portada
  2. function portada_add_custom_user_profile_fields( $user ) {
  3. ?>
  4.     <br />
  5.  
  6.  
  7. <script type="text/javascript">
  8. $('.add_img').click(function(){
  9.     var input_img = $(this).next();
  10.     var frame = wp.media({
  11.         title : 'Seleccionar imagen',
  12.         multiple : false,
  13.         library : { type : 'image'},
  14.         button : { text : 'Insert' }
  15.     });
  16.     frame.on('select',function() {
  17.         attachment = frame.state().get('selection').first().toJSON();
  18.         input_img.val(attachment['url']);
  19.     });
  20.     frame.open();
  21. });
  22. </script>
  23.  
  24. <table class="form-table">
  25. <tbody>
  26.                 <tr>
  27.             <th style="margin:15px;"><label for="portada">Imagen de portada</label></th>
  28.            
  29.             <th style="float:left;width:50%;">         
  30.                 <input type="text" name="portada" id="portada" value="<?php echo esc_attr( the_author_meta( 'portada', $user->ID ) ); ?>" class="regular-text"><br />Coloca el enlace de tu imagen de portada tamaño recomendado 1010x310.</th>
  31.             <th><input type="button" class="add_img" name="add_img" value="add_img" onclick="wp_enqueue_media()" /></th>
  32.            
  33.         </tr>
  34. </tbody>
  35. </table>
  36.  
  37. <?php }
  38.  
  39. function portada_save_custom_user_profile_fields( $user_id ) {
  40.    
  41.     if ( !current_user_can( 'edit_user', $user_id ) )
  42.         return FALSE;
  43.    
  44.     update_usermeta( $user_id, 'portada', $_POST['portada'] );
  45. }
  46. add_action('admin_enqueue_scripts', 'nportada_add_custom_user_profile_fields');
  47. add_action( 'show_user_profile', 'portada_add_custom_user_profile_fields' );
  48. add_action( 'edit_user_profile', 'portada_add_custom_user_profile_fields' );
  49.  
  50. add_action( 'personal_options_update', 'portada_save_custom_user_profile_fields' );
  51. add_action( 'edit_user_profile_update', 'portada_save_custom_user_profile_fields' );