• The insert_button function in KBJ_UserShortcodesPlus_Admin_TinyMCE_AddShortcodeButton caused a memory_limit issue, if too much users are in the system.

    The get_users() request needs about 512MB in our system for about 13k users.
    Can you please update the function to load the users chunked or limit the users?

    I made the following changes in our system to prevent the memory_limit error:

    public function insert_button($context) {
    	global $pagenow;
    	if(!in_array($pagenow, array('post.php', 'post-new.php'))) {
    		return $context;
    	}
    	add_thickbox();
    	$users = array();
    	$page = 0;
    	do {
    		$page++;
    		$users_chunk = get_users(array('number' => 3000, 'paged' => $page));
    		if(is_array($users_chunk) && count($users_chunk)) {
    			$users = array_merge($users, array_map(function($user) {
    				return json_decode('{"ID":"'.$user->ID.'", "display_name": "'.str_replace('"', '\"', $user->display_name).'"}');
    			}, $users_chunk));
    		}
    	} while(is_array($users_chunk) && count($users_chunk));
    	$data = array(
    		'button_text' => __('Add User Shortcode', ''),
    		'users' => $users,
    		'shortcodes' => KBJ_UserShortcodesPlus::config('Shortcodes'),
    	);
    	return KBJ_UserShortcodesPlus::template('admin-tinymce-modal.html.php', $data);
    }
  • The topic ‘memory_limit issue on 10k+ users’ is closed to new replies.