You are here

function contextphp_reaction_php::execute in Context PHP 7

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

File

plugins/contextphp_reaction_php.inc, line 40
contextphp_reaction_php.inc Adds php reaction to Context

Class

contextphp_reaction_php
PHP code as a Context reaction.

Code

function execute() {
  foreach (context_active_contexts() as $context) {
    $options = $this
      ->fetch_from_context($context, 'options');
    if (!empty($options['phpcode'])) {
      $code = '<?php ' . $options['phpcode'] . ' ?>';
      if (module_exists('php')) {
        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;
      }
    }
  }
}