admin管理员组文章数量:1295948
wonder if you can help me.
I'm trying to get an action (geodir_after_save_listing) to change a user role.
Basically, in Geo Directory, when the user submits a business listing, I want to change their role from "member" to "member_with_business"
I believe the geo_dir_after_save_listing is still a relevant action (awaiting response from GeoDirectory support) so IMO the php snippet below should work?
add_action('geodir_after_save_listing', 'change_user_role_when_submit_business');
function change_user_role_when_submit_business( $last_post_id, $request_info ) {
$gd_post_type = geodir_get_current_posttype();
if ($gd_post_type == 'gd_place') {
$user = wp_get_current_user();
$roles = $user->roles;
if (in_array('member', $roles)){
$user->add_role( 'member_with_business' );
$user->remove_role( 'member' );
}
}
}
Any thoughts from those more php savvy than me?
wonder if you can help me.
I'm trying to get an action (geodir_after_save_listing) to change a user role.
Basically, in Geo Directory, when the user submits a business listing, I want to change their role from "member" to "member_with_business"
I believe the geo_dir_after_save_listing is still a relevant action (awaiting response from GeoDirectory support) so IMO the php snippet below should work?
add_action('geodir_after_save_listing', 'change_user_role_when_submit_business');
function change_user_role_when_submit_business( $last_post_id, $request_info ) {
$gd_post_type = geodir_get_current_posttype();
if ($gd_post_type == 'gd_place') {
$user = wp_get_current_user();
$roles = $user->roles;
if (in_array('member', $roles)){
$user->add_role( 'member_with_business' );
$user->remove_role( 'member' );
}
}
}
Any thoughts from those more php savvy than me?
Share Improve this question asked Apr 8, 2021 at 20:41 Mark LeeMark Lee 11 Answer
Reset to default 0Couple of things perhaps spring to mind - when using add_action
you'll need to provide how many of the arguments you're planning on using. Default 1. You're not using request info so get rid of that. Second bit geodir_get_current_posttype()
link
Read through how the function works and make sure it makes sense and would work in the context you are using it. It looks like it reads a query var from the URL - is that there?
Another option could just be to look this up yourself - looks like you've got the $last_post_id
variable. Can you not find out the info you need from that?
Plenty of var_dumps and die can help you diagnose what you're missing. Looks like the plugin author leaves most of them in the code anyway!
本文标签: On actionchange user role
版权声明:本文标题:On action, change user role 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741621213a2388822.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论