How do I verify a block can be shown in the current page? I created a normal block and configured it using the following settings.


   


I don't want to show the block on node/2 and node/3, for example. I want to get the block render, but verify first the block can be shown on the current page.

// 1 is the block ID.
$block = block_load('block', 1);
// I want to verify if the block can be shown on the current page before getting the renderable array.
$renderable_block = _block_get_renderable_array(_block_render_blocks(array($block)));


I can verify $block-&gt;pages contains the path for the current page, but I think there is a proper way to do that. I am sure there is a core function to which I can pass the block object and the current path.  

What core function should I use to verify the block is visible in the current page?
With the help of the answer on this question, Here is a helper function to check block visibility in case someone needs it:

/**
 * Helper function to remove blocks from list who can not show in the current path:
 * based on , pages, user, roles ..
 * @see: block_block_list_alter().
 * @return mixed
 */
function _check_block_list_visibility_on_current_path(&amp;$blocks) {
  global $user;

  // Build an array of roles for each block.
  $block_roles = array();

  $result = db_query('SELECT module, delta, rid FROM {block_role}');

  foreach ($result as $record) {
    $block_roles[$record-&gt;module][$record-&gt;delta][] = $record-&gt;rid;
  }

  foreach ($blocks as $key =&gt; $block) {

    // 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 (isset($block_roles[$block-&gt;module][$block-&gt;delta]) &amp;&amp; !array_intersect($block_roles[$block-&gt;module][$block-&gt;delta], array_keys($user-&gt;roles))) {
      // No match.
      unset($blocks[$key]);
      continue;
    }

    // Use the user's block visibility setting, if necessary.
    if ($block-&gt;custom != BLOCK_CUSTOM_FIXED) {
      if ($user-&gt;uid &amp;&amp; isset($user-&gt;data['block'][$block-&gt;module][$block-&gt;delta])) {
        $enabled = $user-&gt;data['block'][$block-&gt;module][$block-&gt;delta];
      }
      else {
        $enabled = ($block-&gt;custom == BLOCK_CUSTOM_ENABLED);
      }
    }
    else {
      $enabled = TRUE;
    }

    // Limited visibility blocks must list at least one page.
    if ($block-&gt;visibility == BLOCK_VISIBILITY_LISTED &amp;&amp; empty($block-&gt;pages)) {
      $enabled = FALSE;
    }

    if (!$enabled) {
      unset($blocks[$key]);
      continue;
    }

    // Match path if necessary.
    if ($block-&gt;pages) {
      // Convert path to lowercase. This allows comparison of the same path
      // with different case. Ex: /Page, /page, /PAGE.
      $pages = drupal_strtolower($block-&gt;pages);
      if ($block-&gt;visibility &lt; BLOCK_VISIBILITY_PHP) {
        // Convert the Drupal path to lowercase.
        $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
        // Compare the lowercase internal and lowercase path alias (if any).
        $page_match = drupal_match_path($path, $pages);
        if ($path != $_GET['q']) {
          $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
        }
        // When $block-&gt;visibility has a value of 0
        // (BLOCK_VISIBILITY_NOTLISTED), the block is displayed on all pages
        // except those listed in $block-&gt;pages. When set to 1
        // (BLOCK_VISIBILITY_LISTED), it is displayed only on those pages
        // listed in $block-&gt;pages.
        $page_match = !($block-&gt;visibility xor $page_match);
      }
      elseif (module_exists('php')) {
        $page_match = php_eval($block-&gt;pages);
      }
      else {
        $page_match = FALSE;
      }
    }
    else {
      $page_match = TRUE;
    }

    if (!$page_match) {
      unset($blocks[$key]);
    }
  }
}


Thank you No Sssweat for pointing me to right direction.