functions.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * Timber starter-theme
  4. * https://github.com/timber/starter-theme
  5. *
  6. * @package WordPress
  7. * @subpackage Timber
  8. * @since Timber 0.1
  9. */
  10. /**
  11. * If you are installing Timber as a Composer dependency in your theme, you'll need this block
  12. * to load your dependencies and initialize Timber. If you are using Timber via the WordPress.org
  13. * plug-in, you can safely delete this block.
  14. */
  15. $composer_autoload = __DIR__ . '/vendor/autoload.php';
  16. if ( file_exists( $composer_autoload ) ) {
  17. require_once $composer_autoload;
  18. $timber = new Timber\Timber();
  19. }
  20. if( function_exists('acf_add_options_page') ) {
  21. acf_add_options_page(array(
  22. 'page_title' => 'Information',
  23. 'menu_title' => 'Information',
  24. 'menu_slug' => 'information',
  25. 'capability' => 'edit_posts',
  26. 'redirect' => false
  27. ));
  28. acf_add_options_sub_page(array(
  29. 'page_title' => 'Partenaires',
  30. 'menu_title' => 'Partenaires',
  31. 'parent_slug' => 'information',
  32. ));
  33. }
  34. add_filter( 'timber_context', 'options_footer' );
  35. function options_footer( $context ) {
  36. $context['options'] = get_fields('option');
  37. return $context;
  38. }
  39. /**
  40. * This ensures that Timber is loaded and available as a PHP class.
  41. * If not, it gives an error message to help direct developers on where to activate
  42. */
  43. if ( ! class_exists( 'Timber' ) ) {
  44. add_action(
  45. 'admin_notices',
  46. function() {
  47. 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>';
  48. }
  49. );
  50. add_filter(
  51. 'template_include',
  52. function( $template ) {
  53. return get_stylesheet_directory() . '/static/no-timber.html';
  54. }
  55. );
  56. return;
  57. }
  58. /**
  59. * Sets the directories (inside your theme) to find .twig files
  60. */
  61. Timber::$dirname = array( 'templates', 'views' );
  62. /**
  63. * By default, Timber does NOT autoescape values. Want to enable Twig's autoescape?
  64. * No prob! Just set this value to true
  65. */
  66. Timber::$autoescape = false;
  67. // REMOVE EDITOR
  68. function remove_editor() {
  69. remove_post_type_support(
  70. 'page', 'editor'
  71. );
  72. remove_post_type_support(
  73. 'post', 'editor'
  74. );
  75. };
  76. add_action('admin_init', 'remove_editor');
  77. /**
  78. * We're going to configure our theme inside of a subclass of Timber\Site
  79. * You can move this to its own file and include here via php's include("MySite.php")
  80. */
  81. class StarterSite extends Timber\Site {
  82. /** Add timber support. */
  83. public function __construct() {
  84. add_action( 'after_setup_theme', array( $this, 'theme_supports' ) );
  85. add_filter( 'timber/context', array( $this, 'add_to_context' ) );
  86. add_filter( 'timber/twig', array( $this, 'add_to_twig' ) );
  87. add_action( 'init', array( $this, 'register_post_types' ) );
  88. add_action( 'init', array( $this, 'register_taxonomies' ) );
  89. parent::__construct();
  90. }
  91. /** This is where you can register custom post types. */
  92. public function register_post_types() {
  93. }
  94. /** This is where you can register custom taxonomies. */
  95. public function register_taxonomies() {
  96. }
  97. /** This is where you add some context
  98. *
  99. * @param string $context context['this'] Being the Twig's {{ this }}.
  100. */
  101. public function add_to_context( $context ) {
  102. $context['foo'] = 'bar';
  103. $context['stuff'] = 'I am a value set in your functions.php file';
  104. $context['notes'] = 'These values are available everytime you call Timber::context();';
  105. $context['menu'] = new Timber\Menu();
  106. $context['site'] = $this;
  107. return $context;
  108. }
  109. public function theme_supports() {
  110. // Add default posts and comments RSS feed links to head.
  111. add_theme_support( 'automatic-feed-links' );
  112. /*
  113. * Let WordPress manage the document title.
  114. * By adding theme support, we declare that this theme does not use a
  115. * hard-coded <title> tag in the document head, and expect WordPress to
  116. * provide it for us.
  117. */
  118. add_theme_support( 'title-tag' );
  119. /*
  120. * Enable support for Post Thumbnails on posts and pages.
  121. *
  122. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  123. */
  124. add_theme_support( 'post-thumbnails' );
  125. /*
  126. * Switch default core markup for search form, comment form, and comments
  127. * to output valid HTML5.
  128. */
  129. add_theme_support(
  130. 'html5',
  131. array(
  132. 'comment-form',
  133. 'comment-list',
  134. 'gallery',
  135. 'caption',
  136. )
  137. );
  138. /*
  139. * Enable support for Post Formats.
  140. *
  141. * See: https://codex.wordpress.org/Post_Formats
  142. */
  143. add_theme_support(
  144. 'post-formats',
  145. array(
  146. 'aside',
  147. 'image',
  148. 'video',
  149. 'quote',
  150. 'link',
  151. 'gallery',
  152. 'audio',
  153. )
  154. );
  155. add_theme_support( 'menus' );
  156. }
  157. /** This Would return 'foo bar!'.
  158. *
  159. * @param string $text being 'foo', then returned 'foo bar!'.
  160. */
  161. public function myfoo( $text ) {
  162. $text .= ' bar!';
  163. return $text;
  164. }
  165. /** This is where you can add your own functions to twig.
  166. *
  167. * @param string $twig get extension.
  168. */
  169. public function add_to_twig( $twig ) {
  170. $twig->addExtension( new Twig\Extension\StringLoaderExtension() );
  171. $twig->addFilter( new Twig\TwigFilter( 'myfoo', array( $this, 'myfoo' ) ) );
  172. return $twig;
  173. }
  174. }
  175. new StarterSite();