示例#1
1
 /**
  * @param Plugin $plugin
  */
 public function __construct(Plugin $plugin)
 {
     parent::__construct($plugin);
     $this->pluginBaseDir = dirname($plugin->getFilePath());
     $this->pluginBaseDirRel = preg_replace('/^' . preg_quote(ABSPATH, '/') . '/', '', $this->pluginBaseDir);
     $uploadsData = wp_upload_dir();
     $this->uploadsBaseDir = isset($uploadsData['basedir']) ? $uploadsData['basedir'] . '/' . $plugin->getSlug() : $this->pluginBaseDir . '/uploads';
     $logFileName = Stringy::create($plugin->getName());
     $this->logFilePath = $this->uploadsBaseDir . '/log/' . (string) $logFileName->camelize() . '.log';
     $templatePluginSlugDir = get_template_directory() . '/' . $plugin->getSlug();
     /* @var FcrHooks $hookFactory */
     $hookFactory = $this->plugin->getHookFactory();
     $this->whereTemplatesMayReside = array($templatePluginSlugDir, $this->pluginBaseDir . '/templates');
     $this->whereTemplatesMayResideFilter = $hookFactory->getWhereTemplatesMayResideFilter();
     $this->whereScriptsMayReside = array($templatePluginSlugDir . '/js', $this->pluginBaseDir . '/assets/js');
     $this->whereScriptsMayResideFilter = $hookFactory->getWhereScriptsMayResideFilter();
     $this->whereStylesMayReside = array($templatePluginSlugDir . '/css', $this->pluginBaseDir . '/assets/css');
     $this->whereStylesMayResideFilter = $hookFactory->getWhereStylesMayResideFilter(array());
 }
示例#2
0
 /**
  * @param Plugin $plugin
  */
 protected function __construct(Plugin $plugin)
 {
     parent::__construct($plugin);
     if ($this->optName) {
         $options = get_option($this->optName);
         if ($options) {
             $this->options = $options;
         } else {
             $this->options = $this->defaults;
             $this->save();
         }
         if (!$this->menuSetupHook) {
             $this->menuSetupHook = $plugin->getHookFactory()->action('plugins_loaded', array($this, 'setupMenuPages'));
         }
         $this->menuSetupHook->add();
     }
 }
示例#3
0
 /**
  * @param string $name       Plugin name. {@link WPluginCore003\Plugin\Plugin::$name}
  * @param string $version    Version of the plugin. {@link WPluginCore003\Plugin\Plugin::$version}
  * @param string $filePath   Abs path to plugin file. {@link WPluginCore003\Plugin\Plugin::$filePath}
  * @param string $slug       Plugin slug. Should contain only alpha-numeric chars and underscore. All other chars
  *                           get replaced with ` `(space) and the {@link Stringy::upperCamelize()} is then
  *                           applied. See also {@link WPluginCore003\Plugin\Plugin::$slug}
  * @param string $textDomain Text domain of the plugin for localization support.
  *                           This should be a lowercase alpha-num string with underscores.
  *                           {@link Stringy::underscored()} is applied to this.
  *                           See also {@link WPluginCore003\Plugin\Plugin::$textDomain}
  *
  * @throws Exception If plugin base namespace isn't set or trying to instantiate core Plugin class
  */
 public function __construct($name, $version, $filePath = '', $slug = '', $textDomain = '')
 {
     parent::__construct($this);
     $this->name = $name;
     $this->version = $version;
     $this->factory = new Factory($this);
     $this->hookFactory = $this->factory->fcrHooks();
     $ref = new \ReflectionClass(get_class($this));
     $baseNSStr = $ref->getNamespaceName();
     if ($baseNSStr === __NAMESPACE__) {
         throw new Exception('Can\'t instantiate core Plugin class. You should extend it instead.');
     }
     $baseNSAr = explode('\\', $baseNSStr);
     if (isset($baseNSAr[0])) {
         $this->baseNamespace = $baseNSAr[0];
     } else {
         throw new Exception('Base namespace not found');
     }
     if (!empty($filePath) && !file_exists($filePath) || empty($filePath) && !file_exists($filePath = dirname(dirname(dirname(__FILE__))) . '/plugin.php')) {
         throw new InvalidArgumentException("Plugin file couldn't be located");
     }
     $this->filePath = $filePath;
     $this->baseName = plugin_basename($this->filePath);
     if (empty($slug)) {
         $baseNameAr = explode('/', plugin_basename(substr($filePath, 0, -4)));
         $slug = end($baseNameAr);
     }
     $slug = preg_replace("/[^A-Za-z0-9 _]/", ' ', $slug);
     $this->slug = $slug = (string) Stringy::create($slug)->upperCamelize();
     $GLOBALS[$slug] =& $this;
     $this->textDomain = empty($textDomain) ? $this->slug : $textDomain;
     $this->textDomain = preg_replace("/[^A-Za-z0-9 _]/", ' ', $this->textDomain);
     $this->textDomain = (string) Stringy::create($this->textDomain)->underscored();
     $this->options = $this->factory->fcrOptions()->options();
     $this->factory->fcrPlugin()->initializer()->coreInit();
 }