WordPress.org

Ready to get started?Download WordPress

Forums

Cimy User Extra Fields
[resolved] Question: Default values for fields if user doesn't have permi (20 posts)

  1. Matt Jensen
    Member
    Posted 3 years ago #

    Hey there

    I was just wondering out aloud: for fields that have default values and that need certain permissions to be seen by the user, should the default value be entered in to the database when they submit the form but if the user can't actually see the field?

    I am inclined to think it should (particularly given I have this issue at the moment!). Part of the problem though comes from the fact that I am using custom roles (inc. WordPress' newer capability permissions system) as well as this plugin though, and that custom roles now seem to have the wp_user_level value defaulting to 0.

    Interested in any comments.
    Cheers
    Matt

  2. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    I actually didn't get fully, so I'll try to summarize:
    1. field not visible for the user
    2. default value to something

    and you want that even if the user cannot see the field, the default value is saved anyways?

  3. Matt Jensen
    Member
    Posted 3 years ago #

    Hey Cimmo, that is what I am thinking it should do, yes. But do you agree? So essentially it'd be like a default value for a database table column...

    The other approach to my issue would be me modifying the plugin so that different WordPress Roles capabilities can see the field, rather than different WordPress user levels as it works currently...

  4. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    Default value is saved only when field is visible and user saves first time, I like this behaviour.

    The second approach seems much better and actually adds a nice feature to the plugin that has been requested by other people.
    So either you can propose a patch or sponsor it I guess.

  5. Matt Jensen
    Member
    Posted 3 years ago #

    Hey Cimmo

    So part of the reason I was asking is so that I could potentially start working on a patch for it, and in line with where you'd like to take the plugin. However, for all your great work I've been meaning to get around to donating to your plugin anyway, so I finally have just done so now. It's not a lot (the Canadian to Euro exchange rate is not great!), (and I'm actually using the plugin currently for a non-profit website), hopefully it's something nice for you anyway though.

    So I'll be taking a look at a 'patch' sometime soon too. Speak later.

    Cheers
    Matt

  6. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    So basically you want an extended dropdown where to choose:
    Do not edit this field if not capable of...

    and the list from:
    http://codex.wordpress.org/Roles_and_Capabilities#Administrator

    plus all the custom capabilities assigned to the administrator.

    Am I understanding right?

  7. Matt Jensen
    Member
    Posted 3 years ago #

    Hey Cimmo

    I've been thinking about this as well, and I can think of 2 options. It depends on how clever/complicated you want to make it.

    1) The simplest option would be to change the dropdown menu for "Show the field if the role is at least:" to say "Show the field if the role is capable of:", and make the options:
    - None;
    - List_Users (which would correspond to the list_users capability);
    - Edit_Users (which would correspond to the edit_users capability);

    Or you could list all options as you suggest - although I don't think that's necessary personally...

    2) The other option would be to create a new capability for your plugin called something like 'edit_cimy_field', and change the "Show the field if the role is at least" field to be just a checkbox which says something like "Show the field only if the role has the 'edit_cimy_field' capability".

    I'm not sure how hard this second option is. The 'MailPress' plugin is a good example of this (it has it's own custom capabilities for roles, as well as a 'Roles Manager' Add-on to manage Roles and capabilities). Another good example is Justin Tadlock's 'Members' plugin, which has a Roles management feature (I'm using both these plugins on a site with your plugin actually :-))

    Whichever is easiest. Of course supporting older versions of WordPress may become problematic here (or perhaps you don't need to support them for future updates to your plugin).

    HTH

    Cheers
    Matt

  8. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    Uhm 2 is much better, creating a role is very easy, but then you'll have to use another plugin to assign that to non admin users.
    I'll go for that.

  9. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    > "Show the field only if the role has the 'edit_cimy_field' capability".

    Actually for the edit there is another rule that is the:
    Can be modified only by admin
    Which rule are you talking about exactly?

  10. Matt Jensen
    Member
    Posted 3 years ago #

    My suggestion was to add a new role *capability* to WordPress. The capability could be called something like 'edit_cimy_field'.

    Then, in your plugin, you could change the setting 'Can be modified only by admin' that is in the admin pages for your plugin to read something like 'Show the field only if the role has the 'edit_cimy_field' capability'.

    Then in the code for the plugin, rather than checking if the user is in the 'Admin' role, you could check whether the user is in a role that has the 'edit_cimy_field' capability.

    And therefore, your plugin wouldn't be tied to specific role *names*, but would cater to the "extensible role model" I think WordPress is moving to. But as you say, to make modifications to which role has the 'edit_cimy_field' capability, people would need another plugin for managing roles. But if you were to make it so that the 'Admin' role gets the 'edit_cimy_field' capability when your plugin is installed, people wouldn't necessarily need a role management plugin.

    The MailPress plugin does exactly this - it creates a few of it's own WordPress capabilities. And it also has a 'role manager' feature too. It'd be worth taking a look at the plugin to see how hard this option would be. Option #1 above may be simpler though. Or course it's up to you though.

    Cheers
    Matt

  11. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    And I repeat once more:
    one thing is to see the field
    one thing is to edit the field

    with my plugin you can set both rules but you are mixing them like is the same one, but is NOT.
    For example with my plugin you can let the non admin SEE the field, but NOT edit.

    I already understood you want one more role, but you want the role for SEEING or for EDITING? This is the point.

  12. Matt Jensen
    Member
    Posted 3 years ago #

    Hey, sorry for the confusion, you are right.

    From memory, this is why I thought option #1 above could be simplest actually, as no role capability management would be needed as the plugin could just use each roles existing capabilities, and in fact, potentially you wouldn't need the 'can be modified by ...' and 'show the field if ...' options for each field anymore either (as it would be implied by the role each user was in).

    So I guess for option #2 you would need two new capabilities that could be assigned to each role.

    Hope that answers the question, sorry for the confusion.
    Cheers
    Matt

  13. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    Actually I have to apologize as well as I made confusion too, let's summarize:
    1. if you set the rule to not view the field for non admin then non admin user cannot see it and cannot modify it
    2. if you set the rule to not edit the field for non admin then non admin user may see (depends on point 1.) but definitively not edit it.

    This allows you to let non admin see the field, but not edit it, might be useful.

    Said this I created a new capability named "view_cimy_extra_fields" and is added to Administrator role first time you open plug-in's options.
    Then you can modify the rule "Show the field if at least" -> "User has 'view_cimy_extra_fields' capability"

    Please download dev version and try it out:
    http://downloads.wordpress.org/plugin/cimy-user-extra-fields.zip

    I hope this is enough to solve your problems, let me know.

    regards
    Marco

  14. Matt Jensen
    Member
    Posted 3 years ago #

    Hey Cimmo

    So I've tested it out in my setup and it seems to be pretty good. I gave a reasonably good test of everything I think.

    The changes you made re the new capability seem to work great.

    The only issue I did find was, when logged in to an account using one of my custom Admin roles with the 'view_ cimy_extra_fields' enabled, when I went to edit another user's profile, when I clicked the 'update' button it failed, saying that one field that was not visible "couldn’t be empty". The settings for this field in question are:
    - dropdown-multi
    - Value (ie. default): No
    - Can be modified only by admin
    - show the field in the User's profile
    - Show the field if the role is at least 'Administrator'

    Actually, I've just realised that this field should have been set as "Show the field if the role is at least: User has 'view_cimy_extra_fields' capapability".

    So I've just updated the field, and now it all works.
    So actually, I'm not sure if this is a problem or not. Maybe all fields that can only be modified by only admin must have the same value for the 'show the field if the role is at least' setting...('view_cimy_extra_fields' in my case)?

    Hmm, not sure.

    Hope this helps.

    Cheers
    Matt

  15. Matt Jensen
    Member
    Posted 3 years ago #

    By the way, thanks again, looks great so far!

  16. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    I am interested in the bug, so the field was visible? What does it mean exactly custom admin?

    Right now visible to only admin and to user that has 'view_cimy_extra_fields; cap are not the same:
    only by admin means _really_ only by admin, who has level 8 or higher.
    the other depends on who you assign that role, initially is only admin, then can be everyone.

  17. Matt Jensen
    Member
    Posted 3 years ago #

    Hey, no the field wasn't visible to this admin user, but they got the error message that it can't be empty.

    Using Justin Tadlock's Members plugin, I've created some "custom admin" roles for the club members that are on the club committee - for example, some of them can update members profiles (eg. to say they paid their membership for this year). And for these roles, I've given some of them the 'view_cimy_extra_fields' capability (and by the way, because it is a custom role, the role has a level of 0 (given WordPress doesn't seem to user Levels any more)). So this custom role shouldn't be able to see or edit this field, but obviously they then shouldn't get an error saying that the field can't be blank given they can't see it.

    HTH
    Matt

  18. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    Indeed was a bug there since ages, strange nobody noticed before.
    Can you download again and test with the above settings that triggered it please?

    EDIT:
    Indeed I introduced with my latest patch, wasn't there before :)

  19. Matt Jensen
    Member
    Posted 3 years ago #

    Hey dude, sorry for the delay responding.

    Ok, I've just done some fairly thorough testing.

    - reproduced the bug on the older dev version of the plugin
    - upgrade to the new plugin
    - verified the problem went away

    Then I tested:

    - creating a user
    -updating a user
    -updating another user
    -updating my own profile

    for each of the following user types:

    - a full Admin
    - a 'custom' Admin with 'view_cimy_user_field'
    - a normal user with no admin related permissions (although obviously I couldn't test updating other users since this user didn't have access)

    and all tests passed.

    So looks good thanks very much Cimmmo!

    Cheers
    Matt

  20. Marco Cimmino
    Member
    Plugin Author

    Posted 3 years ago #

    Cool, thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic