Title: Bash import phpBB avatars for Basic User Avatars
Last modified: August 31, 2016

---

# Bash import phpBB avatars for Basic User Avatars

 *  Resolved [Schoelje](https://wordpress.org/support/users/schoelje/)
 * (@schoelje)
 * [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/)
 * I’m importing my phpBB forum into bbPress and the only thing left is to import
   the users avatars.
 * I’ve been looking into the usermeta table and thought that inserting the basic_user_avatar
   meta_key should be enough. Unfortunately, it doesn’t work that way. Although 
   the avatar path exists, it is not shown.
 * This is the query I used:
    `INSERT INTO pre_usermeta (user_id, meta_key, meta_value)
   VALUES (1, 'basic_user_avatar', 'a:2:{s:4:"full";s:61:"http://domain/wp-content/
   uploads/userlogin_avatar.png";i:96;s:67:"http://domain/wp-content/uploads/userlogin_avatar.
   png";}');`
 * Do you have any idea how to bash import avatars for BUA?
 * [https://wordpress.org/plugins/basic-user-avatars/](https://wordpress.org/plugins/basic-user-avatars/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Jared Atchison](https://wordpress.org/support/users/jaredatch/)
 * (@jaredatch)
 * [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/#post-7391136)
 * If you are doing it via raw SQL then you are going to have to do the serialization
   yourself If that’s wrong it won’t work.
 * Depending on how many users you have, I’d consider maybe doing it in batches 
   and actually updating the users that way since it will do all the serialization.
   And since you’re dealing with PHP you can adapt it from what in the plugin
 *     ```
       $users = get_users();
       foreach( $users as $user ) {
   
          // put together $local_avatar array
          update_user_meta( $user->ID, 'basic_user_avatar', $local_avatars );
       }
       ```
   
 * See [https://github.com/jaredatch/Basic-User-Avatars/blob/master/init.php#L164](https://github.com/jaredatch/Basic-User-Avatars/blob/master/init.php#L164)
 *  Thread Starter [Schoelje](https://wordpress.org/support/users/schoelje/)
 * (@schoelje)
 * [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/#post-7391145)
 * Thank you for your reply.
 * I suppose $users is an array of user_ids and $local_avatars is an array of locally
   saved image paths?
 *  Plugin Author [Jared Atchison](https://wordpress.org/support/users/jaredatch/)
 * (@jaredatch)
 * [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/#post-7391190)
 * Pretty much, check out the function for more details
 * [https://codex.wordpress.org/Function_Reference/get_users](https://codex.wordpress.org/Function_Reference/get_users)
 * Best thing you can do is to do some debugging to see exact formats;
 *     ```
       $users = get_users();
       echo '<pre>' . print_r( $users, true ) . '</pre>';
       ```
   
 * Upload an avatar for a user as a test, then do
 *     ```
       $local_avatar = get_user_meta( USERID, 'basic_user_avatar', true );
       echo '<pre>' . print_r( $local_avatar, true ) . '</pre>';
       ```
   
 *  Thread Starter [Schoelje](https://wordpress.org/support/users/schoelje/)
 * (@schoelje)
 * [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/#post-7391232)
 * It is done!
 * Steps I took (globally):
    **1)** Convert with ImageMagick to png:
 *     ```
       for JPG in *.jpg; do
             PNG="${JPG%%.*}.png"
             convert -resize 96x96 "$JPG" "../converted/$PNG"
           done
       ```
   
 * **2)** Manually rename avatars to ‘user_login’_avatar.png (check user_meta for
   phpbb_user_id, phpbb_user_login, phpbb_user_avatar):
 *     ```
       cp -vf "711d7fbb7058b86d9a07750a767ee787_2.png" "./avatars/userlogin_avatar.png"
       ```
   
 * **3)** Place the phpbb avatars in the uploads directory or a sub-directory of
   the uploads directory (I did the latter).
 * **4)** Place the following script as import_phpbb_avatars.php in the base directory,
   open a browser and point to the script:
 *     ```
       <?php
           function find_wordpress_base_path() {
               $dir = dirname(__FILE__);
               do {
                   //it is possible to check for other files here
                   if( file_exists($dir."/wp-config.php") ) {
                       return $dir;
                   }
               } while( $dir = realpath("$dir/..") );
               return null;
           }
   
           define( 'BASE_PATH', find_wordpress_base_path()."/" );
           define('WP_USE_THEMES', false);
           global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
           require(BASE_PATH . 'wp-load.php');
   
           // Set domain and upload directory
           $domain = 'http://my_domain';
           $upload_dir = '/content_dir/uploads/old_avatars/';
   
           $users = get_users();
           foreach( $users as $user ) {
             // Build path to avatar
             $avatar_url = $upload_dir . str_replace(' ', '-', $user->user_login) . '_avatar.png';
             if ( file_exists ( BASE_PATH . $avatar_url ) ) {
               // Update user meta data
               update_user_meta( $user->ID, 'basic_user_avatar', array( 'full' => $domain . $avatar_url ) );
               // Show user meta data from database
               $local_avatar = get_user_meta( $user->ID, 'basic_user_avatar', true );
               echo '
       <pre>' . print_r( $local_avatar, true ) . '</pre>
       ';
             }
           }
       ?>
       ```
   
 * The only draw back is that when you develop on dev.my_domain.com and want to 
   use the dev database for production when you’re done, you’ll need to replace 
   all domain names in the URLs in your database.
 * I also had to convert all internal phpBB links (viewtopic.php?f=x&t=x) to the
   appropriate bbPress URLs. This was quite a difficult job.
 *  Plugin Author [Jared Atchison](https://wordpress.org/support/users/jaredatch/)
 * (@jaredatch)
 * [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/#post-7391242)
 * schoelje,
 * Very impressive, nice work! Thanks for coming back with an update and the steps.
   This could be very helpful to someone else in the future.
 * There are two solid and easy solution that will help with the issue of changing
   domains.
 * As you know, you can’t do a simple search/replace in the .sql file because doing
   that will break serialized data (like in BUA plugin).
 * My favorite and recommended method is using WP CLI. If you have that installed(
   many hosts offer it now, its really easy to install locally) you can do this 
   command:
    `wp search-replace "www.domain.com" "dev.domain.com"`
 * That will take care of all the URLs in the database (correctly) for you.
 * The second option is to use this handy script:
 * [https://interconnectit.com/products/search-and-replace-for-wordpress-databases/](https://interconnectit.com/products/search-and-replace-for-wordpress-databases/)
 * Hope that helps 🙂
 *  Thread Starter [Schoelje](https://wordpress.org/support/users/schoelje/)
 * (@schoelje)
 * [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/#post-7391243)
 * As I’m the maintainer of SolydXK, I know how important it is that people always
   post back their solutions. Perhaps I’m the first having this particular issue
   but I really doubt it. This way people don’t have to re-invent the wheel and 
   the solution might even be base for the plugin ;).
 * Thanks for the tip on [wp-cli](https://wp-cli.org/). I didn’t even know it existed!
 * Now the only thing left is to write redirects for my phpbb domain to point to
   the new bbPress domain/topic.
 * I’ve started a topic for that in the bbPress forum: [https://bbpress.org/?post_type=topic&p=175032](https://bbpress.org/?post_type=topic&p=175032)

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Bash import phpBB avatars for Basic User Avatars’ is closed to new replies.

 * ![](https://ps.w.org/basic-user-avatars/assets/icon-256x256.png?rev=2560641)
 * [Basic User Avatars](https://wordpress.org/plugins/basic-user-avatars/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/basic-user-avatars/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/basic-user-avatars/)
 * [Active Topics](https://wordpress.org/support/plugin/basic-user-avatars/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/basic-user-avatars/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/basic-user-avatars/reviews/)

## Tags

 * [bash](https://wordpress.org/support/topic-tag/bash/)
 * [Import](https://wordpress.org/support/topic-tag/import/)

 * 6 replies
 * 2 participants
 * Last reply from: [Schoelje](https://wordpress.org/support/users/schoelje/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/bash-import-phpbb-avatars-for-basic-user-avatars/#post-7391243)
 * Status: resolved