BuddyDev

Search

Display a shortcode in Xprofile fields from another Plugin.

  • Participant
    Level: Initiated
    Posts: 13
    Peter on #27576

    Is it possible to display a shortcode of another plugin in the Xprofile fields?

    Regrads
    Peter

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #27582

    Hi Peter,
    Welcome to BuddyDev.

    This is doable if you want your users to enter some data. In case of BuddyPress, only a field with some data is fetched and shown on profile page.

    If you want to create a field which uses shortcode from another plugin but the user does not enter any data, It is not doable(atleast easily since BuddyPress won’t list the field).

    If you want, You can provide me a field id(text or multiline text field) and I can help getting your shortcode working in it.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 13
    Peter on #27593

    Basically, it should be such that only the admin can fill this field.

    I used e.g. the Football Leagues plugin.

    Here there is a short code of clubs or tables.

    I would like to display this club or table in the user profile page.

    The shortcode looks like this:
    [anwpfl-clubs competition_id = "" logo_size = "big" logo_height = "50px" logo_width = "50px" exclude_ids = ""]

    Now I have created a field with the name: Club.

    Title: Club
    Type: Text area
    Meta name: user_verein

    If I now enter the shortcode, I will not see the club but only the shortcode.

    • This reply was modified 4 years, 1 month ago by Peter.
    • This reply was modified 4 years, 1 month ago by Peter.
  • Participant
    Level: Initiated
    Posts: 13
    Peter on #27702

    At this Example the field_id are 5
    field id=5 and groupe id=2

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #27707

    HI Peter,
    Here is an example

    
    add_filter( 'xprofile_get_field_data', function ( $value, $field_id, $user_id ) {
    
    	if ( 5 != $field_id || is_array( $value ) ) {
    		return $value;
    	}
    
    	return do_shortcode( $value );
    
    }, 10, 3 );
    
    

    Please add it to your bp-custom.php and try.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 13
    Peter on #27754

    Thanks in advance I will test it.
    Could you just tell me what 10 and 3 means at the end of the code?

    Then the question is this code flexible if I have the field ID 6,7 or 8?

    Do I only have to change the 5 in the code?

    Regards
    Peter

  • Participant
    Level: Initiated
    Posts: 13
    Peter on #27757

    HEllo,

    i canĀ“t find a file with the name: bp-custom.php

    Regrads

    UPDATE:
    I created the file and then uploaded it to the wp-content / plugins folder
    – ` <?php
    // hacks and mods will go here
    add_filter( ‘xprofile_get_field_data’, function ( $value, $field_id, $user_id ) {

    if ( 3 != $field_id || is_array( $value ) ) {
    return $value;
    }

    return do_shortcode( $value );

    }, 10, 3 );
    ?> `.

    But the shortcode is not displayed.
    The field remains empty

    • This reply was modified 4 years, 1 month ago by Peter.
  • Participant
    Level: Initiated
    Posts: 13
    Peter on #27763

    OK. It works.

    I had a normal text field and no multi-line.

    Would it also work with a one-line text field?

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #27766

    Hi Peter,
    Thank you for confirming.

    Yes, It will work for one line text fields too.

    Regards
    Brajesh

The topic ‘Display a shortcode in Xprofile fields from another Plugin.’ is closed to new replies.

This topic is: not resolved