Skip to:
Content

BuddyPress.org

Opened 13 years ago

Closed 13 years ago

Last modified 2 years ago

#3044 closed enhancement (fixed)

bp-xprofile Add Hook before saving xprofile field data

Reported by: marinig's profile 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)

#1 @marinig
13 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
13 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: @marinig
13 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
13 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 13 years ago by marinig (previous) (diff)

#5 @DJPaul
13 years ago

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

#6 @DJPaul
13 years ago

  • Milestone changed from Awaiting Review to 1.3

#7 @djpaul
13 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

#8 in reply to: ↑ 3 @8dayclub
2 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!!

Note: See TracTickets for help on using tickets.