diff --git a/entityreference.install b/entityreference.install
index caae34e..4630290 100644
--- a/entityreference.install
+++ b/entityreference.install
@@ -38,7 +38,6 @@ function entityreference_update_7000() {
   }
 
   // Get the list of fields of type 'entityreference'.
-  $fields = array();
   foreach (field_info_fields() as $field_name => $field) {
     // Update the field configuration.
     if ($field['type'] == 'entityreference') {
@@ -73,3 +72,25 @@ function entityreference_update_7000() {
     }
   }
 }
+
+/**
+ * Add default value function to all entity reference field instances.
+ */
+function entityreference_update_7001() {
+    // Get the list of fields of type 'entityreference'.
+  foreach (field_info_fields() as $field_name => $field) {
+    if ($field['type'] != 'entityreference') {
+      continue;
+    }
+
+    // Update the instance configurations.
+    foreach ($field['bundles'] as $entity_type => $bundles) {
+      foreach ($bundles as $bundle) {
+        $instance = field_info_instance($entity_type, $field_name, $bundle);
+        $instance['default_value_function'] = 'entityreference_field_default_value';
+        field_update_instance($instance);
+      }
+    }
+  }
+}
+
diff --git a/entityreference.module b/entityreference.module
index 2327e9b..31f52ea 100644
--- a/entityreference.module
+++ b/entityreference.module
@@ -25,14 +25,13 @@ function entityreference_field_info() {
     'label' => t('Entity Reference'),
     'description' => t('This field reference another entity.'),
     'settings' => array(
-      // Default to the core target entity type node. 
+      // Default to the core target entity type node.
       'target_type' => 'node',
       // The handler for this field.
       'handler' => 'base',
       // The handler settings.
       'handler_settings' => array(),
     ),
-    'instance_settings' => array(),
     'default_widget' => 'entityreference_autocomplete',
     'default_formatter' => 'entityreference_label',
     'property_callbacks' => array('entityreference_field_property_callback'),
@@ -340,6 +339,51 @@ function entityreference_field_widget_settings_form($field, $instance) {
   return $form;
 }
 
+
+/**
+ * Implements hook_field_create_instance().
+ *
+ * Add "default value function" setting to the field instance.
+ * We have to do it from this hook, as we don't have another chance of setting
+ * this option via the hook_field_info().
+ */
+function entityreference_field_create_instance($instance) {
+  $field = field_info_field($instance['field_name']);
+  if ($field['type'] != 'entityreference') {
+    return;
+  }
+  $instance['default_value_function'] = 'entityreference_field_default_value';
+  field_update_instance($instance);
+}
+
+
+/**
+ * Field default value callback.
+ *
+ * Set the default from the URL context. This works even if the widget is
+ * not shown, e.g. due to restricted field access.
+ *
+ * @see entityreference_field_info()
+ */
+function entityreference_field_default_value($entity_type, $entity, $field, $instance, $langcode) {
+  $field_name = $field['field_name'];
+  if (empty($_GET[$field_name])) {
+    return;
+  }
+  $ids = explode(',', $_GET[$field_name]);
+  // Check access to the provided entities.
+  $target_type = $field['settings']['target_type'];
+  entity_load($target_type, $ids);
+  $items = array();
+  foreach ($ids as $id) {
+    $entity = entity_load_single($target_type, $id);
+    if (entity_access('view', $target_type, $entity)) {
+      $items[] = array('target_id' => $id);
+    }
+  }
+  return $items;
+}
+
 /**
  * Implements hook_options_list().
  */
