コード例 #1
0
ファイル: Theme.php プロジェクト: austbot/gantry5-composer
 public function __construct($path, $name = '')
 {
     parent::__construct($path, $name);
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     \Timber::$locations = $locator->findResources('gantry-engine://views');
     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_filter('timber_context', [$this, 'add_to_context']);
     add_filter('get_twig', [$this, 'add_to_twig']);
     add_action('template_redirect', [$this, 'set_template_layout'], -10000);
     add_action('init', [$this, 'register_post_types']);
     add_action('init', [$this, 'register_taxonomies']);
     add_action('widgets_init', [$this, 'widgets_init']);
     add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']);
     add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']);
     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']);
 }
コード例 #2
0
ファイル: Theme.php プロジェクト: nmsde/gantry5
 public function __construct($path, $name = '')
 {
     global $pagenow;
     parent::__construct($path, $name);
     $gantry = Gantry::instance();
     $global = $gantry['global'];
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     \Timber::$locations = $locator->findResources('gantry-engine://views');
     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('timber_context', [$this, 'add_to_context']);
     add_filter('get_twig', [$this, 'add_to_twig']);
     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_action('template_redirect', [$this, 'set_template_layout'], -10000);
     add_action('init', [$this, 'register_post_types']);
     add_action('init', [$this, 'register_taxonomies']);
     add_action('template_redirect', [$this, 'disable_wpautop'], 10000);
     add_action('widgets_init', [$this, 'widgets_init']);
     add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']);
     add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']);
     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']);
     add_action('widgets_init', function () {
         register_widget('\\Gantry\\WordPress\\Widget\\Particle');
     });
     // Offline support.
     add_action('init', function () use($global, $pagenow) {
         if ($global->get('offline') && !(is_super_admin() || current_user_can('manage_options') || $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'));
             }
         }
     });
 }
コード例 #3
0
ファイル: Theme.php プロジェクト: rishiv3/gantry5
 /**
  * @see AbstractTheme::init()
  */
 protected function init()
 {
     parent::init();
     $gantry = Gantry::instance();
     $global = $gantry['global'];
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     \Timber::$locations = $locator->findResources('gantry-engine://views');
     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('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']);
     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']);
     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($global) {
         if ($global->get('offline') && !(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'));
             }
         }
     });
     $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;
 }
コード例 #4
0
ファイル: Loader.php プロジェクト: mrgrain/timber
 /**
  *
  * @return array
  */
 public function get_locations_user()
 {
     $locs = array();
     if (isset(Timber::$locations)) {
         if (is_string(Timber::$locations)) {
             Timber::$locations = array(Timber::$locations);
         }
         foreach (Timber::$locations as $tloc) {
             $tloc = realpath($tloc);
             if (is_dir($tloc)) {
                 $locs[] = $tloc;
             }
         }
     }
     return $locs;
 }
コード例 #5
0
 function testTwigLoadsFromLocation()
 {
     Timber::$locations = __DIR__ . '/assets';
     $str = Timber::compile('thumb-test.twig');
     $this->assertEquals('<img src="" />', trim($str));
 }
コード例 #6
0
/**
* @package uw-photo-story
* @version 0.0.14
*/
/*
Plugin Name: UW Photo Story
Version: 0.0.1
Description: Extend Wordpress’s built-in media gallery for embedding carousels and lightboxed photo sets using the Owl 2 and Photoswipe JS libraries.
Author: Nick Weaver
*/
if (!class_exists('Timber')) {
    die("This plugin requires Timber for Wordpress.");
} else {
    // append views dir in this plugin to Timber's view locations
    // if (is_array(Timber::$dirname)) {
    //   $views = Timber::$dirname;
    // } else {
    //   $views = array(Timber::$dirname);
    // }
    // $views[] = plugin_dir_path(__FILE__) . "views";
    // Timber::$dirname = $views;
    error_log("HWWW");
    Timber::$locations = plugin_dir_path(__FILE__) . "views";
    error_log(Timber::$locations);
    error_log(print_r(Timber::$locations, true));
}
if (!class_exists('UwPhotoStory')) {
    require_once dirname(__FILE__) . '/lib/uw_photo_story.class.php';
}
$photo_story = new UwPhotoStory();
コード例 #7
0
ファイル: Block.php プロジェクト: jblpdev/wp-page-builder
 /**
  * Renders a specific template.
  * @method render
  * @since 0.1.0
  */
 public function render($template, $context)
 {
     $this->on_render($template, $context);
     $locations = Timber::$locations;
     Timber::$locations = array_merge($this->get_render_location(), Timber::$locations);
     $context['block_buid'] = $this->infos['buid'];
     $context['block_name'] = $this->infos['name'];
     $context['block_description'] = $this->infos['description'];
     $context['page_id'] = $this->page_id;
     $context['post_id'] = $this->post_id;
     $context['page'] = new TimberPost($this->page_id);
     $context['post'] = new TimberPost($this->post_id);
     Timber::render($template, $context);
     Timber::$locations = $locations;
 }
コード例 #8
0
    global $acf;
    if (is_plugin_active('timber-library/timber.php') === false || version_compare(Timber::$version, '1.0.0', '<')) {
        echo 'Timber-Library version 1.0.0 or higher is required. <br> See https://wordpress.org/plugins/timber-library/';
        exit;
    }
    if (is_plugin_active('advanced-custom-fields-pro/acf.php') === false || version_compare($acf->settings['version'], '5.4.0', '<')) {
        echo 'Advanced Custom Fields version 5.4.0 or higher is required. <br> See https://wordpress.org/plugins/advanced-custom-fields/';
        exit;
    }
});
/**
 * @action init
 * @since 1.0.0
 */
add_action('init', function () {
    Timber::$locations = array(WPB_DIR . 'templates/');
    $ver = get_option('wpb_version', '1.0.0');
    if ($ver === '1.0.0') {
        $ver = migrate_0_1_0_to_1_0_0();
    }
});
/**
 * @action admin_init
 * @since 1.0.0
 */
add_action('admin_init', function () {
    /**
     * Adds a metabox on the block edit page used to store the block id and page
     * it was added to. This metabox is hidden.
     * @since 1.0.0
     */
コード例 #9
0
ファイル: functions.php プロジェクト: sturple/fg-theme-master
        }
        //adding errors
        $config['ERRORS'] = $errors;
        $dirnameChildTheme = get_stylesheet_directory() . '/twig-templates';
        $dirnameTheme = get_template_directory() . '/twig-templates';
        Timber::$dirname = array('twig-templates');
        //setting up timber twig file locations
        // it will look in theme first, if it doesn't find it it will look in master
        $timberLocationsArray = array($dirnameChildTheme, $dirnameChildTheme . '/wp', $dirnameChildTheme . '/partials', $dirnameChildTheme . '/email', $dirnameChildTheme . '/form');
        // only merge if seperate;
        if ($dirnameChildTheme !== $dirnameTheme) {
            $timberLocationsArray = array_merge($timberLocationsArray, array($dirnameTheme, $dirnameTheme . '/wp', $dirnameTheme . '/partials', $dirnameTheme . '/email', $dirnameTheme . '/form'));
        }
        // adding filter to add twig locations
        $timberLocationsArray = apply_filters('fg_theme_master_twig_locations', $timberLocationsArray);
        Timber::$locations = $timberLocationsArray;
        return $config;
    };
});
$get_slideshow = function () {
    if (function_exists('rwmb_meta')) {
        $meta = rwmb_meta('fgms_slideshow_items');
        if (!is_array($meta) || count($meta) === 0) {
            return null;
        }
        $items = array();
        foreach ($meta as $m) {
            $items[] = array('caption' => $m['caption'], 'url' => $m['full_url'], 'alt' => $m['alt'], 'title' => $m['title']);
        }
        $filter = function ($str) {
            return $str === '' ? null : $str;
コード例 #10
0
ファイル: class-maera-timber.php プロジェクト: wpmu/maera
 /**
  * Apply global Timber customizations
  */
 function timber_customizations()
 {
     global $wp_customize;
     $locations = $this->twig_locations();
     Timber::$locations = $locations;
 }
コード例 #11
0
ファイル: functions.php プロジェクト: pipbeard/blank
<?php

if (!class_exists('Timber')) {
    add_action('admin_notices', function () {
        echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url(admin_url('plugins.php#timber')) . '">' . esc_url(admin_url('plugins.php')) . '</a></p></div>';
    });
    return;
}
// Location of template files
Timber::$locations = 'views';
class BlankSite extends TimberSite
{
    function __construct()
    {
        // add_theme_support( 'post-formats' );
        add_theme_support('post-thumbnails');
        add_theme_support('menus');
        add_filter('timber_context', array($this, 'add_to_context'));
        add_action('init', array($this, 'register_post_types'));
        add_action('init', array($this, 'register_menus'));
        parent::__construct();
    }
    function register_post_types()
    {
        // Register custom post types here, like this:
        /*$labels = array(
            'name'               => _x( 'Custom Items', 'post type general name', 'custom' ),
            'singular_name'      => _x( 'Custom Item', 'post type singular name', 'custom' ),
            'menu_name'          => _x( 'Custom Items', 'admin menu', 'custom' ),
            'name_admin_bar'     => _x( 'Custom Item', 'add new on admin bar', 'custom' ),
            'add_new'            => _x( 'Add New', 'custom', 'custom' ),
コード例 #12
0
ファイル: Block.php プロジェクト: jblpdev/wp-page-block
 /**
  * Renders a specific template.
  * @method render
  * @since 1.0.0
  */
 public function render($template, $context)
 {
     $this->on_render($template, $context);
     $locations = Timber::$locations;
     Timber::$locations = array_merge($this->get_render_location(), Timber::$locations);
     $context['block_buid'] = $this->infos['buid'];
     $context['block_name'] = $this->infos['name'];
     $context['block_description'] = $this->infos['description'];
     $context['page_id'] = $this->page_id;
     $context['post_id'] = $this->post_id;
     $context['page'] = new TimberPost($this->page_id);
     $context['post'] = new TimberPost($this->post_id);
     ob_start();
     Timber::render($template, $context);
     $render = ob_get_contents();
     $render = apply_filters('wpb/render', $render, $this);
     ob_end_clean();
     echo $render;
     Timber::$locations = $locations;
 }