Change WordPress user roles and capabilities Forums How to or FAQ Set Posts to manage at User level but by an ACF setting Reply To: Set Posts to manage at User level but by an ACF setting

#6702
edering
Participant

Hi Vladimir,

I took your recommendation above and to use the ure_edit_posts_access_id_list function and created this:

add_filter('ure_edit_posts_access_id_list', 'ure_edit_posts_access_set_id_list_cu');

function ure_edit_posts_access_set_id_list_cu($list) {

	$current_user = wp_get_current_user();

	$ag = get_field('analytics_group_name','user_' . $current_user->ID);

	if(!isset($ag)){

		return; 

	}else{

		$posts = get_posts(array(
			'numberposts'	=> -1,
			'post_type'		=> 'page',
			'meta_query'	=> array(
				'relation'		=> 'OR',
				array(
					'key'	 	=> 'analytics_group_name',
					'value'	  	=> $ag,
					'compare' 	=> 'IN',
				),
			),
		));

		foreach($posts as $post){
			$list .= $post->ID.',';
		}

		$list = rtrim($list, ',');

		wp_reset_postdata();

    	return $list;
	}
}

I’m able to return a list via echo and can see my comma separated list in the admin at the top of the page if I use init() temporarily. However, when I attempt to create a page (or any post type) as one of the role types that have a restriction by custom field, the page eventually runs out of memory (currently set to 1G) and we receive several fatal errors:
https://www.dropbox.com/s/wa0x9v892xrf0ua/server-errors.jpg?dl=0

This role has what I believe to be everything needed for this role to create a post type:
create_pages
create_posts
create_tablepress_tables
create_tribe_events

Other roles that we have set up do not have this issue, only this one. Any thoughts or recommendations on what we can try to resolve this issue?