Home › Forums › Front End PM PRO › How to see old announcements after the role change
- This topic has 14 replies, 2 voices, and was last updated 6 years, 3 months ago by Shamim Hasan.
-
AuthorPosts
-
September 4, 2018 at 7:09 pm #17224Aaku AsujamaaParticipant
Hi!
We are looking for a solution to get the user to see old announcements of the role after the user role have been set to the user.
For example:
1. We send an Announcement1 to Role1
2. We add Role1 user role for User2
3. User2 would see the Announcement1 and all the other previous announcements of Role1If I remember right, this is how it worked in the previous version of the plugin? Is there any way to get it work again?
September 4, 2018 at 8:59 pm #17233Shamim HasanKeymasterAdd following code in your theme’s (child theme’s if any) functions.php
add_action( 'set_user_role', function( $user_id, $role, $old_roles ) { global $wpdb; if ( ! defined( 'FEP_PARTICIPANT_TABLE' ) ) { return false; } $mgs_ids = $wpdb->get_col( $wpdb->prepare( "SELECT fep_message_id FROM $wpdb->fep_messagemeta where meta_key = %s AND meta_value = %s", '_fep_participant_roles', $role ) ); if ( $mgs_ids ) { $query = 'INSERT INTO ' . FEP_PARTICIPANT_TABLE . ' (mgs_id, mgs_participant) VALUES '; foreach ( $mgs_ids as $mgs_id ) { $values[] = $mgs_id; $values[] = $user_id; $place_holders[] = '(%d, %d)'; } $query .= implode( ', ', $place_holders ); $wpdb->query( $wpdb->prepare( $query, $values ) ); delete_user_meta( $user_id, '_fep_user_announcement_count' ); } }, 10, 3 );
September 5, 2018 at 1:18 pm #17239Aaku AsujamaaParticipantHi Shamim! And thanks for the fast reply. We have now added that code to our child theme but can’t get the functionality to work. All the other codes in the child theme work correctly. I have tried to activate and deactivate plugins but that have not have any effect.
I’m not an expert on php scripts so can’t really say if there is some kind of error in the code or if I just misstated our need. I found one conversation regarding the group messages where the asker wanted to have exact the opposite kind of function for group messages:
https://www.shamimsplugins.com/support/topic/group-message-2/
At the moment it seems that group messages either do not work the way you described in the above conversation? If I add a member to a group he won’t see the old messages of the group.
Is this issue correlated with issue in announcements? The announcement behaviour is a priority for us but wouldn’t mind if the group messages would start to work same way too as you described in the above conversation.
Cheers!
September 5, 2018 at 6:28 pm #17249Shamim HasanKeymasterFrom version 10.1.1 both group message and announcement work this way. Users can access group messages/ announcements only which is sent when they are in that role/group.
I have tested above code again and find working.
I have created an announcement to test role RA. Then i have checked if user UA (which user role is not RA) have got that announcement. find that user UA have no access to that announcement. Now i changed that user role to RA and now that user have access to that announcement.Please check and let me know.
September 5, 2018 at 9:40 pm #17267Aaku AsujamaaParticipantHi Shamim! Thanks again!
We just made a new conflict test and found out that our membership role plugin caused the problem. We used Members plugin (https://wordpress.org/plugins/members/) and when we deactivated that, your code started working.
We would need to be able to assign multiple roles to one user. We already tested out another plugin called User Role Editor (https://wordpress.org/plugins/user-role-editor/), but with that activated your code didn’t work either.
What role management plugin you are using? Or should the code be edited someway to work also when user is assigned to multiple roles?
Cheers!
September 5, 2018 at 11:07 pm #17272Shamim HasanKeymasterUse this code
add_action( 'add_user_role', 'fep_cus_update_ann_when_role_change', 10, 2 ); add_action( 'set_user_role', 'fep_cus_update_ann_when_role_change', 10, 2 ); function fep_cus_update_ann_when_role_change( $user_id, $role ) { global $wpdb; if ( ! defined( 'FEP_PARTICIPANT_TABLE' ) ) { return false; } $mgs_ids = $wpdb->get_col( $wpdb->prepare( "SELECT fep_message_id FROM $wpdb->fep_messagemeta where meta_key = %s AND meta_value = %s", '_fep_participant_roles', $role ) ); if ( $mgs_ids ) { $query = 'INSERT INTO ' . FEP_PARTICIPANT_TABLE . ' (mgs_id, mgs_participant) VALUES '; foreach ( $mgs_ids as $mgs_id ) { $values[] = $mgs_id; $values[] = $user_id; $place_holders[] = '(%d, %d)'; } $query .= implode( ', ', $place_holders ); $wpdb->query( $wpdb->prepare( $query, $values ) ); delete_user_meta( $user_id, '_fep_user_announcement_count' ); } }
September 6, 2018 at 3:18 pm #17305Aaku AsujamaaParticipantThanks again Shamim! That made the trick! There is still one problem which we haven’t been able to solve yet, but I will get back to you later regarding that.
Now more urgent problem is that we upgraded our license 2-5 sites license but I can’t get the license to work on a new site. I visited my account and added the new site (tutkimukset.buenno.fi) to the Site URL list, but still FEPM gives me an error:
“Your Front End PM PRO is not active for this URL. Please visit your account page to manage your license key URLs.”
I have a correct license key copied and site URL active. Do you know where the problem might be?
September 6, 2018 at 7:05 pm #17309Shamim HasanKeymasterSeptember 6, 2018 at 8:14 pm #17312Aaku AsujamaaParticipantThank you that made the license error to dissapear.
But the role to role block setting still doesn’t work. I’m a bit confused why. I have erased the whole plugin now three times again and still the “Add more” button does not work. It works on our development site but on the production site it does nothing. (The production site is the same place where we had the license error)
We have now erased the plugin totally three times and set it up again. The add more button stays unresponsive.
Any idea where this problem might come from?
September 6, 2018 at 8:46 pm #17316Shamim HasanKeymasterThere are add more buttons for Admins and Groups in Front End PM PRO > Settings > Recipient. Does those work?
Are you having any js error in role to role block setting page? Please see browser console and let me know.September 6, 2018 at 8:56 pm #17321Aaku AsujamaaParticipantThose add more buttons in Recipient settings do work. I found that there is one JS error in the role block setting page:
Uncaught SyntaxError: missing ) after argument list
admin.php?page=fep_settings&tab=security:485September 6, 2018 at 9:05 pm #17324Aaku AsujamaaParticipantThis reply has been marked as private.September 6, 2018 at 9:24 pm #17327Shamim HasanKeymasterSee your role name
'Viitasaari
started with'
. Remove that'
from role name. Then try.Let me know.
September 6, 2018 at 9:38 pm #17329Aaku AsujamaaParticipantThank you Shamim! I should have spotted that by myself but I’m so unfamiliar with the JS that didn’t really know where to look for.
Now everything else is working as planned, much because of your awesome support!
The only thing with my original request still is that if I reset same role back to the user the old announcements do not anymore appear.
I mean that if I continue your example onwards from there where the user UA has received the old announcement:
1. I take the test role RA away from the user UA
2. I make a new Announcement2 for role RA
3. I reset the role for user UA as RA
4. The user UA does not anymore receive the Announcement2It seems that the wordpress somehow remember that the user UA has some time had to role UA and doesn’t anymore run the code.
September 7, 2018 at 12:16 am #17335Shamim HasanKeymasterBy default wordpress allow only one role for user. It makes difficult to debug. As you are using another plugin to set multiple roles to a user.
You can debug line by line to find your issue.
-
AuthorPosts
You need to purchase ‘Front End PM PRO’ to create topic in this support forum.
If you already purchased ‘Front End PM PRO’ please LOGIN.