In the course of debugging some breadcrumb logic, I've realized that

drupal_is_front_page()

is unsafe to call in a drush context, because it always returns true. Naively I expected it to return false for cron/drush, or otherwise issue a warning.

To replicate behaviour, observe that the following prints "1":
drush php-eval 'print_r(drupal_is_front_page())'

It seems like I'm not the only one who got bitten by this: https://api.drupal.org/api/drupal/includes!path.inc/function/drupal_is_f...

Comments

dergachev’s picture

Issue summary: View changes
siliconmind’s picture

Status: Active » Closed (works as designed)

Well, this is rather obvious since $_GET['q'] for drush and cron is empty. It's like accessing your site via index.php directly. What you'd expect?

acrosman’s picture

Status: Closed (works as designed) » Active

I agree with evolvingweb: I'd expect it to return false since there is no "current page" during drush or cron. If you're using drupal_is_front_page() within a hook that gets called in one of those contexts Drupal is telling you the front page is being displayed and therefore the code may either waste time or do something wholly inappropriate. Clearly this isn't a huge issue for many people, but it still seems incorrect since it's not like accessing the site via index.php: it's like accessing your site via cron.php or an outside application.

dineshw’s picture

It doesn't work either in hook_page_alter() for frontpages.
For me it works in local not on acquia.

dalin’s picture

The simple workaround would be:

if (drupal_is_front_page() && !drupal_is_cli()) {
  // Do your stuff.
}

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.