Neither of those work either. They don’t return an error, but nothing is being saved when a Billing Modification Form is processed.
I’ve also discovered that I can’t seem to retrieve the data from the array in the database. I’ve tried get_user_field
, get_user_option
, and get_user_meta
. Either nothing is displayed in the dashboard when the product_id
field is an array or the word Array
is displayed instead of the value of the field. The latter only occurs with get_user_field()
. The others simply show nothing.
My code:
<?php
add_action('ws_plugin__s2member_during_configure_user_registration', function ($vars = array())
{
$user = $vars['user']; // A WP_user object instance.
$_p = stripslashes_deep($_POST); // $_POST vars via form submission.
if(!empty($_p['product_id']) && is_string($_p['product_id']))
$pid = array();
$pid[] = esc_html($_p['product_id']);
update_user_option($user->ID, 'product_id', $pid);
});
add_action( 'edit_user_profile', 'sg_add_product_id_to_profile' );
function sg_add_product_id_to_profile ( $user )
{
?>
<h3>Product ID</h3>
<table class="form-table">
<tr>
<th><label for="product_id">Product ID</label></th>
<td><input type="text" name="product_id" value="<?php echo get_user_field( 'product_id', $user ); ?>" class="regular-text" /></td>
</tr>
</table>
<?php
};
The add_action('ws_plugin__s2member_during_configure_user_registration', function ($vars = array())
works fine when I’m regiatering a new User, but it apparently isn’t called when a User is updated. So my array really does me no good unless I can find the right hook.
As I said the code to display the product_id
in the User Profile doesn’t work when I use an array either. There’s nothing I can find in the sample code or s2Member Codex showing anything different being done with get_user_field()
to retrieve an array.