Having issues adding custom profile fields
-
Hi guys,
I’m trying to write a plugin but all the functions I used to use are deprecated! Could someone have a look over the below and let me know where I’m going wrong?
The basic objective is to add a user meta value named “showcase_enabled_bool”. When users view the edit profile page, they can either read that value (general user) or change that value (admin only). The idea is that an admin can enable any user to be included a showcase, but the users themselves can only look to see if they’ve been included.
When I submit the form, it looks as though no data is stored – but I’m having real trouble debugging this, so that might not be the issue. Any tips would be hugely appreciated.
add_action('personal_options', 'showcase_options'); function showcase_options() { $currentStatus = get_user_meta($user_id, 'showcase_enabled_bool', true); if ($currentStatus == 1) { $currentStatus = "enabled"; } else { $currentStatus = "disabled"; } if ( !IS_PROFILE_PAGE && !is_network_admin() ) : // Admin sees this ?> <h3>Showcase Settings</h3> <table class="form-table"> <tr><th><label for="showcase-enabled-bool">Enabled for showcase?</label></th> <td> <input type="radio" name="showcase-enabled-bool" value="1"<? if ($currentStatus == "enabled") { echo " checked"; } ?>> Yes <input type="radio" name="showcase-enabled-bool" value="0"<? if ($currentStatus == "disabled") { echo " checked"; } ?>> No<br> </td></tr> </table> <? else: // User sees this ?> <h3>Showcase Settings</h3> <table class="form-table"> <tr><th><label>Enabled for showcase?</label></th> <td> Your profile is currently <b><? echo $currentStatus; ?></b> for showcase listing. Contact an administrator to change this setting. </td></tr> </table> <? endif; } add_action('personal_options_update', 'showcase_save_options'); add_action( 'edit_user_profile_update', 'showcase_save_optionss' ); function showcase_save_options( $user_id ) { if ($_POST['showcase-enabled-bool'] == 1) { $showcase_input = 1; } else { $showcase_input = 0; } add_user_meta( $user_id, 'showcase_enabled_bool', $showcase_input, true); }
The topic ‘Having issues adding custom profile fields’ is closed to new replies.