#3044 closed enhancement (fixed)
bp-xprofile Add Hook before saving xprofile field data
Reported by: | marinig | Owned by: | |
---|---|---|---|
Milestone: | 1.5 | Priority: | lowest |
Severity: | trivial | 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 (8)
#2
follow-up:
↓ 3
@
14 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-ups:
↓ 4
↓ 8
@
14 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
@
14 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
#8
in reply to:
↑ 3
@
3 years ago
- Priority changed from normal to lowest
- Severity set to trivial
Replying to marinig:
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 in nearly 8day ... 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
Thank you for your advise. I have a forum website and it's really nice!!
Here is the complete (and correct) line to add the filter:
Applied at line 751 - bp-xprofile.php - function xprofile_set_field_data
BP ver 1.2.7