public function enqueue() { /* * @AgreablePromoPlugin is a Twig namespace which Herbert generates from * values in herbert.config.php. * @see http://twig.sensiolabs.org/doc/api.html#loaders * * Using get_field() which is an ACF function to retrieve theme * specific options affecting the style of the promo. * ACF definitions for Panel are in app/panels.php. */ $ns = Helper::get('agreable_namespace'); $plugin_root = realpath(__DIR__ . '/../..'); $js_string = file_get_contents($plugin_root . '/resources/assets/app.js'); $webpack_port = null; $override_environment = $environment = getenv('WP_ENV'); if ($environment === 'development') { try { $webpack_port = $this->getDevelopmentWebpackPort($plugin_root); } catch (Exception $e) { // If exception the developer hasn't run webpack so may not be // 'developing' this particular plugin, force 'production' $override_environment = 'production'; } } // If we're on staging then make calls to calais staging. if ($environment === 'staging' || $environment === 'development') { if (!getenv('CALAIS_DOMAIN')) { throw new \Exception('CALAIS_DOMAIN missing from .env file'); } $pattern = '/(www\\.)?(calaisapi\\.com)/'; $js_string = preg_replace($pattern, getenv('CALAIS_DOMAIN'), $js_string); } echo view('@AgreablePromoPlugin/files.twig', ['env' => $override_environment, 'common_css_path' => Helper::asset('styles.css'), 'js_string' => $js_string, 'webpack_port' => $webpack_port, 'plugin_settings_property_primary_colour' => get_field($ns . '_plugin_settings_property_primary_colour', 'option'), 'plugin_settings_property_secondary_colour' => get_field($ns . '_plugin_settings_property_secondary_colour', 'option'), 'plugin_settings_property_font_family' => get_field($ns . '_plugin_settings_property_font_family', 'option'), 'plugin_settings_free_text' => get_field($ns . '_plugin_settings_free_text_css', 'option')])->getBody(); }
public function addPaths($paths) { // Get views specified in herbert. $namespaces = Helper::get('views'); foreach ($namespaces as $namespace => $views) { foreach ((array) $views as $view) { // Add to timber $paths array. array_unshift($paths, $view); } } return $paths; }