• Resolved lllor

    (@lllor)


    Hello dear sirs,
    I have extend the default WP user entity with Pods, adding some text fields and also a couple of media. Some of those fields are mandatory, others are not.

    But…those new custom fields are now added to every user, despite its role. Even the administrators*! Which, to me, doesn’t make sense. Super-users should be excluded by the extensions; better, I should be able to select which kind (read: role) of user I’m extending.

    Maybe I’m missing a way to select the roles whose will be affected by the extension? Also via coding (filters, actions, whatever…)

    Thanks in advance for the support!

    *administrator must fill the mandatory fields in order to update its password…

    • This topic was modified 5 years, 1 month ago by lllor.
    • This topic was modified 5 years, 1 month ago by lllor.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter lllor

    (@lllor)

    any suggestions?

    cheers

    Plugin Contributor Jory Hogeveen

    (@keraweb)

    Hello @lllor,

    The only difference between admins and other users is their role, nothing more. So extending a user will also extend an admin.
    Currently Pods does not support enabling/disabling fields based on parameters from the object.
    However, with the Field Groups coming in the next major releases this will probably be something we can support.

    Cheers, Jory

    Plugin Contributor Jory Hogeveen

    (@keraweb)

    In addition to the above, if you are comfortable with PHP you can always dive into the codebase and use hooks to modify the fields based on the current user.

    Thread Starter lllor

    (@lllor)

    Thanks for your reply, Yes I’m comfortable with php. Which pods hooks should I aim?

    I’m not expert of pods internals, but I don’t get why I must look at the current user, shouldn’t I control the user I’m creating?

    Plugin Contributor Jory Hogeveen

    (@keraweb)

    You could look into pods_meta_groups_get and remove fields (array keys) when they shouldn’t be visible. I havent tested this though.

    I’m not expert of pods internals, but I don’t get why I must look at the current user, shouldn’t I control the user I’m creating?

    This has nothing to do with Pods internals. With current user I mean the current user profile being edited in your hook function.
    You could add a check like if ( is_super_admin ) {} or if (current_user_can( 'manage_options' ) ) or something that matches your criteria.

    Thread Starter lllor

    (@lllor)

    I don’t think it’s related to the current user, but to the user’s usermeta I’m (as admin – the *current* user) inspecting. I can (as admin) edit its custom fields (and that’s good!).

    Anyway, thanks for the hint: I will look at pods_meta_groups_get to see if I can manage some sort of workaround. In case of success, I will write here the solution.

    Cheers.

    btw, I would not rely on is_super_admin since it verifies only if the user can delete other users (which sometimes is true also for non-admin roles). See ticket 4738 https://core.trac.wordpress.org/ticket/47338 (opened by me…)

    Plugin Contributor Jory Hogeveen

    (@keraweb)

    You misunderstood what I meant with “current” user. We meant the same haha ;).

    And correct is_super_admin() isn’t the best idea for single installation. (I always work with multisites so I use it quite often).

    Good luck and indeed please share your solution!

    Cheers, Jory

    Thread Starter lllor

    (@lllor)

    add_filter('pods_meta_groups_get','pods_group', 10, 3);
    
    function pods_group($groups, $type, $name) {
        
        global $user_id;
        
        if (is_super_user($user_id) ) {//custom function that verifies if the user has managing capabilities
            $groups[0] = null;
        }
        
        return $groups;
    }

    that works in profile.php and user-edit.php (which define a global $user_id). I’m not so sure in terms of software architecture is the right solution, but it works.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Extend WP user entity’ is closed to new replies.