-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·117 lines (90 loc) · 3.1 KB
/
functions.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
use Qaribou\Collection\ImmArray;
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;
}
Timber::$dirname = array('templates', 'components', 'modules');
require('php/_php.php');
class GardenHui extends TimberSite {
function __construct() {
$controller = new GardenHui_Controller();
add_theme_support( 'post-formats' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_action( 'after_setup_theme', array($controller, 'thumbnails') );
add_filter( 'timber_context', array( $this, 'add_to_context' ) );
add_action( 'init', array( $controller, 'register_post_types' ) );
add_action( 'init', array( $controller, 'register_taxonomies' ) );
add_filter( 'get_twig', array( $this, 'add_to_twig' ) );
add_filter( 'login_redirect', array( $this, 'gardenhui_auth_signon'), 10, 3);
add_filter( 'show_admin_bar', '__return_false' );
add_filter('acf/fields/google_map/api', [$this, 'google_map']);
if(function_exists('acf_add_options_page')) {
acf_add_options_page();
}
parent::__construct();
}
function google_map($api) {
return array_merge($api, [ 'key' => get_field('gmap_api_key', 'options') ]);
}
function add_to_context( $context ) {
/**
* components {array} an associative array of components and their template
* files to be used when including elements
*
* usage: {% include components.header ... %}
*/
$context['components'] = array_reduce(
// glob of all component directories
glob(dirname(__FILE__) . '/components/*'),
function($components, $path) {
// get component directory name
$name = explode("/", $path); $name = end($name);
// merge with initial array
return array_merge($components, array($name => "{$name}/{$name}.twig"));
},
// start with empty array
array()
);
$context['menu'] = new TimberMenu();
$current_user = wp_get_current_user();
$context['current_user'] = $current_user;
$context['is_logged_in'] = $current_user->exists();
$context['site'] = $this;
return $context;
}
function add_to_twig( $twig ) {
/* this is where you can add your own fuctions to twig */
$twig->addTokenParser(new Render_TokenParser() );
$twig->addFilter(
new Twig_SimpleFilter('parse_display_name',function($display_name) {
return preg_replace('/\./', ' ', $display_name);
})
);
$twig->addFunction(
new Twig_SimpleFunction('edit_profile', function($user_id) {
$form = new acf_form_user();
$form->render($user_id, 'edit');
})
);
$twig->addFunction(
new Twig_SimpleFunction('register_form', function() {
$test = new acf_form_user();
$test->user_new_form();
})
);
return $twig;
}
function gardenhui_auth_signon( $redirect_to, $request, $user) {
if(!is_wp_error($user)) {
if(!in_array('administrator', $user->roles)) {
return '/profile';
}
}
return $redirect_to;
}
}
new GardenHui();