Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Custom profie "text" field
Avatar
Lorenzo
Member
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2012 - 7:35 am

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

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2012 - 9:46 am

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...

Avatar
Lorenzo
Member
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2012 - 10:00 am

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

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2012 - 10:03 am

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...

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 619
Members: 17362
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625