示例#1
0
 /**
  * @see AbstractTheme::init()
  */
 protected function init()
 {
     parent::init();
     $gantry = Gantry::instance();
     $global = $gantry['global'];
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     // Set lookup locations for Timber.
     \Timber::$locations = $locator->findResources('gantry-engine://views');
     // Enable caching in Timber.
     \Timber::$twig_cache = true;
     \Timber::$cache = false;
     // Set autoescape in Timber.
     \Timber::$autoescape = false;
     add_theme_support('html5', ['comment-list', 'comment-form', 'search-form', 'gallery', 'caption', 'widgets']);
     add_theme_support('title-tag');
     add_theme_support('post-formats');
     add_theme_support('post-thumbnails');
     add_theme_support('menus');
     add_theme_support('widgets');
     add_theme_support('woocommerce');
     add_filter('script_loader_tag', ['Gantry\\Framework\\Document', 'script_add_attributes'], 10, 2);
     add_filter('timber_context', [$this, 'getContext']);
     add_filter('timber/loader/twig', [$this, 'timber_loader_twig']);
     add_filter('timber/cache/location', [$this, 'timber_cache_location']);
     add_filter('get_twig', [$this, 'extendTwig'], 100);
     add_filter('the_content', [$this, 'url_filter'], 0);
     add_filter('the_excerpt', [$this, 'url_filter'], 0);
     add_filter('widget_text', [$this, 'url_filter'], 0);
     add_filter('widget_content', [$this, 'url_filter'], 0);
     add_filter('widget_text', 'do_shortcode');
     add_filter('widget_content', 'do_shortcode');
     add_filter('widget_update_callback', ['\\Gantry\\WordPress\\Widgets', 'widgetCustomClassesUpdate'], 10, 4);
     add_filter('dynamic_sidebar_params', ['\\Gantry\\WordPress\\Widgets', 'widgetCustomClassesSidebarParams'], 9);
     add_action('template_redirect', [$this, 'set_template_layout'], -10000);
     add_action('init', [$this, 'register_post_types']);
     add_action('init', [$this, 'register_taxonomies']);
     add_action('init', [$this, 'register_menus']);
     add_action('template_redirect', [$this, 'disable_wpautop'], 10000);
     add_action('widgets_init', [$this, 'widgets_init']);
     add_action('wp_enqueue_scripts', [$this, 'prepare_particles'], 15);
     add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts'], 20);
     add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts'], 20);
     add_action('wp_head', [$this, 'print_styles'], 20);
     add_action('wp_head', [$this, 'print_scripts'], 30);
     add_action('admin_print_styles', [$this, 'print_styles'], 200);
     add_action('admin_print_scripts', [$this, 'print_scripts'], 200);
     add_action('wp_footer', [$this, 'print_inline_scripts'], 100);
     add_action('in_widget_form', ['\\Gantry\\WordPress\\Widgets', 'widgetCustomClassesForm'], 10, 3);
     add_action('widgets_init', function () {
         register_widget('\\Gantry\\WordPress\\Widget\\Particle');
     });
     add_shortcode('loadposition', [$this, 'loadposition_shortcode']);
     // Offline support.
     add_action('init', function () use($gantry, $global) {
         if ($global->get('offline')) {
             if (!(is_super_admin() || current_user_can('manage_options') || $_GLOBALS['pagenow'] == 'wp-login.php')) {
                 if (locate_template(['offline.php'])) {
                     add_filter('template_include', function () {
                         return locate_template(['offline.php']);
                     });
                 } else {
                     wp_die($global->get('offline_message'), get_bloginfo('title'));
                 }
             } else {
                 $gantry['messages']->add(__('Site is currently in offline mode.', 'gantry5'), 'warning');
             }
         }
     });
     $this->preset_styles_init();
     // Load theme text domains
     $domain = $this->details()->get('configuration.theme.textdomain', $this->name);
     load_theme_textdomain($domain, $this->path . '/languages');
     $this->url = $gantry['site']->theme->link;
 }