Skip to content

Instantly share code, notes, and snippets.

@Alimir
Created January 28, 2021 07:34
Show Gist options
  • Save Alimir/12e9417f92e689b65e03e4b3fee43686 to your computer and use it in GitHub Desktop.
Save Alimir/12e9417f92e689b65e03e4b3fee43686 to your computer and use it in GitHub Desktop.
Add new inputs to wp ulike edit profile forms
<?php
/**
* Process submitted form args
*
* @param array $args
* @return void
*/
function wp_ulike_pro_custom_after_profile_process( $args ){
// Get current user id
$user_id = get_current_user_id();
$meta_args = array();
$meta_args['notifications_choice'] = ! empty( $_POST['notifications_choice'] ) ? 1 : 0;
foreach ($meta_args as $key => $value) {
update_user_meta( $user_id, $key, $value );
}
}
add_action( 'wp_ulike_pro_after_profile_process', 'wp_ulike_pro_custom_after_profile_process', 10, 1 );
/**
* Add new fields to profile forms
*
* @param string $type
* @param array $args
* @return void
*/
function wp_ulike_pro_add_custom_inputs_to_profile_forms( $type, $args ){
if( $type === 'profile' ){
?>
<div class="ulp-flex-col-xl-12 ulp-flex-col-md-12 ulp-flex-col-xs-12">
<div class="ulp-flex ulp-flex-start-md ulp-flex-center-xs">
<input id="ulp-notifications-choice" name="notifications_choice" type="checkbox" value="1" <?php checked( get_user_meta( $args->user->ID, 'notifications_choice', true ), 1 ); ?> />
<label for="ulp-notifications-choice">
<span>Send Notification?</span>
</label>
</div>
</div>
<?php
}
}
add_action( 'wp_ulike_pro_forms_before_submit', 'wp_ulike_pro_add_custom_inputs_to_profile_forms', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment