 Welcome back to the channel, today we're going to continue with writing our software that is a an SMS plugin of sorts that will do external queries to external APIs on different servers and eventually send that by some SMSes. However, we're going to do it in a professional way and one of the things that really caught my eyes as I was planning this out was wukamas. If I go to my users right now I have one user, I'm actually able to just check this and then change the kind of role that I do have so I have shop manager here listed as a role and I can change my particular user to just a shop manager. Now the shop manager does not do so much apart from managing the wukamas shop, they will not edit, make new posts, they will not make new pages and so on because they have been limited in what we call capabilities. So in our plugin we're going to have SMS manager, we're going to have to create that role ourselves and then we are actually going to kick off with our plugin. So what I'm going to do here is I'm going to get most of this data from our plugin that we have here and I'm going to save it in a different text file so I'll just make a text file here then I'm just going to dump all our functions that we've been using in here, I'll just leave only the register, the menu, the admin menu, that's what I'll leave there and then I'll take the rest of the other content out so cut this then save this, we'll revert to this a little later so what we're going to do here is save this, we still have our plugin page showing up here so I'll just open up this function and just do something very simple so we'll have this function and what it's going to do it's just going to basically echo our header one so we'll have header one that will close off and we'll just say our SMS admin and then save that here so we'll reload and we have that showing up so we're going to restrict this to be able to be shown to someone who is either an SMS admin or an administrator fully administrator and so on so what we're going to do here first and foremost is actually add our new role so I'm going to use the word press functionality that is embedded in for us so when we look at the the codecs we see that we have an add role that requires a string of role the display name and then it will require an array of capabilities first of all we have to show that this is actually true and then we can add the other possibilities of roles and how do we add those roles when we go to roles and capabilities we're able to see the different roles that are assigned in wordpress by default we have super admins who are created when we create a multi site we have administrators we have editors we have authors contributors and subscribers and each one of those has their own kind of super powers or powers or whatever roles or capabilities whatever you would call them and this could include creating sites deleting them deleting posts editing the dashboard publishing pages and so on that's why you're able to have subscribers in your site but they will never post a post for you they will never do anything they cannot even submit anything so the roles that subscribers usually have is just to read later then we have contributors who can delete some posts and edit posts that are theirs then we have authors who have a little more powers to delete posts and delete other posts from other from their own posts edit them read upload files then we have editors who can edit even other people's posts and do private pages and posts and delete published pages then we have the administrators who can basically add plugins and themes delete them edit them add users create new users so we're going to have our sms admin as a new role and we shall assign them a couple of user roles and we're going to sort of equate them to what a contributor is like so that they are able to only edit their own posts and maybe delete them but they cannot do so many other things so let's jump into that code and see how we can actually add this in so we shall have a hook here so we're going to do admin add action and the hook we shall use is innate when word press is initialized what we're going to do is add a function and the function is we're going to call it sms add user user role so we'll copy this and then add the function yeah so function add user role and after adding this user role what we're going to do next is we're going to go to add role which is here so the role name is going to be sms manager sms manager then what we're going to do is add now a description we're going to add a display name for them so we'll just basically copy this and make it pet so copy replace this and then i'll just change this manager to sms manager and then for their capabilities it's going to be an array of information so we'll start off with an array close that off in our capabilities what we're going to do first of all is add the role to be able to read so we'll append that and say this is going to be so sorry to be a comma and say that is true so when we come back to our users here we should be able to now we check change roles we should have sms manager showing up right here now with that we're able to add more capabilities and i'm going to be looking at adding some other capabilities so the new capability that i'm going to do is i'm going to add edit posts they should be able to delete their own posts so delete posts is going to be another so i'll wrap this in single quotes and then just add the true to each so true and save this so what we are going to do is create a new user this side and we're going to call them eric say eric at warner dot vala that's not an extension we know of so call him eric warner and uh we'll give them a show uh sorry an sms manager and then we'll give them a password or maybe dark tells 2020 dark tells 2020 so don't send them so let's save this and what we're going to do is come incognito so that we can see log on and then we shall put our local horse youtube and then at the end do slash wp admin so what i'm going to be looking for here is eric and then we're going to use our dark tells so we can now see that our sms manager actually cannot do so much so they can go to their profile edit it so what we're going to do is let's add some more roles and say edit published edit published posts uh there should be about upload files uh then publish posts is here delete publish posts so let's sort of make them like an author so delete publish posts so they're able to edit delete upload read publish posts edit and delete post so uh i'm actually going to just close this out and then i'm going to actually remove this role so let me remove this role it's going to be a string and i'll add sms manager uh let's reload this uh let's sign out and then deactivate and activate our plugin again let's go see the users and then we see now there's no role for eric and we don't have our sms manager so what i'm going to do is just comment this out then i'll add this role again and save let's reload this have sms manager it was stored in in there so let's go back to our incognito login to eric dark tells so when we log in now we can see that he actually has posts i is able to upload so we have attach media so we can actually compose he can see the posts that have been written can just view them because he doesn't have the powers to edit other people's posts so they can just view them but if we give him a role to edit other people's posts then he could be able to edit all of them so we want the person to just publish edit delete and read but what i'm going to do is i'm actually going to remove uh the delete posts for all because i don't think they should be able to delete the sms that they have set up so we're going to use basically custom post types to sort of trigger uh those are those posts so what i'm going to do is i'm going to they should not edit they're unpublished they shouldn't delete published uh they should be able to edit edit and delete but all those that have been published should not be published and then uploading files no they shouldn't publish so i'm just going to give them a few powers let's see what this looks like so first of all going to remove this role again save reload so they're not able to edit delete and then i am going to reload this role again save to this reload i need to reassign so they're able to actually create a new post the new post would be in your post that would be the new post publish it and then once we go back to the back end they're not able to see other people's posts they can only see their own post that they published and they cannot delete it so that's what we are looking at having as a post manager so you can be able to add so many roles you're able to remove a role if you need to do that for example i'm able to see a number of roles that remained after i removed certain plugins that should be going out with the plugins this is a big issue that i have with WordPress it when you're deleting the plugin it says will delete all the data and so on but this doesn't go out so as part of our removing uh when we are registering our function so part of the rules that i'll be adding when i'm deregistering our plugin so register deactivation so when i'm deactivating the plugin i'll add uh i'll use this file and i'll add a function which is basically just going to remove this role so save this then add this then i'll do a function which is a deregister role so sms manager deregister role so that will be the function we used to to register a role and all it's going to do is just remove the role of sms manager so i'll copy this and change it here in our functions and using single quotes to make this legitimate okay so we'll save that so on deactivation of this plugin let's say if i go to plugins and then deactivate this plugin what will happen is if i go back to users you actually see our hrequana doesn't have any role because i've deactivated that but when i reactivate i should be able to use this uh sms manager so let me just do that sms manager add role so i'll duplicate this and just remove the de to activate and then copy this and press this here so at the initialization of our plugin we are able to register the function or to deregister it in the event that we are letting the function go so this is a very simple thing that we did i hope you use it in your pro in whenever you're programming i'll go back to plugins activate this so if i come back to users we have erik and then sms manager so i hope you can use this information as you wish depending on your needs of your plugin so you can add a new user role or you can remove it give or take so enjoy using this new information that you found if you like the video please give it a thumbs up or leave a comment thank you for watching and bye bye