/** * Add an asset to the application. * * NOTE : By default the path is relative to one of the registered * paths. Make sure your asset is unique by handle and paths/url. * You can also pass an external url. * * @param string $handle The asset handle name. * @param string $path The URI to the asset or the absolute URL. * @param array|bool $deps An array with asset dependencies or false. * @param string $version The version of your asset. * @param bool|string $mixed Boolean if javascript file | String if stylesheet file. * @param string $type 'script' or 'style'. * * @return Asset|\WP_Error * * @throws AssetException */ public function add($handle, $path, $deps = [], $version = '1.0', $mixed = null, $type = '') { if (!is_string($handle) && !is_string($path)) { throw new AssetException('Invalid parameters for [Asset::add] method.'); } // Init type. $t = ''; // Get full URL for the asset. $path = $this->finder->find($path); // Group arguments. $args = compact('handle', 'path', 'deps', 'version', 'mixed'); // Get file extension. $ext = pathinfo($path, PATHINFO_EXTENSION); // Define the asset type. if (!empty($type) && in_array($type, $this->allowedAssets)) { $t = $type; } elseif ($ext) { $t = $ext === 'css' ? 'style' : 'script'; } /* * Check the asset type is defined. */ if (empty($t)) { return new \WP_Error('asset', sprintf('%s: %s. %s', __("Can't load your asset", THEMOSIS_FRAMEWORK_TEXTDOMAIN), $handle, __('If your asset has no file extension, please provide the type parameter.', THEMOSIS_FRAMEWORK_TEXTDOMAIN))); } // Register the asset into the service container // and return it for chaining. // Assets are shared, so only one instance of each is available // into the container. // Assets are registered using the 'asset' prefix followed // by their unique asset handle: 'asset.unique-handle' $asset = new Asset($t, $args, $this->container['action'], $this->container['html'], $this->container['filter']); $this->container->instance($this->aliasPrefix . '.' . $handle, $asset); return $asset; }
/** * Bootstrap the core plugin. */ protected function bootstrap() { /* * Define core framework paths. * These are real paths, not URLs to the framework files. */ $paths['core'] = __DIR__ . DS; $paths['sys'] = __DIR__ . DS . 'src' . DS . 'Themosis' . DS; $paths['storage'] = THEMOSIS_STORAGE; themosis_set_paths($paths); /* * Instantiate the service container for the project. */ $this->container = new \Themosis\Foundation\Application(); /* * Create a new Request instance and register it. * By providing an instance, the instance is shared. */ $request = \Themosis\Foundation\Request::capture(); $this->container->instance('request', $request); /* * Setup the facade. */ \Themosis\Facades\Facade::setFacadeApplication($this->container); /* * Register into the container, the registered paths. * Normally at this stage, plugins should have * their paths registered into the $GLOBALS array. */ $this->container->registerAllPaths(themosis_path()); /* * Register core service providers. */ $this->registerProviders(); /* * Setup core. */ $this->setup(); /* * Project hooks. * Added in their called order. */ add_action('admin_enqueue_scripts', [$this, 'adminEnqueueScripts']); add_action('admin_head', [$this, 'adminHead']); add_action('template_redirect', 'redirect_canonical'); add_action('template_redirect', 'wp_redirect_admin_locations'); add_action('template_redirect', [$this, 'setRouter'], 20); }
/** * Set the custom taxonomy. A user can also override the * arguments by passing an array of taxonomy arguments. * * @link http://codex.wordpress.org/Function_Reference/register_taxonomy * * @param array $params Taxonomy arguments to override defaults. * * @return \Themosis\Taxonomy\TaxonomyBuilder */ public function set(array $params = []) { // Override custom taxonomy arguments if given. $this->datas['args'] = array_replace_recursive($this->datas['args'], $params); // Trigger the 'init' event in order to register the custom taxonomy. // Check if we are not already called by a method attached to the `init` hook. $current = current_filter(); if ('init' === $current) { // If inside an `init` action, simply call the register method. $this->register(); } else { // Out of an `init` action, call the hook. $this->action->add('init', [$this, 'register']); } // Register each custom taxonomy instance into the container. $this->container->instance($this->prefix . '.' . $this->datas['name'], $this); return $this; }