Support

Account

Home Forums Backend Issues (wp-admin) Groups not showing for non-admin users

Solving

Groups not showing for non-admin users

  • All the field groups show up when logged in as an admin, but not when logged in as another user role. I’ve tried removing plugins, changing the settings for that field group, and changing permissions, but nothing has worked so far.

    I’m using BusinessDirectory+ by AiT-Themes, and ACF Pro.

  • More than likely there is a filter that’s interfering with the display of field groups, here’s a related topic https://support.advancedcustomfields.com/forums/topic/custom-fields-not-showing-for-non-admin/

    The first thing you need to do is deactivate all other plugins and change to a standard theme to see if you can clear up the issue and narrow down what could be causing the conflict.

  • Okay, so I realized that the custom fields are showing up on the edit page for the custom post type for non-admins, but not when they’re initially creating the post. If they save the post as a draft or publish it, then the custom fields will display.

    I don’t think this problem has to do with the theme or plugins. I tried changing the theme and deactivating everything, but the problem was still happening. I also tried creating a new custom post type, and the issue was still occurring for non-admins.

    Any reason why it’d be doing this?

  • This can also happen because of at JavaScript error or a PHP error during the AJAX request.

    What are the location rules for the field groups that are not appearing?

  • “Post Type is equal to Listing” is the rule. ‘Listing’ is the name of the custom post type

  • Giving the information I have I would say that this is more than likely due to the theme or another plugin. You need to deactivate other plugins to rule them out and switch to a basic theme to rule it out.

    Look for errors.

    1) Are there any JavaScript errors

    2) Enable debugging and turn on error logging and see if there are any PHP errors reported during the AJAX request. https://codex.wordpress.org/WP_DEBUG

  • I turned on debugging, but can’t detect any JS or PHP errors

  • This could have something to do with the permissions set up for the post type in the theme, I think I remember something in the past similar to this. Unfortunately, I can’t really test this and I don’t remember what the solution was.

    Here are a couple related topics (it seems that a pre_get_posts filter not done correctly could also do this) https://support.advancedcustomfields.com/forums/topic/custom-fields-not-showing-for-non-admin/, https://support.advancedcustomfields.com/forums/topic/acf-fields-not-showing-for-wp-membership-groups/

    Have you tried using a different theme and testing to see if non-admin users can see field groups?

  • I’ve tried turning off my theme, creating a new custom post type, and making the rules for the groups to also display for that custom post type. I also gave that user type all the same permissions as an admin using User Role Editor. The same thing happened. Are there any permissions specifically for ACF that would be missing from the rest of the permissions?

  • If you could, just as a quick temporary fix, do you know if there’s a way to change the ‘Add New’ button to just create and save a blank draft? And then maybe to redirect to the edit page for that newly created blank draft? That way the custom fields would show up regardless.

  • Or is there a way that I could manually add the ACF metaboxes for the “Add new” form myself? Maybe in functions.php?

    If it helps diagnose the problem, for some reason this user type can’t create drafts. Whenever they save the custom post type, it automatically becomes “Pending.”

  • I cannot recreate your issue. I created a CPT and any user type that can edit the CPT can see the custom fields I add to it. You’re issue has to be something to do with something in another plugin or your theme.

    You need to figure out what you have that’s causing the issue by deactivating other plugins and narrow it down.

    As far as your other questions, I don’t know how to do any of those things.

  • Hi, run in the same problem with an AIT Theme (Eventguide),

    First im new to wordpress but i found out that there is a problem with a filter.

    My custom usergroups can not see the customfields the problem is in this:

    function altered_search($query) ...
    
    		/* Display posts in admin for current user only */
    		$wp_user = wp_get_current_user();
    		if(isCityguideUser($wp_user->roles)){
    		$query->set('author', $wp_user->data->ID);
    		} 
    
    add_filter('pre_get_posts', 'altered_search');

    When i comment the add_filter out the custom fields display but the user can also edit other post types.

    Does anyone have a solution or a hint for this?

    PS: The support from ait answer:

    Hello, seems like the filter which is needed to filter posts and show only posts created by currently logged in user may cause the problem, it’s part:
    if(isCityguideUser($wp_user->roles)){

    $query->set(‘author’, $wp_user->data->ID);

    }
    Unfortunately it’s important part for theme core functionality and users registered via our theme. I am sorry but we are not capable to customize theme scripts per customers needs to make working all third party plugins. Seems like this filter needs some workaround in order to work with other parts like custom fields from plugin.

    Thanks for understanding, Ivan.

  • The problem with the filter is that there isn’t sufficient checks to make sure that the filter is only filtering the posts it should be filtering and it filters everything… or at least that’s the case with the code I can see.

    The response from their support is simply wrong. There are many, many plugins that use CPTs to hold data that should not be filtered on only the basis of the current user role.

    Can you supply the code for the entire filter function.

  • Hi John,
    thank you very much for your efforts, here is the hole part, hope you can help 🙂

    /* CUSTOM CITYGUIDE FUNCTIONS */
    function isCityguideUser($wp_roles = array()){
    	$result = false;
    	if(count($wp_roles) == 0){
    		$wp_user = wp_get_current_user();
    		$wp_roles = $wp_user->roles;
    	}
    	foreach ($wp_roles as $index => $role) {
    		if(strpos($role, 'cityguide_') !== false){
    			$result = true;
    		}
    	}
    	return $result;
    }
    
    /*****************************************************************************/
    /****** PLEASE KEEP HERE ONLY CODE WHICH IS COMON FOR ALL GUIDE THEMES *******/
    /******** CUSTOM pre_get_posts FILTERS ARE IN ait-custom-functions.php ********/
    /*****************************************************************************/
    function altered_search($query) {
    	if($query->is_admin) {
    		// hotfix - wordpress consider all ajax calls as is_admin call
    		// on fronend logged users could see only their items/events
    		// TODO: replace by filter where I can register all custom ajax actions/handlers
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:getHeaderMapMarkers') {
    			return $query;
    		}
    
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:retrieve') {
    			return $query;
    		}
    
    		/* Display posts in admin for current user only */
    		$wp_user = wp_get_current_user();
    		if(isCityguideUser($wp_user->roles)){
    			$query->set('author', $wp_user->data->ID);
    		}
    		
    	} else {
    		if($query->is_main_query()){
    			if (isset($_GET['s']) && empty($_GET['s'])){
    				$query->is_search = true;
    			
    			}
    
    			// is woocommerce search
    			if(isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'product'){
    			
    				return $query;
    			}
    			
    		
    			$query = apply_filters( 'ait_alter_search_query', $query );
    			
    			
    		}
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'altered_search');
  • The first thing is that query changes like this should only be set on the main query. This is done in the second part, but not on the first.

    
    function altered_search($query) {
    	if($query->is_admin) {
    		// hotfix - wordpress consider all ajax calls as is_admin call
    		// on fronend logged users could see only their items/events
    		// TODO: replace by filter where I can register all custom ajax actions/handlers
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:getHeaderMapMarkers') {
    			return $query;
    		}
    
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:retrieve') {
    			return $query;
    		}
    		
    		// ADD THIS AND TEST
    		if (!$query->is_main_query()) {
    			return;
    		}
    
    		/* Display posts in admin for current user only */
    		$wp_user = wp_get_current_user();
    		if(isCityguideUser($wp_user->roles)){
    			$query->set('author', $wp_user->data->ID);
    		}
    		
    	} else {
    		if($query->is_main_query()){
    			if (isset($_GET['s']) && empty($_GET['s'])){
    				$query->is_search = true;
    			
    			}
    
    			// is woocommerce search
    			if(isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'product'){
    			
    				return $query;
    			}
    			
    		
    			$query = apply_filters( 'ait_alter_search_query', $query );
    			
    			
    		}
    	}
    	return $query;
    }
    
  • Thank you very much!

    i´ve tested your input and now the custom fields work as they should:) the only thing is that the user now see all uploaded files in the media library and not only his own…

  • You will need to do some more tweaking then to be more specific and eliminate only certain types of CPTs from the change.

    Instead of the condition I gave you try something like this

    
    if (isset($query->query_vars['post_type']) && 
        ($query->query_vars['post_type'] == 'acf-field' || 
         $query->query_vars['post_type'] == 'acf-field-group')) {
      return;
    }
    

    Honestly, this it should be the other way around, only applying the change to a specific set of post types. But I don’t know all the post types that should be limited so I wouldn’t know how to do that.

  • You are the man!

    Now all works as it should.

    Thank you very much for that awesome support!

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

The topic ‘Groups not showing for non-admin users’ is closed to new replies.