Skip to:
Content

Opened 8 years ago

Closed 8 years ago

#3044 closed enhancement (fixed)

bp-xprofile Add Hook before saving xprofile field data

Reported by: marinig Owned by:
Milestone: 1.5 Priority: normal
Severity: Version:
Component: Extended Profile Keywords:
Cc:

Description

File: bp-xprofile.php
Function: xprofile_set_field_data()

Is it possible to add a filter hook before saving the profile custom field value?

Something like:

$value = apply_filter( 'xprofile_field_data_set_pre', $value );

Is it possible to pass also the field name along with the $value variable?

Thanks

Change History (7)

#1 @marinig
8 years ago

Here is the complete (and correct) line to add the filter:

$value = apply_filters( 'xprofile_field_data_set_pre', $field, $value );

Applied at line 751 - bp-xprofile.php - function xprofile_set_field_data

BP ver 1.2.7

#2 follow-up: @DJPaul
8 years ago

What about using 'xprofile_data_value_before_save' or 'xprofile_data_before_save' in BP_XProfile_ProfileData::save()?

#3 in reply to: ↑ 2 ; follow-up: @marinig
8 years ago

Replying to DJPaul:

What about using 'xprofile_data_value_before_save' or 'xprofile_data_before_save' in BP_XProfile_ProfileData::save()?

Yes but I think my suggestion is simpler to use and more versatile... at least in my opinion.

What if I have to use the field name and field value at the same time (in the same filter function)? I can't use any of the hooks you indicated as they pass just one of them (field ID or field value) at a time... So I can't do different filtering on values basing on field name... I may be wrong, so please, correct me if there is a solution using those hooks.

Considering the hooks you wrote above, I could use the action hook "xprofile_data_before_save" but I must declare global $this in the hooked function in order to apply changes made, and I don't like this very much.

Thanks for your time

#4 in reply to: ↑ 3 @marinig
8 years ago

Ok, I made some test using the xprofile_data_before_save hook and discovered some useful OOP characteristics and so I solved my problems, thankyou very much DJPaul.

Just a final note:
I noticed that the $this->id passed to every filter in the BP_XProfile_ProfileData::save() method is always empty...

I don't know if this is normal, if it's just a problem on my installation or whatever...

Thankyou

Last edited 8 years ago by marinig (previous) (diff)

#5 @DJPaul
8 years ago

Hmm, yeah, id is never set in this particular context.

#6 @DJPaul
8 years ago

  • Milestone changed from Awaiting Review to 1.3

#7 @djpaul
8 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [4032]) Set ID in BP_XProfile_ProfileData class when a new value is set. Fixes #3044

Note: See TracTickets for help on using tickets.