diff --git a/insert_block.info b/insert_block.info
index ca32a0c..cc2c3c8 100644
--- a/insert_block.info
+++ b/insert_block.info
@@ -1,6 +1,3 @@
 name = Insert Block
 description = "Inserts the contents of a block into into a node using [block:module=delta] tags"
 core = 7.x
-
-files[] = insert_block.module
-files[] = insert_block.install
\ No newline at end of file
diff --git a/insert_block.module b/insert_block.module
index 9917a50..642c067 100644
--- a/insert_block.module
+++ b/insert_block.module
@@ -37,31 +37,59 @@ function insert_block_filter_info() {
     'process callback' => '_insert_block',
     'settings callback' => '_insert_block_settings',
     'tips callback' => '_insert_block_tips',
+    'default settings' => array(
+      'check_roles' => 0,
+    ),
     'cache' => FALSE,
   );
   return $filters;
 }
 
 function _insert_block($text, $filter, $format) {
+  global $user;
   if (preg_match_all("/\[block:([^=\\]]+)=?([^\\]]*)?\]/i", $text, $match)) {
+    $block_roles = _insert_block_roles();
     foreach ($match[2] as $key => $value) {
       $raw_tags[] = $match[0][$key];
       $module = $match[1][$key];
       $delta = $match[2][$key];
 
       // see comments on http://api.drupal.org/api/drupal/developer--theme.php/function/theme_block/7
-      $block = block_load($module, $delta);
-      $block_content = _block_render_blocks(array($block));
-      $build = _block_get_renderable_array($block_content);
-      $repl[] = drupal_render($build);
+      $replacement = '';
+      if ($block = block_load($module, $delta)) {
+        $check_roles = !empty($filter->settings['check_roles']);
+        // If a block has no roles associated, it is displayed for every role.
+        // For blocks with roles associated, if none of the user's roles matches
+        // the settings from this block, remove it from the block list.
+        if ($check_roles && isset($block_roles[$block->module][$block->delta]) && !array_intersect($block_roles[$block->module][$block->delta], array_keys($user->roles))) {
+          // No match.
+          $block = NULL;
+        }
+        if ($block) {
+          $block_content = _block_render_blocks(array($block));
+          $build = _block_get_renderable_array($block_content);
+          $replacement = drupal_render($build);
+        }
+      }
+      $repl[] = $replacement;
     }
     return str_replace($raw_tags, $repl, $text);
   }
   return $text;
 }
 
-function _insert_block_settings($format) {
-  
+/**
+ * Settings callback for the insert block filter.
+ */
+function _insert_block_settings($form, &$form_state, $filter, $format, $defaults) {
+  $filter->settings += $defaults;
+  $settings['check_roles'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Check the roles assigned by the Block module'),
+    '#default_value' => $filter->settings['check_roles'],
+    '#description' => t('Without this checked, anyone could see the content of this block.'),
+  );
+  return $settings;
 }
 
 function _insert_block_tips($filter, $format, $long = FALSE) {
@@ -72,4 +100,20 @@ function _insert_block_tips($filter, $format, $long = FALSE) {
     return t('You may use <a href="@insert_block_help">[block:<em>module</em>=<em>delta</em>] tags</a> to display the contents of block <em>delta</em> for module <em>module</em>.',
     array("@insert_block_help" => url("filter/tips/$format->format", array('fragment' => 'filter-insert_block'))));
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Helper function to load and cache the block roles.
+ */
+function _insert_block_roles() {
+  // Build an array of roles for each block.
+  $block_roles = &drupal_static(__FUNCTION__, NULL);
+  if (!isset($block_roles)) {
+    $block_roles = array();
+    $result = db_query('SELECT module, delta, rid FROM {block_role}');
+    foreach ($result as $record) {
+      $block_roles[$record->module][$record->delta][] = $record->rid;
+    }
+  }
+  return $block_roles;
+}
