public function ajax_edit( $params ) {

		global $wp_roles;

		$capabilities = $this->get_capabilities();

		$params->capabilities = (array) pods_var_raw( 'capabilities', $params, array() );

		$params->custom_capabilities = (array) pods_var_raw( 'custom_capabilities', $params, array() );
		$params->custom_capabilities = array_filter( array_unique( $params->custom_capabilities ) );

		if ( ! isset( $params->id ) || empty( $params->id ) || ! isset( $wp_roles->role_objects[ $params->id ] ) ) {
			return pods_error( __( 'Role not found, cannot edit it.', 'pods' ) );
		}

		/**
		 * @var $role WP_Role
		 */
		$role              = $wp_roles->role_objects[ $params->id ];
		$role_name         = $params->id;
		$role_label        = $wp_roles->role_names[ $params->id ];
		$role_capabilities = $role->capabilities;

		$new_capabilities = array();

		foreach ( $params->capabilities as $capability => $x ) {
			if ( empty( $capability ) || true !== (boolean) $x ) {
				continue;
			}

			$new_capabilities[] = esc_attr( $capability );

			if ( ! $role->has_cap( $capability ) ) {
				$role->add_cap( $capability );
			}
		}

		foreach ( $params->custom_capabilities as $x => $capability ) {
			if ( empty( $capability ) ) {
				continue;
			}

			if ( in_array( $capability, $new_capabilities, true ) ) {
				continue;
			}

			$new_capabilities[] = esc_attr( $capability );

			if ( ! $role->has_cap( $capability ) ) {
				$role->add_cap( $capability );
			}
		}

		foreach ( $role_capabilities as $capability => $x ) {
			if ( ! in_array( $capability, $new_capabilities, true ) && false === strpos( $capability, 'level_' ) ) {
				$role->remove_cap( $capability );
			}
		}

		return true;
	}