Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /**
  2. * Class for adding a new field to the options-general.php page
  3. */
  4. class ct_drop_add_profile_image_upload {
  5.  
  6. /**
  7. * Class constructor
  8. */
  9. public function __construct() {
  10. add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
  11. }
  12.  
  13. /**
  14. * Add new fields to wp-admin/options-general.php page
  15. */
  16. public function register_fields() {
  17. register_setting( 'general', 'ct_drop_profile_image_upload', 'esc_attr' );
  18. add_settings_field(
  19. 'ct_drop_profile_image_upload',
  20. '<label for="ct_drop_profile_image_upload">' . __( 'Avatar' , 'drop' ) . '</label>',
  21. array( &$this, 'fields_html' ),
  22. 'general'
  23. );
  24. }
  25.  
  26. /**
  27. * HTML for extra settings
  28. */
  29. public function fields_html() {
  30. $value = get_option( 'ct_drop_profile_image_upload', '' );
  31.  
  32. ?>
  33. <!-- Outputs the image after save -->
  34. <img id="image-preview" src="<?php echo esc_url( $value ); ?>" style="width:100px;"><br />
  35. <!-- Outputs the text field and displays the URL of the image retrieved by the media uploader -->
  36. <input type="text" name="ct_drop_profile_image_upload" id="ct_drop_profile_image_upload" value="<?php echo esc_url_raw( $value ); ?>" class="regular-text" />
  37. <!-- Outputs the save button -->
  38. <input type='button' id="profile-image-upload" class="button-primary" value="<?php _e( 'Upload Image', 'drop' ); ?>"/><br />
  39. <span class="description"><?php _e( 'This image will be used in the sidebar instead of your Gravatar.', 'drop' ); ?></span>
  40. <?php
  41. }
  42. }
  43. new ct_drop_add_profile_image_upload();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement