Support Forum

Custom profie "text" field

UN
Unknown
Member

Hello,

I am working on the “custom profile fields” and I found a odd behaveur on the “text” fields.

1) Editing: the text displayed on the edit profile is html encoeded, i.e. on the textarea I have the <p>…</p> tags

2) Display: if I dont specify the userid on the sp_CustomProfileFieldsDisplay (i.e. the custom field is always “my own ” data) the text displayed is correctly transformed to html (i.e. “n” -> “<br/>”), if I specify the userId the text comes from without the html “translation”

I have tried to fix it myself, but I guess it is better if you look at it and fix in your code.

Here’s the couple of thing sthat I came up with:

sp-custom-profile-fields-components.php line 95:

esc_html($text) should become sp_filter_text_edit($text)

sp-custom-profile-fileds-display-tag.php: I didn’t find the “correct” way to pick up the html-ed field;

 

Thank you

13 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

I really need Mr Papa to take this one on board and he is away for a couple of days but will see it when he returns… thanks.

LU lm66uk
lm66uk
Member

Thank you.

I had a couple of ideas as well, i.e. a function which displays all the custom fields (with both name/value) just to avoid the need to type all the htmls.

If you reckon that to be of any help, let me know, I’ll be happy to share it.

MP Mr Papa
Mr Papa
Member

nope, sorry. due to an annoying limit of 50 (which we plan to change) in the unread posts, I never saw this one…

interesting…  you should see html in the input area since html is allowed, but it should not be encoded…  your hint does look like a proper fix… will open a ticket to research in detail and get it fixed up…

UN
Unknown
Member

I like the support here and how the creators are actively involved.  It adds a personal touch to software and makes it fun to use because as users…we help create it!!! kiss

MP Mr Papa
Mr Papa
Member

corrections for this have been submitted to svn trunk…  will be in next push update for RC, likely Sunday…

LU lm66uk
lm66uk
Member

Wow, that’s speedy!!

I guess I should use the bug-tracker too…

I’ll have a go with the changes and do some testing.

 

Thank you,

Lorenzo

LU lm66uk
lm66uk
Member

Hello,

I thought I could contribute to the bug tracker, but I guess I need to be authorization…

Anyway, thank you for the fix which is mostly working, however I have few notes:

  1. On sp-custom-profile-fields-display-tag.php: the sp_filter_text_display() is needed only for the get_usermeta(). $spThisUser->$fields[‘slug’] returns it already html-ed. Maybe it does not harm, but as a matter of principle…
  2. The include_once(CPFTAGSDIR.’sp-custom-profile-fileds-display-tag.php’); (line 101 on sp-custom-profile-fields-plugin.php) prevents it to be called twice. Either include(…) or make sp-custom-profile-fileds-display-tag.php a function.
  3. I was thinking of adding some little work on it, i.e. to be able to call a single function from the layout template to show all (of some) of the fields with the name / value and the divs so that it does not need to be done on the template. I am wondering if I could pass to you the suggestion, so that if you think it’s worth having it you can include in your code.

Thank you,

Lorenzo

LU lm66uk
lm66uk
Member

Hello,

here’s my code…

On sp-custom-profile-fields-plugin.php I added:

function sp_CustomProfileShow($userid = null, $names = null, $tags = null) {
 include_once(CPFLIBDIR.'sp-custom-profile-fields-components.php');
  include_once(CPFTAGSDIR.'sp-custom-profile-fields-display-tag.php');
  echo sp_custom_profile_fileds_display_tag($userid, $names, $tags);
}

On sp-custom-profile-fields-display-tag.php I added:

function sp_custom_profile_fileds_display_tag($userid = null, $names = null, $template = null){
 if (!isset($userid)) {
  global $spThisUser;
 }
 
 if(isset($names) && !is_array($names)){
  $names = explode(',', $names);
 }
 
 if(!isset($template)){
  $template = '<div class="spColumnSection spProfileLeftCol"><p>[name]</p></div>' .
        '<div class="spColumnSection spProfileSpacerCol"></div>' .
        '<div class="spColumnSection spProfileRightCol">[data]</div>';
 }
$cfields = sp_custom_profile_fields_get_data();
 $res = array();
 
 if (!empty($cfields)){
  foreach ($cfields as $fields) {
   $name = $fields['name'];
   $type = $fields['type'];
   $slug = $fields['slug'];
   if (!isset($names) || in_array($name, $names)) {
    if (!isset($userid)) {
     $data = $spThisUser->$slug;
    } else {
     $data = get_usermeta($userid, $slug, true);
     if ($type == 'textarea') {
      $data = sp_filter_text_display($data);
     }
    }
    $res[] = str_replace(array('[name]', '[data]'), array($name, $data), $template);
   }
  }
 }
 return implode(' ', $res);
}

Thank you,

Lorenzo

MP Mr Papa
Mr Papa
Member

the biggest problem here is that you have assumed the custom profile field will be displayed on the profile form…  many users of the plugin are also displaying the info on each users post…  so all that extra styling would be in error…  if you want to do that, it needs to be a distinct function explicitly for displaying on the profile form only…

interesting on the include… I have not had an issue displaying two items, but clearly need to think through that a bit more…

agree on the filter of meta data from the user object… I had forgotten the user class already filters it… wont hurt anything but not needed and slightly wasteful…

LU lm66uk
lm66uk
Member

Hi Mr Papa,

good point about my wrong assumption, so I guess I’d better create my little plugin and put there those ‘too customised’ functions.

Thank you!

Lorenzo

MP Mr Papa
Mr Papa
Member

I have committed the changes…

and more than willing to consider adding new template tags or functionality to this plugin… absolutely…  just wanted to make sure you understood the nuances…

if you would like to make some updates for growth and flexibility, giving me a patch file with the changes would allow me to review easiest…