. */ //for update practice // delete_option( 'kl_addnewdefaultavatar' ); delete_option( 'pre_anda_avatar_default' ); delete_option( 'add_new_default_avatar' ); // add_option( 'kl_addnewdefaultavatar', array( 'name' => 'Custom Avatar', 'url' => 'http://colorto.me/png/%size%/row2/red/yellow/orange/blue.png' ) ); 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 ); add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); } 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 ); } //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'; 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://colorto.me/png/%size%/row2/purple/yellow/orange/blue.png' ) ) ); foreach( $value as $k => $pair ) { extract( $pair ); echo "
"; echo "
"; } $uid = uniqid(); echo ""; echo ""; echo "
"; echo "Add another"; echo '' . __( '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://colorto.me/png/%size%/row2/purple/yellow/orange/blue.png' ) . '