-
Notifications
You must be signed in to change notification settings - Fork 2
/
custom-user-meta.php
99 lines (36 loc) · 1.65 KB
/
custom-user-meta.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Plugin Custom User Meta
*/
/**
* Create comment notification user meta field
*/
function cbent_macn_add_user_meta_field( $user ) { ?>
<h3><?php _e( 'Comment Email Notification', 'cbnet-multi-author-comment-notification' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="comment_notify"><?php _e( 'Comment Email Notification', 'cbnet-multi-author-comment-notification' ); ?></label></th>
<td>
<input type="checkbox" name="cbnet_macn_comment_notify" value="true" <?php checked( true == get_the_author_meta( 'cbnet_macn_comment_notify', $user->ID ) ); ?>>
<span class="description"><?php _e( 'Receive email notification of comments to all posts, regardless of post author', 'cbnet-multi-author-comment-notification' ); ?></span>
</td>
</tr>
</table>
<?php }
add_action( 'show_user_profile', 'cbent_macn_add_user_meta_field' );
add_action( 'edit_user_profile', 'cbent_macn_add_user_meta_field' );
/**
* Save comment notification user meta data
*/
function cbent_macn_save_user_meta_data( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
// Update user meta
update_user_meta( $user_id, 'cbnet_macn_comment_notify', ( isset( $_POST['cbnet_macn_comment_notify'] ) ? true : false ) );
// Delete transients
delete_site_transient( 'cbnet_macn_moderation_email_addresses' );
delete_site_transient( 'cbnet_macn_notification_email_addresses' );
}
add_action( 'personal_options_update', 'cbent_macn_save_user_meta_data' );
add_action( 'edit_user_profile_update', 'cbent_macn_save_user_meta_data' );
?>