/
ThemeExtension.php
88 lines (80 loc) · 2.04 KB
/
ThemeExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/*
* This file is part of the Ekino Wordpress package.
*
* (c) 2013 Ekino
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Ekino\WordpressBundle\Twig\Extension;
/**
* Class ThemeExtension.
*
* This extension provides native Wordpress theme integration into Symfony.
*
* @author Vincent Composieux <vincent.composieux@gmail.com>
*/
class ThemeExtension extends \Twig_Extension
{
/**
* Returns the name of the extension.
*
* @return string
*/
public function getName()
{
return 'ekino_wordpress_theme';
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction('wp_get_header', [$this, 'getHeader'], ['is_safe' => ['html']]),
new \Twig_SimpleFunction('wp_get_sidebar', [$this, 'getSidebar'], ['is_safe' => ['html']]),
new \Twig_SimpleFunction('wp_get_footer', [$this, 'getFooter'], ['is_safe' => ['html']]),
new \Twig_SimpleFunction('wp_get_template_part', [$this, 'getTemplatePart'], ['is_safe' => ['html']]),
];
}
/**
* Displays Wordpress theme header (and administration menu bar if available).
*
* @param string|null $name
*/
public function getHeader($name = null)
{
\get_header($name);
\_wp_admin_bar_init();
\wp_admin_bar_render();
}
/**
* Displays Wordpress theme sidebar.
*
* @param string|null $name
*/
public function getSidebar($name = null)
{
\get_sidebar($name);
}
/**
* Displays Wordpress theme footer.
*
* @param string|null $name
*/
public function getFooter($name = null)
{
\get_footer($name);
}
/**
* Displays a Wordpress theme template part.
*
* @param string $slug
* @param string|null $name
*/
public function getTemplatePart($slug, $name = null)
{
\get_template_part($slug, $name);
}
}