API integration into wordpress

Im working on a gaming website and i want to incorporate an api into the buddypress/wordpress wesbite.

https://github.com/viion/XIVPads-LodestoneAPI

Read More

The trouble im having it where to actually start… The examples they give, i modified it so when 2 fields are entered ($ff14 & $ff14world) it will do a search for it.

<?php 
require 'api-autoloader.php';
$api = new ViionLodestoneLodestoneAPI();
$ff14 = bp_get_member_profile_data( 'field=Character' );
$ff14world = bp_get_member_profile_data( 'field=World' );

// Search by: name + world
$character = $api->Search->Character($ff14, $ff14world);

// Basic data
echo $character->name;
echo $character->world;
//var_dump( $character->classjobs );

?>

I tested it by putting it in the header.php file of the child theme and it output the result i wanted in the header but it wasn’t picked up anywhere else on the website when i entered say echo $character->name;

In the end i just want people to be able to enter their character name/world in the profile page and within a separate tab the data from the $character variable will show 🙂

Ive been searching and stuffing around for about a week now…. Do i put it in the header.php… maybe the themes function.php…. ive tried but haven’t successfully done it. Any tips?

  • Justin

Related posts

1 comment

  1. In the end i just want people to be able to enter their character
    name/world in the profile page and within a separate tab the data from
    the $character variable will show

    A separate tab where? On the member’s profile page?
    Adding a profile tab example.
    Putting your code in the theme header is very inefficient.

    This function bp_get_member_profile_data is meant to be used when viewing a member’s page. It assumes that the member id is the displayed member – unless you pass it another id. To retrieve profile data ‘outside’ of a member page, use function xprofile_get_field_data( $field, $user_id = 0, $multi_format = 'array' )

    This example will show the lodestone field values in the member-header file: buddypressbp-templatesbp-legacybuddypressmemberssinglemember-header.php

    This code can go in your theme/functions.php or in plugins/bp-custom.php

    function justin_show_lodestone() {
         require 'api-autoloader.php';  // adjust path as necessary
         $api = new ViionLodestoneLodestoneAPI();
         $ff14 = bp_get_member_profile_data( 'field=Character' );
         $ff14world = bp_get_member_profile_data( 'field=World' );
    
         // Search by: name + world
         $character = $api->Search->Character($ff14, $ff14world);
    
         // Basic data
         echo $character->name;
         echo $character->world;
    
    }
    add_action('bp_profile_header_meta', 'justin_show_lodestone'); 
    

Comments are closed.