我想列出用户配置文件中复选框中的页面,以便用户角色检查指定的页面
function my_user_field( $user ) {
$user_meta = get_the_author_meta( 'user_interests', $user->ID, true );?>
<table class="form-table">
<tr>
<th>
<label for="Dealing Type">Multi pages select for blurbs
</label></th><td>
<?php
$mypages = get_pages( array(
'sort_column' => 'post_date',
'sort_order' => 'desc'
) );
if(count($mypages)){
foreach( $mypages as $page )
{
$title = $page->post_title;
$slug = $page->post_name;
?>
<label for='user_interests_<?php echo $page->post_name; ?>' class='blurb_user_label_checkbox'>
<input id='user_interests_<?php echo $page->post_name; ?>' name='user_interests[<?php echo $page->post_title; ?>]' type='checkbox' value='$page->post_title'
<?php if ( in_array( $page->post_title, $user_meta ) ) echo ' checked="checked"'; ?> class='blurb_user_checkbox'>
<?Php echo $title; ?>
</label>
<?php
}
}
var_dump($user_meta);
?>
</td>
</tr>
</table>
function my_save_custom_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
update_usermeta( $user_id, 'user_interests', $_POST['user_interests']);
}
add_action( 'user_new_form', 'my_user_field' );
add_action( 'show_user_profile', 'my_user_field' );
add_action( 'edit_user_profile', 'my_user_field' );
add_action( 'personal_options_update', 'my_save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_custom_user_profile_fields' );
add_action('user_register', 'my_save_custom_user_profile_fields');
保存选项后复选框无效,请帮助我。我希望你能帮助我的人。如果还有其他方法也请给我