In my website there is a master admin and some editors.
Each editor can edit and fill some custom fields too (meta boxes added by Meta Box plugin APIs) but I need to restrict editing and showing some custom fields to that group but didn't found anything related to this topic.
any help will be appreciated.
There are two free plugins that will work together to accomplish this, and more...
The first plugin is Advanced Custom Fields: http://wordpress.org/plugins/advanced-custom-fields/
Advanced Custom Fields lets you create and assign groups of custom fields to specific user roles or post types.
The second plugin is the Members plugin which extends and allows customization/creation of user roles: http://wordpress.org/plugins/members/ .
How it works. Use the Members plugin to create a new user role with the same (or whatever you like) permissions as Editor, call them 'Editors Plus'. Then use Advanced Custom Fields to create a custom field group that only 'Editors Plus' can access. IE: Show this field group if: 'User', 'is equal to', 'Editor Plus'. All of it happens via easy GUIs.
Register a new role with help of this link:
http://codex.wordpress.org/Function_Reference/add_role
and then apply authentication to this whatever you want.
thanks.
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 was following this blog post https://www.themelocation.com/how-to-add-custom-fields-to-user-registration-form-in-woocommerce/ to learn about creating custom user fields in Woo (for registration).
The post above worked, and I was able to see new fields during registration, but I had two questions:
How can I get these fields to appear when I'm editing a user in wp-admin? I didn't notice them rendering on the edit user page.
Right now Woo (by default) lets you just register with an e-mail. I wanted to also use a first name and last name (my custom fields), but this is already a field on the users in WordPress, so I don't want to duplicate fields. Is there a way to somehow pull in/use/associate an existing field (such as name) during the Woo registration?
Thanks so much for any help/guidance you all can give me.
1 You can use this plugin for display your custom fields in the admin view.
2 In your template HTML file, find the form, and use the default id & name tag : "Firstname" / "Lastname" ...ext
When I create a custom form for a custom user role using ultimate member plugin, it doesn't work. Only the default profile form works. Please what can be the problem. I need to create different profile forms for different types of users
The cause of this issue is that the original User page only contains the shortcode for the default profile form.
After you create all of your custom profile forms, and assign the relevant roles to each (Form Settings -> Disable Global Settings -> Select Role), you need to add the short codes of all your forms to the User page, just one after another.
UltimateMember will decide which of the forms to display depending on the user's role.
So on the view user page, add the shortcode for the custom form, in addition to the existing default profile form.
It's a bit weird to have multiple shortcodes but it will only show the one for that role.
Also make sure to assign a the Custom Role to the Custom Form, as stated by Michael Rodriguez
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/
As part of my theme install, I'd like to add a set of custom field options to the wordpress database that would be available to all posts as long as my theme is active.
For example, I'd like to add these fields:
custom-image-1
custom-image-2
custom-image-3
And also these
custom-image-1-link
custom-image-2-link
custom-image-3-link
And then when a user goes to add or edit a post, they can insert values for each of these fields if they choose to...
You simply have to create a post and add these custom fields once to have them proposed for every next posts (in the custom fields part of the form).
If you need to create a more integrated interface for these extra fields, you might be better off creating a plugin or looking for existing ones, such as this one.
Use the add_meta_box function that comes with WordPress.
https://developer.wordpress.org/reference/functions/add_meta_box/