1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Best way to add to xf_user

Discussion in 'XenForo Development Discussions' started by LPH, Jun 10, 2013.

  1. LPH

    LPH Well-Known Member

    Does anyone have any links or suggestions on the best way to add to the xf_user database?

    1. determine db name
    2. determine prefix
    3. add field

    So, the plugin does this to a WP database:

    $wpdb->query("ALTER TABLE $wpdb->posts ADD `thread_id` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `ID` ");
    Is it best practice to do similar to XF or ... ?
  2. Jeremy P

    Jeremy P Well-Known Member

    I would use XenForo's DataWriters to do anything with the XF database. That way the proper events are called to make sure everything is in sync.
  3. LPH

    LPH Well-Known Member

    Thank you. Since I'm very new to this, basically a function would start off like the following ...

    * A function to create a table in the XF database
    * @since Version 1.1.5
    * @version 0.0.1
    * @[USER=13327]Author[/USER] LPH

    public static function xf_add_wp_custom_profiles() {

    $db XenForo_Application::get('db');
    Next would be writing the query to add fields to the table using DataWriters - which I do not know how to do but am willing to learn ;)
  4. Jeremy P

    Jeremy P Well-Known Member

    Oops sorry, I just looked at what your code was doing. (Still early in the morning here, haven't had any coffee yet).

    You are right, just alter the table directly with an SQL query. No datawriters needed unless you're writing to the database.
  5. LPH

    LPH Well-Known Member

    Overall, the add-on would allow a person to add, edit, and delete to their profile tab (or a new tab) new fields pulled from their WordPress profile page (if exists).

Share This Page