. */ $add_new_default_avatar = new Add_New_Default_Avatar( ); class Add_New_Default_Avatar { function __construct( ) { add_filter( 'init' , array( $this , 'init' ), 9 ); register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); add_filter( 'plugin_action_links_'. plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ), 10, 4 ); add_filter( 'admin_init' , array( $this, 'admin_init' ) ); add_filter( 'avatar_defaults' , array( $this, 'avatar_defaults' ) ); add_filter( 'get_avatar', array( $this, 'get_avatar' ), 10, 5 ); } function init() { //move away from kl_ prefix $opts = get_option( 'kl_addnewdefaultavatar', false ); if ( $opts ) { update_option( 'add_new_default_avatar', $opts ); delete_option( 'kl_addnewdefaultavatar' ); } $opts = get_option( 'add_new_default_avatar', false ); //upgrade option, we can now save multiple avatar options if ( isset( $opts['name'] ) ) { $opts = array( $opts ); update_option('add_new_default_avatar', $opts ); } if ( ! $opts ) return; //get current default opton $current = get_option( 'avatar_default' ); //get any custom created avatars $unavailable = wp_list_pluck( $opts, 'url' ); //if the current wasn't created by this plugin, update the backup if ( ! in_array( $current, $unavailable ) ) { update_option( 'pre_anda_avatar_default', $current ); } } function deactivate() { //on deactivation, restore backup update_option( 'avatar_default', get_option( 'pre_anda_avatar_default', 'mystery' ) ); } function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) { if ( is_plugin_active( $plugin_file ) ) $actions[] = ''. __( 'Setup', 'anda' ) .''; return $actions; } function admin_init() { register_setting( 'discussion', 'add_new_default_avatar', array( $this, 'validate') ); add_settings_field('add_new_default_avatar', __( 'Add New Default Avatar' , 'anda' ) , array( $this, 'field_html') , 'discussion', 'avatars', $args = array() ); } function field_html() { $value = get_option( 'add_new_default_avatar', array( array( 'name' => 'Custom Avatar', 'url' => 'http://placehold.it/%size%/%size%' ) ) ); foreach( $value as $k => $pair ) { extract( $pair ); // $url, $name echo '
'; echo ""; echo ""; echo '
'; } $uid = uniqid(); echo ''; echo ""; echo ""; echo '
'; echo ''; esc_html_e( __( 'Add another', 'anda' ) ); echo ''; echo '';
esc_html_e( __( 'Some themes won\'t resize your image to fit, so it\'s best to use an image that\'s already the right size.', 'anda' ) );
echo '
';
echo sprintf(
__( 'However if your image accepts a size argument, you can use %1$s. Example: %2$s', 'anda' ),
'%size%',
'http://placehold.it/%size%/%size%'
);
echo '