Skip to content

Instantly share code, notes, and snippets.

@mrbobbybryant
Last active August 29, 2015 14:18
Show Gist options
  • Save mrbobbybryant/f0665474dea5d29cead8 to your computer and use it in GitHub Desktop.
Save mrbobbybryant/f0665474dea5d29cead8 to your computer and use it in GitHub Desktop.
Create user profile upload field
<?php
function bootstrap_bob_user_image($user) {
?>
<h3>User Profile Picture</h3>
<table>
<tr>
<th><label for="upload_image">Enter a URL or upload an image.</label></th>
<td><input id="upload_image" type="text" size="36" name="ad_image" value="<?php if ( !empty( get_the_author_meta( 'upload_image', $user->ID ) ) ) echo esc_attr(get_the_author_meta( 'upload_image', $user->ID )); ?>" /></td>
<td><input id="upload_image_button" class="button" type="button" value="Upload Image" /></td>
</tr>
</table>
<?php
var_dump( get_the_author_meta( 'upload_image', $user->ID ) );
}
add_action( 'show_user_profile', 'bootstrap_bob_user_image', 11 );
add_action( 'edit_user_profile', 'bootstrap_bob_user_image', 11 );
function save_user_image( $user_id ) {
update_user_meta( $user_id,'upload_image', sanitize_text_field( $_POST['upload_image'] ) );
}
add_action( 'personal_options_update', 'save_user_image' );
add_action( 'edit_user_profile_update', 'save_user_image' );
//enqueue scripts for uploader
function bootstrap_bob_admin_scripts() {
wp_enqueue_script( 'bootstrap-bob-js', get_template_directory_uri() . '/js/bootstrap-bob.js', array( 'jquery' ), '20150330', true );
wp_enqueue_media();
}
add_action( 'admin_enqueue_scripts', 'bootstrap_bob_admin_scripts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment