• Resolved Matt Jensen

    (@ultrawebsites)


    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

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author Marco Cimmino

    (@cimmo)

    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?

    Thread Starter Matt Jensen

    (@ultrawebsites)

    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…

    Plugin Author Marco Cimmino

    (@cimmo)

    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.

    Thread Starter Matt Jensen

    (@ultrawebsites)

    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

    Plugin Author Marco Cimmino

    (@cimmo)

    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?

    Thread Starter Matt Jensen

    (@ultrawebsites)

    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

    Plugin Author Marco Cimmino

    (@cimmo)

    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.

    Plugin Author Marco Cimmino

    (@cimmo)

    > “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?

    Thread Starter Matt Jensen

    (@ultrawebsites)

    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

    Plugin Author Marco Cimmino

    (@cimmo)

    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.

    Thread Starter Matt Jensen

    (@ultrawebsites)

    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

    Plugin Author Marco Cimmino

    (@cimmo)

    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

    Thread Starter Matt Jensen

    (@ultrawebsites)

    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

    Thread Starter Matt Jensen

    (@ultrawebsites)

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

    Plugin Author Marco Cimmino

    (@cimmo)

    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.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Plugin: Cimy User Extra Fields] Question: Default values for fields if user doesn't have permi’ is closed to new replies.