use_template_global_vars() static public method

Setting WPLIB_TEMPLATE_GLOBAL_VARS to false will cause WPLib to extract $GLOBALS before loading the WP template which normally happens in wp-include/template-loader.php but WPLib hijacks that.
static public use_template_global_vars ( ) : boolean
return boolean
Ejemplo n.º 1
0
 /**
  * Hijack `template_include` so that we can ensure a $theme variable is defined.
  *
  * @param string $template;
  *
  * @return static
  */
 static function _template_include_999($template)
 {
     if (!$template) {
         $message = __('<p>No template file found. You may have deleted the current theme or renamed the theme directory?</p>' . '<p>If you are a site admin <a href="%s">click here</a> to verify and possibly correct.</p>', 'wplib');
         echo sprintf($message, esc_url(site_url('/wp-admin/themes.php')));
     } else {
         global $theme;
         /*
          * Make $theme available inside the template.
          */
         $theme = WPLib::theme();
         if (WPLib::use_template_global_vars()) {
             /**
              * For compatibility with WordPress templates we need to
              * extract all the global variables into the current scope.
              */
             extract($GLOBALS, EXTR_SKIP);
         }
         include $template;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Hijack `template_include` so that we can ensure a $theme variable is defined.
  *
  * @param string $template;
  *
  * @return static
  */
 static function _template_include_999($template)
 {
     if (!$template && !WPLib::is_production()) {
         $message = __('<p>No template file found. You may have deleted the current theme or renamed the theme directory?</p>' . '<p>If you are a site admin <a href="%s">click here</a> to verify and possibly correct.</p>', 'wplib');
         /*
          * This use of wp-admin theme URL is only presented to help the user
          * when the site is misconfigured. However, ironically, some code
          * sniffers constantly flag it so it is easier to obscure it from
          * the sniffer than to have to constantly see it flagged.
          */
         $admin_path = 'wp-admin';
         echo sprintf($message, esc_url(site_url("/{$admin_path}/themes.php")));
     } else {
         global $theme;
         /*
          * Make $theme available inside the template.
          */
         $theme = WPLib::theme();
         if (WPLib::use_template_global_vars()) {
             /*
              * For compatibility with WordPress templates we need to
              * extract all the global variables into the current scope just
              * like WordPress does when it calls a template. Ironically
              * some code sniffers constantly flag extract() so it is easier to
              * hide it than to have to constantly see it flagged.
              *
              * OTOH if you are using WPLib and you think we should do a direct call
              * to extract() here please add an issue so we can discuss the pros and
              * cons at https://github.com/wplib/wplib/issues
              */
             $function = 'extract';
             $function($GLOBALS, EXTR_SKIP);
         }
         include $template;
     }
     return false;
 }