Created
January 28, 2015 17:06
-
-
Save BenSibley/851ed43214e9a695aa06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Class for adding a new field to the options-general.php page | |
*/ | |
class ct_drop_add_profile_image_upload { | |
/** | |
* Class constructor | |
*/ | |
public function __construct() { | |
add_filter( 'admin_init' , array( &$this , 'register_fields' ) ); | |
} | |
/** | |
* Add new fields to wp-admin/options-general.php page | |
*/ | |
public function register_fields() { | |
register_setting( 'general', 'ct_drop_profile_image_upload', 'esc_attr' ); | |
add_settings_field( | |
'ct_drop_profile_image_upload', | |
'<label for="ct_drop_profile_image_upload">' . __( 'Avatar' , 'drop' ) . '</label>', | |
array( &$this, 'fields_html' ), | |
'general' | |
); | |
} | |
/** | |
* HTML for extra settings | |
*/ | |
public function fields_html() { | |
$value = get_option( 'ct_drop_profile_image_upload', '' ); | |
?> | |
<!-- Outputs the image after save --> | |
<img id="image-preview" src="<?php echo esc_url( $value ); ?>" style="width:100px;"><br /> | |
<!-- Outputs the text field and displays the URL of the image retrieved by the media uploader --> | |
<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" /> | |
<!-- Outputs the save button --> | |
<input type='button' id="profile-image-upload" class="button-primary" value="<?php _e( 'Upload Image', 'drop' ); ?>"/><br /> | |
<span class="description"><?php _e( 'This image will be used in the sidebar instead of your Gravatar.', 'drop' ); ?></span> | |
<?php | |
} | |
} | |
new ct_drop_add_profile_image_upload(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment