Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the plugin "Extra User Fields" to add extra fields to the user's profile. I know how to get the value of the field (get_user_meta/get_author_meta), but I also want the label as a string, but I don't want to get the full code (like <label>Label</label><input value="value" /> etc., because I want to be able to do with the label and the value what I please.

So, what function (or tag) should I use to get the label value of an user field?

share|improve this question
    
You can already get the label but you ALSO get the input with it right? –  Sterling Hamilton Apr 17 '12 at 18:41
    
Yes, I just want the "values" as strings, not wrapped in html labels and inputs... –  Sander Bruggeman Apr 17 '12 at 18:44
    
Could you post an example of what you've tried that isn't giving you the desired results? –  Sterling Hamilton Apr 17 '12 at 18:53
    
Yes. do_action( 'edit_user_profile', $profileuser ); gives me all the user profile fields (labels, input and help wrapped in html elements, ready for output to the browser), but I just want the label value on it's own. I can get the input value with get_the_author_meta('field_id'), but I have no idea how to get just the label value that goes with that input value.. –  Sander Bruggeman Apr 17 '12 at 18:59
    
The plugin appears to be intended for people to use in the administration area, are you extending the plugin or are you editing the plugin? The plugin doesn't look like it supports PHP execution from the admin area - so I am just trying to get some context. –  Sterling Hamilton Apr 17 '12 at 19:57
add comment

1 Answer

Mentioned Functions:

If you can already get the label BUT it comes with the input, and you are doing this in PHP, then do this:

<?php
    # ...
    # Your code which produces the input + label data into $data
    # ...
    $document = new DOMDocument();
    $document->loadHTML( $data );
    $xpath = new DOMXPath( $document );
    $entries = $xpath->evaluate("//label");
    $results = array();
    foreach( $entries as $entry ) {
        $results[] = '<' . $entry->tagName . '>' . $entry->nodeValue .  '</' . $entry->tagName . '>';
    }
    print_r($results);
?>

This question appears incomplete from my outside perspective, so if this doesn't solve your problem, please refer to the discussion under the original question (in the comments section) so I may formulate a more appropriate response.

share|improve this answer
    
Oke, so what this does is load the data (label, input and someimes more) wrapped in the html-elements, and then parses that to get the desired strings? I've thought of that, but I was hoping there would be a cleaner/direct way to get the label. Anyway, thanks! I will try it like this! –  Sander Bruggeman Apr 17 '12 at 21:26
    
If this answer was acceptable please mark it as "Accepted". I'll see if I can look into a more efficient method - but for now this will do. –  Sterling Hamilton Apr 18 '12 at 6:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.