admin管理员组文章数量:1317915
Hi I want to make the serialized reading value 1 or 0 in mysql, how can I do
example code
$query = $wpdb->get_results('select * from wp_options where option_id = 96');
$dizi = unserialize($query[0]->option_value);
// echo $dizi['subscriber']['capabilities']['read'];
//print_r($dizi);
if(array_key_exists('read', $dizi['subscriber']['capabilities'])){
echo $dizi['subscriber']['capabilities']['read'] = 0;
}
exit;
Hi I want to make the serialized reading value 1 or 0 in mysql, how can I do
example code
$query = $wpdb->get_results('select * from wp_options where option_id = 96');
$dizi = unserialize($query[0]->option_value);
// echo $dizi['subscriber']['capabilities']['read'];
//print_r($dizi);
if(array_key_exists('read', $dizi['subscriber']['capabilities'])){
echo $dizi['subscriber']['capabilities']['read'] = 0;
}
exit;
Share
Improve this question
asked Nov 12, 2020 at 15:56
Mehmet CemilMehmet Cemil
501 silver badge5 bronze badges
3
|
1 Answer
Reset to default 1You should not use raw SQL to modify roles and capabilities, it is very bad practice, and unnecessary.
Instead, use the roles API, e.g.
$role = get_role( 'subscriber' );
$role->add_cap( 'read' );
Or to add it to a specific user:
$user = new WP_User( $user_id );
$user->add_cap( 'read' );
Likewise you can remove a capability from a role:
$role = get_role( 'subscriber' );
$role->remove_cap( 'read' );
本文标签: phphow to serialize() mysql update data
版权声明:本文标题:php - how to serialize() mysql update data 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999075a2410639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_cap
? I feel like that would be easier than trying to deal with$wpdb
. – Howdy_McGee ♦ Commented Nov 12, 2020 at 16:19