Home Forums Backend Issues (wp-admin) Custom User Admin Page


Custom User Admin Page

  • I’m building a CRM plugin and have built a tabbed set of ACF fields for editing user meta which appears on the user profile editor in the admin under user-edit.php?user_id=2. So far, so good.

    The issue I have here is that my ACF fields are buried under all the default user meta fields in which my client has no interest. What I’d like to do therefore is display just those fields on a custom admin page.

    So I have my admin menu and various admin pages including a custom table of all the users with of specific ‘client’ roles. Clicking on those clients takes you to a URL like admin.php?page=crm-client&user=2. THIS is where I’d like my ACF user fields to appear.

    I’ve gone down a whole rabbit hole of building in custom location rules but, so far as I can tell, they just don’t get hooked in on my custom admin pages so I’m thinking that I need another approach: might it be possible to somehow set-up the user object on my custom admin page and ‘trick’ acf into displaying the fields because it believes that default location rule “User role” “is equal to” “x” to be true, i.e.: that we are looking at a user?

    Any and all suggestions are welcome. I’m finding very little useful stuff online relating to customising the admin experience for editing users.

    Many thanks

  • Hi Nugerama,

    I’ve run into a similar situation myself a while back. The solution is more WordPress rather than ACF related. My suggestion would be to use the admin_head action hook to add custom CSS in WP-admin and simply hide the fields you don’t want to show. Most fields still need to be loaded in to be sure that the value isn’t lost. But those fields don’t need to be visible to the user for that.

    There are some fields though you can remove by simply removing them using the user_contactmethods filter. Like for example below:

    function update_contact_methods( $contactmethods ) {
        unset( $contactmethods['aim'] );
        unset( $contactmethods['jabber'] );
        unset( $contactmethods['yim'] );
        return $contactmethods;
    add_filter( 'user_contactmethods', 'update_contact_methods' );

    Let me know if this worked for you or you need any further assistance or ideas.

  • Hi, ReHo20. Thanks for those pointers. After posting this question I found that I could pass a post_id, or more specifically a **user id** to the acf_add_options_sub_page() function which enabled me to effectively have an options page which works for editing user meta. The steps I used were:

    – Sending the user to admin.php?page=crm-client&user=2 via a custom table of users on my plugin landing page in admin

    – Creating an options page with acf_add_options_sub_page() with post_id set to $_GET the user_id from the URL

    – I set the position to 99 and then hid that menu item with CSS so that my client wouldn’t find themselves on the Client Settings page without an id in the URL, i.e.: they can only get to it via the user table

    And it works like a charm! This was always a more desirable solution than hacking the default WP user page in admin as it gives me much more control and means that we still have that more detailed user options page at our disposal.

    Thanks again for taking the time to share your solution.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.