Character Name from Currently Logged in User #5

Closed
Ametista opened this Issue Sep 19, 2011 · 15 comments

2 participants

@Ametista

Firstly, thank you for an absolutely awesome plugin! I was wondering whether it would be possible to display character details based on the currently logged in user, assuming obviously that the user name is a valid character name... I've found the get_currentuserinfo() function but I can't seem to integrate it with the plugin. Thank you in advance!

@cooperaj
Owner

I could see that this would be a nice addition but I can't see how you would get to choose your region and realm. I'll investigate this and see what I can come up with.

@cooperaj cooperaj was assigned Sep 20, 2011
@Ametista

I'm making a guild site, so I could make the region and realm required custom fields on registration, maybe?

@Ametista Ametista closed this Sep 20, 2011
@Ametista Ametista reopened this Sep 20, 2011
@cooperaj
Owner

I'm not all that familiar with Wordpress so I wasn't sure how custom registration field would work. Would it be better to have a global region/realm/locale set for the site via a configuration screen or would you want it on a per user basis?

@cooperaj cooperaj closed this Sep 20, 2011
@cooperaj cooperaj reopened this Sep 20, 2011
@cooperaj
Owner

Rofl. Stupid Comment & Close button

@cooperaj
Owner

Would you be doing the custom fields something like this?
http://wordpress.org/support/topic/howto-custom-registration-fields

@Ametista

Hehe, I was also just hunting for info on it. :) Ideally, I'd like to integrate it with Buddypress, so this is what I found: http://blogcastor.com/extend/codex/how-to-display-buddypress-profile-field-data/

@cooperaj
Owner

Where will you have the armory stuff shown? On the users profile? If so it looks like the snippet at the bottom of http://codex.buddypress.org/extending-buddypress/tips-tricks/ might be a good starting point.

You can call the wow-armory-character shortcode function directly passing in the details from the users BP profile here or you could use the documentation http://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-profile-data-loop-bp_has_profile/ and construct a custom profile page that has the shortcode function called.

@Ametista

Thank you for the resources! :) Excuse my denseness, but I'm not sure how I'd pass the details from the profile into the shortcode... I'm not familiar with PHP syntax (I really need to update my coding knowledge and extricate myself from legacy systems! >.<)...

@cooperaj
Owner

http://wp-cms.com/template-development/inserting-wordpress-shortcode-outside-the-loop-in-a-template/ covers the basics with the relevant docs being http://codex.wordpress.org/Function_Reference/do_shortcode

Just construct your shortcode string using the variables you pull out in the profile loop. A bit like

"[wow-armory-character region='eu' realm='terokkar' name='" . $char_name . "']"
@Ametista

Thank you so much; I've got it working! Woot!! :D

@Ametista Ametista closed this Sep 20, 2011
@Ametista Ametista reopened this Sep 20, 2011
@Ametista

Lol, freaking Comment & Close button!! Here's my code:

    <?php
        $charregion = bp_get_profile_field_data( 'field=Region&user_id=' . bp_loggedin_user_id() );
        $charrealm = bp_get_profile_field_data( 'field=Realm&user_id=' . bp_loggedin_user_id() );
        $charname = bp_get_profile_field_data( 'field=Character Name&user_id=' . bp_loggedin_user_id() );
        echo do_shortcode('[armory-character region="' . $charregion . '" realm="' . $charrealm . '" name="' . $charname . '"]');
    ?>
@Ametista

Sorry if it's horrifically inefficient - it's the first bit of PHP I've ever coded. 😊

@cooperaj
Owner

Other then closing and opening the <?php ?> brackets in the middle it looks just fine :)

@Ametista

Rofl, how embarrassing... Fixed! :)

@cooperaj
Owner

When you've got your site all running nicely would you mind if I had a look? I'd like to see the plugin working 'in the wild' especially with BuddyPress. If you don't mind I'd also like to add the code you figured out to the FAQ (you'd get attribution ofc).

@cooperaj cooperaj closed this Mar 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment