Page 1 of 1

Change profile custom fields values

PostPosted: January 31st, 2012, 3:13 pm
by rvencu
Hi, I use some custom registration / profile fields. I need to use an algorithm to generate several fields content and I do not want the user to insert the values manually (still the user must see the field content).

I can generate in PHP the required value. How do I interact with the profile updates?

I found several hooks but have no idea how to change the value captured from the form into the custom value I calculate for the custom field.

Re: Change profile custom fields values

PostPosted: January 31st, 2012, 6:35 pm
by Raam Dev
Hello,

This thread may be useful: viewtopic.php?f=4&t=16594#p59823

Re: Change profile custom fields values

PostPosted: February 1st, 2012, 5:29 am
by rvencu
Yes, I have been there with no success. I tried to hook into those functions but how do I change the value of a field in my action before the field gets updated to the database. What is the syntax?

Re: Change profile custom fields values

PostPosted: February 1st, 2012, 8:49 am
by rvencu
After experimenting with the hooks I discovered some things. Nothing seems to be helpful.
Since I need to alter values in variables it seems that I must use filters. I tried this code:

Code: Select all
add_filter ("ws_plugin__s2member_during_profile_during_fields_display_custom_fields", "my_function");
function my_function ($bool, $vars = array ())
    {
        var_dump($vars);
      return $vars;
    }


So I discovered that in all filter hooks I only get empty array as $vars:
Code: Select all
array(0) { }
Therefore what is the purpose of these filters?

In actions it is true, I get a lot of things inside $vars variable but how to handle them? Specifically what can I do to save a certain value to a certain custom field inside an action?

Re: Change profile custom fields values

PostPosted: February 6th, 2012, 3:05 pm
by Jason Caldwell
Thanks for the heads up on this thread.

I would suggest this article to you as a primer as Hooks/Filters for WordPress.
http://codex.wordpress.org/Plugin_API#H ... our_Filter

The reason you're getting an empty array is because you're only requesting one function argument.

Try it like this please.
Code: Select all
add_filter ("ws_plugin__s2member_during_profile_during_fields_display_custom_fields", "my_function", 10, 2);
function my_function ($bool, $vars = array ())
    {
        var_dump($vars);
      return $vars;
    }