Example #1
0
 /**
  * Initialize WPametu
  */
 private static function init()
 {
     // Avoid double initialization
     if (self::$initialized) {
         trigger_error('Do not call WPametu::init twice!', E_USER_WARNING);
         return;
     }
     // Todo: i18n for plugin
     load_theme_textdomain(self::DOMAIN, dirname(__DIR__) . '/i18n');
     // Check version
     if (version_compare(phpversion(), self::PHP_VERSION, '<')) {
         trigger_error(sprintf(__('PHP version should be %s and over. Your version is %s.', self::DOMAIN), self::PHP_VERSION, phpversion()), E_USER_WARNING);
         return;
     }
     // Fire AutoLoader
     AutoLoader::get_instance();
     self::$initialized = true;
 }
Example #2
0
 /**
  * Register Batch classes
  */
 protected function register_batches()
 {
     static $batch_registered = false;
     if (!$batch_registered) {
         // Register Batches
         /** @var AutoLoader $auto_loader */
         $auto_loader = AutoLoader::get_instance();
         $root = $auto_loader->namespace_root;
         $namespace = $auto_loader->namespace;
         if ($namespace && $root && is_dir($root . '/Batches')) {
             // Scan directory and find batch children
             foreach (scandir($root . '/Batches') as $file) {
                 if (preg_match('/\\.php$/', $file)) {
                     $class_name = $namespace . '\\Batches\\' . str_replace('.php', '', $file);
                     if (class_exists($class_name) && $this->is_sub_class_of($class_name, Batch::class)) {
                         $this->batches[] = $class_name;
                     }
                 }
             }
         }
         $batch_registered = true;
     }
 }