You are here

function contextphp_condition_php::execute in Context PHP 7

Same name and namespace in other branches
  1. 6 plugins/contextphp_condition_php.inc \contextphp_condition_php::execute()

File

plugins/contextphp_condition_php.inc, line 42
contextphp_condition_php.inc Adds php argument condition to Context

Class

contextphp_condition_php
PHP code as a Context condition.

Code

function execute() {
  foreach (context_enabled_contexts() as $context) {
    $options = $this
      ->fetch_from_context($context, 'options');
    if (!empty($options['phpcode'])) {
      $code = '<?php ' . $options['phpcode'] . ' ?>';
      if (module_exists('php')) {
        $return = php_eval($code);
      }
      else {
        drupal_set_message(t("Please enable 'PHP filter' to allow the 'Context PHP' module to evaluate your code."), 'warning', TRUE);
        return FALSE;
      }
      if ($return == TRUE) {
        $this
          ->condition_met($context, $return);
      }
    }
  }
}