I asked this question over on the WordPress StackExchange but was told it was off-topic for there. I hope it is correct to ask it here instead.
A client has asked that I setup the Contributor role in WordPress so that it can only view/edit/delete their own posts from a CPT called 'members'. I have done this using Justin Tadlock's Members plugin + a small snippet of code since they only want the Contributor's to be able to see their own posts & not others (even if they can't edit them).
Everything is working well except for Advanced Custom Fields. The client is using this to provide extra fields on the 'members' CPT, but unless I give the Contributor role the 'edit_others' capability they are unable to see the fields created by ACF.
Is this an issue with ACF, or with WordPress? I am still fairly new to Roles & Caps and I cannot seem to understand how to change this. If possible I would like the ACF fields to be visible on the 'edit_members' capability.
Add the 'edit_others_posts' to your user role.
I had same problem, and after some trying out different combinations, have found that this capability needs to be enabled.
The problem is not in roles or capabilities, problem is how you limit the edit-posts dashboard for non-administrators. Your if-statement should not be performed on edit-post page, only at post listing page (for example, if you use pre_get_posts to restrict posts editing for admins only, then you must not run this pre_get_posts function at posts.php page).
Also example from ACF support forum.
This issue has been posted a long time ago, but I believe there is still someone facing it at the moment. So I would like to make it easy to understand.
First of all, we have to separate it into two parts.
First, the relationship between user, role, and capability. Let's say, each user has a roles, and each role has capabilities. It is one-to-many relation from top down.
Second, custom post type(CPT), advanced custom field plugin (ACF) and ACF extension plugin.
Each custom post type can be done for a specific capability and all fields under the custom post type has been done by using ACF.
Lastly, not all fields need to appear on every user who has the role that included this capability. Some field need to be appear for just for some specific role which has this capability included. This is where ACF extended plugin step in. It is sound complicate isn't it? Let have a look the chart below.
With acf_permission, you can be able to specific the role for be able to see the field like below.
`[instruction_placement] => label
[hide_on_screen] =>
...
[acfe_permissions] => Array
(
[0] => administrator
[1] => editor
)
...`
This might not fully answer the question but hope it will help to clear how does it work together.
https://www.acf-extended.com/features/field-groups/permissions
Related
Right now I am using the ultimate member plugin to register users. But the company asked me to change the form and allow users to insert their education qualifications in a table when registering. Users need to have a button that has the ability to insert more rows (If they have more qualifications).
As far as I know, I can't use the Ultimate Member plugin for that. I searched for many table plugins but didn't find anything that can do this task. I once had done this using code. But I don't know how to apply it to this registration form. If anyone can figure out a way to embed the code to Ultimate member (to save that table data) or any plugin that can do this, please let me know soon as possible.
Updated Question
I have tried that shortcode and got confused as it ruined the page. Now I'm trying a PHP method to solve this problem.
Thank You
Well you have many options to solve this problem. What you are actually looking for is Custom Fields.
WordPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as metadata.
Now, custom fields can be created in 2 ways.
Either you write php code in a plugin/theme
Or you you install plugin which helps you build custom fields.
What you are actually looking for is to create Repeatable Field Groups. These are the field which can be replicated. As many as you want.
Some plugins which provide facility to add them in no particular order are:
Advanced Custom Fields - Repeater Field : https://www.advancedcustomfields.com/resources/repeater/
Toolset - Repetable Field Group : https://toolset.com/course-lesson/creating-and-displaying-repeatable-field-groups/
Metabox - Meta Box Group : https://metabox.io/plugins/meta-box-group/
They all will give you ability to create repeater fields.
Repeater field can be made for both users and posts or Custom Post Types(CPT). You need them for Users. I am not sure which one of them allows you to create repeater field for Users but you can check on there website.
PS : These are all paid plugins. (They may have free version of them but repeater field comes with PRO).
Once you have created a field for users you can use that field in your registration form.
UPDATED ANSWER
As the question author wants to add the field using PHP, the field can be added as so.
After looking at all the hooks available to the user by UM (Ultimate Member) plugin. I found two hook that can be used to add fields and save in the backend.
um_after_form : Some actions after register form fields.
add_action( 'um_after_form', 'my_after_form', 10, 1 );
function my_after_form( $args ) {
// add your repetable fields here.
}
um_after_save_registration_details : Action on user registration after save details. This runs after the form is submited and user is registered. Use this to save data inside the user database.
add_action( 'um_after_save_registration_details', 'my_after_save_registration_details', 10, 2 );
function my_after_save_registration_details( $user_id, $submitted ) {
// Save field here.
// You have user_id and submitted data, do your thing here.
}
I currently have a custom taxonomy select field called "Location" and another custom taxonomy called "Company". What I would want to do is to hide/show the Company check-boxes based on the chosen Location in the select box. This is for the back-end.
The Person custom post type is associated with a Company and each Company is associated with a Location taxonomy. Advanced Custom Fields conditional logic does not extend to taxonomy fields and if anybody knows a way to go around this limitation that would be super awesome.
I am looking for taxonomy-related conditional logic as well and I found a post on the ACF support forums (http://support.advancedcustomfields.com/forums/topic/conditional-logic-using-taxonomy-field/) that shows many other people looking for this as well. However, there was no solution or answer in this post (most recent post asking for help being 6/7/16). Perhaps it will be solved in the future given the many requests, but no answers there at present.
Seems that the best option for now is to use jQuery on the backend.
I'm trying to use the value of one custom field on multiple pages and posts. I'm a newbie to PHP and custom fields so what I'm trying to accomplish could possible be done using a different method.
I have a WPMU setup with all new sites created from a default blog that includes multiple custom post type templates. When users create a new site they are redirected to their site admin dashboard.
Here comes my challenge, I want users to be able to enter information into form fields contained in metabox(es) on their admin dashboard (not post editor) that will be used on the various custom post type templates. For example, a user will need to enter their company name, address, logo, etc.
Depending on the temple, the information entered into the form fields will be used on the frontend of the site. For example, the company logo will be display where the custom field or shortcode is placed on the post template.
I'm having issues using custom fields for this because each custom field is specific to each post. In addition, I'm having issues rendering a form on the admin dashboard for this.
I'm also thinking that custom fields may not be the best way to accomplish my objective because they are usually post specific. I'm really asking for a variable that will be used globally and is static unless the user updates the form.
I'd appreciate any assistance on this.
The options API is what you will need for this:
http://codex.wordpress.org/Options_API
There's also some plugins and frameworks you can use to help such as:
https://wordpress.org/plugins/options-framework/
https://wordpress.org/plugins/redux-framework/
I'd like to add a new role to my Wordpress site. It needs more permissions than Author, but fewer than Admin. Searching the codex and Stack, I have come across a consistent method of adding this code to functions.php, but a repeated error resulted in me trying the User Role Editor plug-in.
Users under this new role need to be able to edit, see, delete, and managed all posts, categories and tags. They also must be able to manage all comments, both approved and pending. Additionally, they should have access to Discussion settings. This last bit seems to be impossible, though. I can give them the ability to manage options, but not specific options. Is there a way to grant such a specific capability?
Thanks.
A client of mine has a site in wordpress, with one section being a directory of agents that each have different text and videos associated with them.
The client wants to be able to easily add/remove/change these agents from within the wordpress admin interface. There will be anywhere from 50-75 of these agents, so doing each page manually is not very attractive.
We currently have 3 agents added as posts, and i understand that we can store additional information inside the post itself, so that is not a problem. What we would like to create is a simpler way of managing those pages where the content cannot be changed by the maintainer, and the additional fields on the post are hard coded so there would be no room for user error.
What i am interested in is if anyone has done something similar in the past and can share their approach and experience, or if anyone can point me in the right direction as to how i can accomplish this and what i need to be aware of.
Thanks.
Yes, Custom Post Types are a perfect fit for your needs. Here are some links to articles explaining them:
http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
http://www.wpbeginner.com/wp-tutorials/how-to-use-custom-post-types/
http://thinkvitamin.com/dev/create-your-first-wordpress-custom-post-type/
You can use a plugin like Custom Post Type UI or just add the register_post_type() calls to your theme's functions.php file:
http://wordpress.org/extend/plugins/custom-post-type-ui/
Then you can use a plugin like "Simple Fields" to add metaboxes to your Agent post type (although there are numerous plugins offering similar functionality; I'm building one myself!):
http://eskapism.se/code-playground/simple-fields/
Hope this helps...
Have you thought about using custom post types? You could create type called Agent and then each agent would be like a post. That way you could search for specific agents easily in the admin and then go in to the post for each agent to change their details.