I am very experienced with Wordpress development, however, I have been asked to do something that I haven't before and my initial thoughts of setting and removing capabilities from individual users isn't working out too well...so I thought I would get a second opinion.
The situation is as follows: On the user edit profile screen in the admin area I have added some additional check boxes. The site has a few different custom post types, so there is a checkbox for each post type for User Can Moderate [Post Type] .
Each user on the site has the Author role, but what I want to do is manage the user capabilities so if say a user named John has the checkbox for Moderate Test Post Type checked they should be able to edit, publish and delete other people's posts in that particular post type. They should also be able to create , edit, publish and delete their own in that post type unless another checkbox is unchecked saying they can't create their own content.
Now I assumed that when saving the options I could bring in a WP_User object and add_cap and remove_cap on the custom post type. It works to an extent but it seems to trip up on itself and I'm not sure what I am doing wrong.
So for example, if the user is NOT able to create their own content but CAN edit, publish and delete other peoples content I would have thought removing the edit_posts, create_posts and delete_posts would do that and adding capabilities (replacing _posts with the post type) for edit_others_posts, publish_others_posts and delete_others_posts would do it, but it doesn't! If I remove their ability to create their own content I can't seem to get them to be able to edit other peoples content.
Has anyone any idea how to solve this?
Related
WordPress has some lovely features for storing revisions, editor approval of content, etc.
I'd like to expand on them by creating the concept of a user group/organisation.
I want:
to be able to attach posts to an organisation
to be able to attach users to an organisation (and ideally make it so that users can invite other users to their same org)
users can only make changes to posts in the same org as them, everything else is read only.
I can do the first two with a custom post type and an Advanced Custom Fields post object field, but I'm stumbling on the last one and would appreciate some pointers.
I imagine I would need to create a custom role with add_role(), but I'm not sure what capabilities it should have.
I imagine I'll need to override a hook somewhere to check if the thing the user is trying to edit is in their org.
Only relevant code so far is:
register_post_type("organisation");
First, on WordPress, the default user system is: admin can do everything, editors can edit every post, authors can only edit their posts.
There are some plugins like https://es.wordpress.org/plugins/user-role-editor/ that may be useful for your needs. Have a look at that!
Is there a way in which I can disable/hide specific fields from the "page form" in the back-end? I have currently test two plugins but none of them meet the requirement that I have, like for example this plugin "User Role Editor by Members – Best User, Role and Capability Management Plugin for WordPress":
I'm sorry that the options are in spanish but the capabilities options are for example: "edit pages", "edit other people's pages", "publish pages", "delete pages"... What I want is to hide certain sections to the "editor" user role from the page form:
Is this even possible?, and if not, what alternatives do I have?, the thing is that I'm afraid that whoever is in charge of editing will end up messing up with the pages...
Use Adminimize plugin It will resolve problem easily.
This plugin changes the administration back-end and gives you the power to assign rights on certain parts.
In most cases, the plugin "Adminimize" that Tech Sourav mentioned will work just fine, but since this page I'm working with is using some annoying custom content editor and other theme tools, the workaround that I ended up doing was:
Create a custom post type with the "Custom Post Type UI" plugin.
In this case I will only and always have 3 pages that have this "modifiable" price field, so once the custom post type is added I added 3 entries to this custom post type (here I will show you just one).
I'm also using the "advanced custom fields pro" plugin in order to create this price field into my entries.
When the custom field has been created there's this option inside the same previous form that allows me to show that specific field just created into specific post types entries, so I made up the rules in order to show this field in the created custom post type entries:
In this example I'm just showing you the rule for one entry, in order to make it appear on the other 2 entries, I would just click in the "agregar grupo de reglas" and select one by one.
Once this custom field and rules are configured correctly, I should see now the custom field "precio" inside my specified entries form:
After saving the entry with the updated custom field value, I will now check the post id and save it for later (we're going to need it):
According to the documentation of Advanced Custom Fields plugin I can show the saved value of certain input within certain post with the shortcode: [acf field="{$field_name}" post_id="{$post_id}"], in this case I will change the values to: [acf field="precio" post_id="1372"] and paste the code into the section of the page that I will show this:
The builder that this page is using has an element called "code block" but you can use it in the equivalent element that allows you to paste code from your theme.
After saving the changes, now the only thing that I have left is to restrict the ability to edit pages to a user with the "editor" role, for this I will use the plugin that I mentioned before in my question called "User Role Editor by Members – Best User, Role and Capability Management Plugin for WordPress":
As you can see, I will not let editor users to mess up with the pages post types, so with this, they will only be able to edit the custom post type that I created, which even if they write something inside the content of that custom post type entry, the website won't be affected at all. This may be a little bit hacky but it works...
I am working on a membership site with wordpress, buddypress, members, acf pro, woocommerce, a custom post type and the X theme.
All users will have a buddypress profile. However, an artist role will have access to post to the custom post type. I already have a custom post type setup. Currently, when a user signs up through buddypress registration form and they click the “I am an artist” radio button, they are automatically assigned the wp role named “artist”.
What I still need upon registration, to generate a sequential membership number for users with the artist role that will be displayed on the front-end. This number needs to last forever and not be affected if a user or profile is deleted. In other words, if a user is removed we don’t want everyone else’s number to change.
WordPress user ID will not work for several reasons. Primarily, because it is associated with all users and the signups will affect the sequential order of the artist numbers. It is important that artist numbers start at 000001 and increment up from there.
I am not a developer/coder. But I am not a total noob either, though I may need a little hand-holding to get through this. I have done an immense amount of searching for an answer to this situation but it seems that I must reach out for help. If you know how to do this I humbly request your assistance.
I am open to this number being assigned by php or by the database. I am also open to it being separate from buddypress, though if it is with buddypress, I still only want the artist role to utilize the membership number.
Below are some of other posts I have found that other people have attempted to do something similar. The fact that I need this to be role-based makes this even more complex.
I really need help and I want to learn. Thank you for your time.
How to generate sequential numbering in wordpress
https://slickmedia.co.uk/blog/glenns-blog/sequentially-number-wordpress-posts/
I'm trying to create a plugin in wordpress that allows you to age restrict certain posts and pages but not others. I looked for a plugin that does this and couldn't find one. I've got all the coding covered except I can't figure out how to instruct wordpress to save the state of the checkbox as data associated with that post or page. I dissected a couple of plugins that have similar functionality but am mystified by how their code works and it breaks when I try to modify it for my use.
Can someone point me to a tutorial that explains how data gets saved from the post edit page and how to access that data later?
check out post meta-data :
http://codex.wordpress.org/Custom_Fields
The basic idea is WP allows you to add additional fields to a post, and then retrieve it during the loop. Just use this field to test against at render-time and display alternate content, should (in this case) your post be restricted.
The codex is pretty thorough on the subject, and I'm sure google can fill in the gaps -
Hope that helps
In Drupal I wish to create a content type as a bio for a user. When you click on a a user name on the site it takes you to there bio. An example I have found online is below.
This article has the authors name Jeff Robbins. Jeff Robbins name links to his profile. How would you go about doing something similar? It does not seem be using the default profile module.
I would ideally only like this to happen for users in a certain group. For other users I wish just for there name to display but no link. Any pointers about how I would do this?
You've already got the core/programming route explained, so I thought I'd chime in with a few signposts on the install-a-module route. As always, with modules there is a bloated but supported solution and guidance on DIY.
Content Profile
Content Profile is a module specifically targeted at supported a User Biography as a node.
Here is an article describing how to add author biographies to nodes using Content Profile.
Author Pane
This module pulls information from the profile with an eye toward creating the sort of author information you would find to the left of a messageboard post.
Permissions
There are a couple modules that add finer control to the Profile permissions mechanism. There may be more, but these jumped out while I was looking for Content Profile.
Profile Role
Profile Permission
The node creator is stored in the node table (column UID), you could write something in a nodeapi hook to take that insert it as a field which can then be themed however you want. You could even in this hook put some logic to make the name a link or not depending on the roll.
You may want to look at the profile module, as this will allow you to set up a bio much more easily.
You can like Jeremy suggests do something like using hook_nodeapi(), but that seems like a bit overkill. I would instead use the template_preprocess_node() function. You could put this into a module or a theme. With it you can change the variable for $submitted, which holds the info for the author, date published etc. You can format it like you want, and keep the date and all that, and just instead make a different link on the user.
You could make it point anywhere really, so that the user is directed to a custom page that holds info on that user. It could a node on itself that you can setup with CCK ect, or you can use one of the profile modules that let your users customize their profiles, whatever works best for you.