diff --git a/core/includes/common.inc b/core/includes/common.inc
index 1bd8b19..917da41 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -5694,7 +5694,7 @@ function drupal_render_page($page) {
  */
 function drupal_render(&$elements) {
   // Early-return nothing if user does not have access.
-  if (empty($elements) || (isset($elements['#access']) && !$elements['#access'])) {
+  if (!is_array($elements) || (isset($elements['#access']) && !$elements['#access'])) {
     return;
   }
 
@@ -7568,3 +7568,64 @@ function drupal_get_filetransfer_info() {
   }
   return $info;
 }
+
+/**
+ * Pre-render callback: renders specified children as the value of another child.
+ *
+ * This function is meant for render array that uses #theme, allowing
+ * arguments for that theme function to be renderable array.
+ *
+ * You have #map_children, which key is the argument for #theme that you wish
+ * its value to be rendered before hand. #map_children values are children,
+ * you can have more than one child, this will be merge in the call to
+ * drupal_render_children().
+ *
+ * This is an example that produce <a><img></a>:
+ * @code
+ * $markup = array(
+ *   '#pre_render' => array('drupal_pre_render_map_children'),
+ *   '#map_children' => array(
+ *     // $markup['notatext'] is going to be rendered, which result is saved
+ *     // in $markup['#text'], later we pass #text as the argument for theme_link().
+ *     '#text' => array('nottext_markup'),
+ *   ),
+ *   '#theme' => 'link',
+ *   '#path' => 'http://example.com/anchor-target/',
+ *     '#options' => array(
+ *       'attributes' => array(),
+ *       // Tell theme_link() that #text is an html markup.
+ *       'html' => TRUE,
+ *     ),
+ *   // Temporary storage, a renderable array for #text.
+ *   'notatext' => array(
+ *     '#theme' => 'image',
+ *     '#path' => 'http://example.com/image-source.jpg',
+ *   ),
+ * );
+ * @endcode
+ *
+ * As seen in the above example, this function give the flexibility so that
+ * we can nest <img> element (or any other element) inside <a> element, not
+ * as predefined markup, but in the form of renderable array.
+ *
+ * @see drupal_render()
+ *
+ * @param $elements
+ *   A structured array using the #map_children key.
+ *
+ * @return
+ *   The passed-in elements, but has the values of each #map_children rendered,
+ *   and saved as a child named with the key.
+ */
+function drupal_pre_render_map_children($element) {
+  foreach ($element['#map_children'] as $key => $value) {
+    if (is_array($value)) {
+      $element[$key] = drupal_render_children($element, $value);
+    }
+    else {
+      drupal_render_children($element[$value]);
+      $element[$key] = $element[$value];
+    }
+  }
+  return $element;
+}
