Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress xprofile_insert_field_groupo Bug


  • stevehalwkings
    Participant

    @stevehalwkings

    i want to create Social Network field Group. in Social NEtwork Field Groupd i want to create One Custom Field Called LastFm

    i did try following code which gives error. it returns Multiple duplicate fields.

    check this screenshot: http://awesomescreenshot.com/035430kucd

    here is my code:

    add_action('bp_init', 'field_xprofile_twitter');
    
    function field_xprofile_twitter()
    {
    
       global $bp;
    $group_args = array(
         'name' => 'Social Networks'
         );
    $group_id = xprofile_insert_field_group( $group_args ); 
       $xfield_args =  array (
               'field_group_id'  => $group_id,
               'name'            => 'lastfm',
               'can_delete'      => false,
               'field_order'   =>  1,
               'is_required'     => false,
               'type'            => 'textbox'
        );
    
       xprofile_insert_field( $xfield_args );
    }
     

    Need Help to create Profile Field Programmaticaly.

    Looking forward to hearing from you.

    Thanks

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

  • danbp
    Participant

    @danbp

    Why don’t you use xProfile built-in component to add your custom field group and field ?

    User Extended Profiles

    Your function is hooked to bp_init, and bp_init occurs once per page load. So if you refresh the page lots of times, you’ll get lots of fields. 🙂


    stevehalwkings
    Participant

    @stevehalwkings

    @danbp
    yes i know i could create new profile field from the Admin but i want to create it programmatically.

    is there any way to fix this issue?


    @djpaul

    yes you are right.everytime when i refresh the page it creates new group field and profile field. do you know how to fix it ?

    any help would be greatly appreciated.

    Thanks


    shanebp
    Moderator

    @shanebp

    You could check to see if the field exists before creating it.
    But that check would happen on every page load.

    The best and most efficient method is to create a plugin and write a function that hooks to the
    register_activation_hook.
    In that function, check to see if the field exists and if not, create it.
    Then the function will only run which the plugin is activated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Buddypress xprofile_insert_field_groupo Bug’ is closed to new replies.
Skip to toolbar