I am trying to create custom options for users in my WordPress website profile area (in their dashboard). These options need to be checked by the user, and then need to be able to do something if they are checked.
How do I save these checkboxes, and then what would be the starting point to 'If checked, then'?
(The checkboxes start on line 53, and I attempt to save them on line 80)
Thank you greatly.
<?php
/**
* Plugin Name: YLDist Profile Options
* Plugin URI:
* Description: Profiles
* Author: JPowersFreelancing
* Author URI:
* Version: 1.0
*/
// Hide Personal Options at Top
function hide_personal_options(){
echo "\n" . '<script type="text/javascript">jQuery(document).ready(function($) {
$(\'form#your-profile > h3:first\').hide();
$(\'form#your-profile > table:first\').hide();
$(\'form#your-profile\').show();
$(\'label[for=url], input#url\').hide();
});
</script>' . "\n";
}
add_action('admin_head','hide_personal_options');
// Add Extra Profile Fields
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<div class="personal-profile">
<h3>Your Website Contact Details</h3>
<span class="description">These details are displayed on your website publicly.</span>
<table class="form-table">
<tr>
<th><label for="sponsor">Young Living Member Number</label></th>
<td>
<input type="text" name="sponsor" id="sponsor" value="<?php echo esc_attr( get_the_author_meta( 'sponsor', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Young Living membership number.</span>
</td>
</tr>
<tr>
<th><label for="number">Phone Number</label></th>
<td>
<input type="text" name="number" id="number" value="<?php echo esc_attr( get_the_author_meta( 'number', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Phone numbers are displayed publicly.</span>
</td>
</tr>
<tr>
<th><label for="options">Website Options</label></th>
<td>
<form action="checkbox-form.php" method="post">
<h3>Navigation Options</h3>
<input type="checkbox" name="A" id="A" value="<?php echo esc_attr( get_the_author_meta( 'A', $user->ID ) ); ?>" />Order Button (Linked to Young Living)<br />
<input type="checkbox" name="B" id="B" value="<?php echo esc_attr( get_the_author_meta( 'B', $user->ID ) ); ?>" />Video Button (Why Young Living)<br />
<input type="checkbox" name="C" id="C" value="<?php echo esc_attr( get_the_author_meta( 'C', $user->ID ) ); ?>" />Video Button (This is Young Living)<br />
<input type="checkbox" name="D" id="D" value="<?php echo esc_attr( get_the_author_meta( 'D', $user->ID ) ); ?>" />Essential Rewards Button<br />
<input type="checkbox" name="E" id="E" value="<?php echo esc_attr( get_the_author_meta( 'E', $user->ID ) ); ?>" />Opportinities Button
<h3>Premium Kit Options</h3>
<input type="checkbox" name="F" id="F" value="<?php echo esc_attr( get_the_author_meta( 'F', $user->ID ) ); ?>" />Premium Starter Kit<br />
<input type="checkbox" name="G" id="G" value="<?php echo esc_attr( get_the_author_meta( 'G', $user->ID ) ); ?>" />Premium Starter Kit w/ Ningxia Red<br />
<input type="checkbox" name="H" id="H" value="<?php echo esc_attr( get_the_author_meta( 'H', $user->ID ) ); ?>" />Premium Starter Kit w/ Thieves<br />
<input type="checkbox" name="I" id="I" value="<?php echo esc_attr( get_the_author_meta( 'I', $user->ID ) ); ?>" />Show Premium Kit Prices<br />
</form>
</td>
</tr>
</table>
</div>
<?php }
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_usermeta( $user_id, 'sponsor', $_POST['sponsor'] );
update_usermeta( $user_id, 'number', $_POST['number'] );
update_usermeta( $user_id, 'A', $_POST['A'] )? true : false;
update_usermeta( $user_id, 'B', $_POST['B'] )? true : false;
update_usermeta( $user_id, 'C', $_POST['C'] )? true : false;
update_usermeta( $user_id, 'D', $_POST['D'] )? true : false;
update_usermeta( $user_id, 'E', $_POST['E'] )? true : false;
update_usermeta( $user_id, 'F', $_POST['F'] )? true : false;
update_usermeta( $user_id, 'G', $_POST['G'] )? true : false;
update_usermeta( $user_id, 'H', $_POST['H'] )? true : false;
update_usermeta( $user_id, 'I', $_POST['I'] )? true : false;
}
?>
Aucun commentaire:
Enregistrer un commentaire