%PDF- %PDF-
Direktori : /var/www/camaservice.eco-n-tech.co.uk/wp-content/themes/camaservice/ |
Current File : /var/www/camaservice.eco-n-tech.co.uk/wp-content/themes/camaservice/functions.php |
<?php /** * Timber starter-theme * https://github.com/timber/starter-theme * * @package WordPress * @subpackage Timber * @since Timber 0.1 */ /** * If you are installing Timber as a Composer dependency in your theme, you'll need this block * to load your dependencies and initialize Timber. If you are using Timber via the WordPress.org * plug-in, you can safely delete this block. */ $composer_autoload = __DIR__ . '/vendor/autoload.php'; if (file_exists($composer_autoload)) { require_once $composer_autoload; $timber = new Timber\Timber(); } /** * This ensures that Timber is loaded and available as a PHP class. * If not, it gives an error message to help direct developers on where to activate */ 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>'; } ); add_filter( 'template_include', function ($template) { return get_stylesheet_directory() . '/static/no-timber.html'; } ); return; } /** * Sets the directories (inside your theme) to find .twig files */ Timber::$dirname = array('templates', 'views'); /** * By default, Timber does NOT autoescape values. Want to enable Twig's autoescape? * No prob! Just set this value to true */ Timber::$autoescape = false; /** * We're going to configure our theme inside of a subclass of Timber\Site * You can move this to its own file and include here via php's include("MySite.php") */ class StarterSite extends Timber\Site { /** Add timber support. */ public function __construct() { add_action('after_setup_theme', array($this, 'theme_supports')); add_filter('timber/context', array($this, 'add_to_context')); add_filter('timber/twig', array($this, 'add_to_twig')); add_action('init', array($this, 'register_post_types')); add_action('init', array($this, 'register_taxonomies')); add_action( 'acf/init', array($this, 'register_gutenberg_blocks') ); add_action('wp_enqueue_scripts', array($this, 'loadScripts')); parent::__construct(); } /** This is where you can register custom post types. */ public function register_post_types() { } /** This is where you can register custom taxonomies. */ public function register_taxonomies() { } public function register_gutenberg_blocks() { if ( ! function_exists( 'acf_register_block' ) ) { return; } require_once('blocks/accordion/accordion.php'); require_once('blocks/image-and-text/image-and-text.php'); } public function loadScripts() { // load fonts // wp_enqueue_style('materialIcons', 'https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Round', array()); wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css2?family=Lato:wght@400;700&family=Raleway:wght@500;700&display=swap', array()); wp_enqueue_style('main-style', get_template_directory_uri() . '/dist/css/main.min.css', array(), $this->get_modified_file('/dist/css/main.min.css')); wp_enqueue_script('jquery'); wp_enqueue_script('main-app', get_template_directory_uri() . '/dist/js/main.min.js', array(), $this->get_modified_file('/dist/js/main.min.js'), true); wp_localize_script('main-app', 'theme', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'page_id' => get_queried_object_id(), 'is_singular' => is_singular(), 'is_user_logged_in' => is_user_logged_in(), )); } /** This is where you add some context * * @param string $context context['this'] Being the Twig's {{ this }}. */ public function add_to_context($context) { $context['options'] = get_fields('options'); $context['foo'] = 'bar'; $context['stuff'] = 'I am a value set in your functions.php file'; $context['notes'] = 'These values are available everytime you call Timber::context();'; //Navigation $context['main_nav'] = new Timber\Menu('main_nav'); $context['second_left_nav'] = new Timber\Menu('second_left_nav'); $context['second_right_nav'] = new Timber\Menu('second_right_nav'); $context['footer_col_1'] = new Timber\Menu('footer_col_1'); $context['footer_col_2'] = new Timber\Menu('footer_col_2'); $context['footer_col_3'] = new Timber\Menu('footer_col_3'); $context['footer_col_4'] = new Timber\Menu('footer_col_4'); $context['site'] = $this; return $context; } public function theme_supports() { // Add default posts and comments RSS feed links to head. add_theme_support('automatic-feed-links'); /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded <title> tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support('title-tag'); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support('post-thumbnails'); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'gallery', 'caption', ) ); /* * Enable support for Post Formats. * * See: https://codex.wordpress.org/Post_Formats */ add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'audio', ) ); register_nav_menus(array( 'main_nav' => 'The Main Menu', // main nav in header 'second_left_nav' => 'Flyttfirma Menu', // flyttfirma nav in header 'second_right_nav' => 'Städfirma Menu', // städfirma nav in header // Footer menu 'footer_col_1' => 'Footer col 1', 'footer_col_2' => 'Footer col 2', 'footer_col_3' => 'Footer col 3', 'footer_col_4' => 'Footer col 4', )); add_theme_support('menus'); if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( 'page_title' => 'Theme settings', 'icon_url' => 'dashicons-admin-settings' )); } add_theme_support('align-wide'); } /** This Would return 'foo bar!'. * * @param string $text being 'foo', then returned 'foo bar!'. */ public function myfoo($text) { $text .= ' bar!'; return $text; } /** This is where you can add your own functions to twig. * * @param string $twig get extension. */ public function add_to_twig($twig) { $twig->addExtension(new Twig\Extension\StringLoaderExtension()); $twig->addFilter(new Twig\TwigFilter('myfoo', array($this, 'myfoo'))); return $twig; } } new StarterSite();