-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
137 lines (109 loc) · 3.41 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* Wue Press theme functions
*
* @package WordPress
* @subpackage wue-press
*/
/* This theme only works with the plugin `NodeifyWP` */
if ( !class_exists( '\NodeifyWP\App') && !is_admin() ) {
wp_die('Wue Press requires the NodeifyWP plugin.');
}
/**
* Enable `NodeifyWP`
*/
$server_js_path = __DIR__ . '/dist/server.js';
$client_js_url = get_stylesheet_directory_uri() . '/dist/client.js';
$client_css_url = get_stylesheet_directory_uri() . '/dist/client.css';
$includes_js_path = null;
$includes_js_url = null;
if ( class_exists( '\NodeifyWP\App') ) {
\NodeifyWP\App::setup($server_js_path, $client_js_url, $client_css_url, $includes_js_path, $includes_js_url);
}
/**
* Theme setups
*/
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
// Add title tag to `<head>`
add_theme_support( 'title-tag' );
// Remove canonical link as it is provied by the WP Seo plugin
remove_action('wp_head', 'rel_canonical');
// Use html5 tags
add_theme_support( 'html5' );
// Add menu support
add_theme_support( 'menus' );
// Remove feeds
remove_theme_support( 'automatic-feed-links' );
// Remove post formats
remove_theme_support( 'post-formats' );
// Disable custom background
remove_theme_support( 'custom-background' );
// Disable custom header
remove_theme_support( 'custom-header' );
// Register menus
register_nav_menus( array(
'primary' => 'Primary Menu',
'secondary' => 'Secondary Menu'
));
}
/**
* Recursively include ACF fields in post querys
*/
add_filter( 'the_posts', 'wue_always_include_acf_fields' );
$GLOBALS['wue_always_include_acf_fields_loops'] = 0;
function wue_always_include_acf_fields( $posts ) {
// Disable for admin queries
if ( is_admin() ) {
return $posts;
}
// When $posts is a single post, we wrap it into an array
if ( $posts && !is_array($posts) ) {
$posts = [$posts];
}
for ( $i = 0; $i < count($posts); $i++ ) {
$acf_fields = get_post_custom( $posts[$i]->ID );
$posts[$i]->post_acf = array();
foreach ( $acf_fields as $label => $value ) {
// Skip internal fields
if ($label[0] == '_') {
continue;
}
$field = get_field( $label, $posts[$i]->ID );
// Loop over custom fields recursively 3 levels deep
if ( isset($field->ID) || isset($field[0]->ID) ) {
$GLOBALS['wue_always_include_acf_fields_loops'] += 1;
if ($GLOBALS['wue_always_include_acf_fields_loops'] < 2) {
wue_always_include_acf_fields($field);
}
}
$posts[$i]->post_acf[ $label ] = $field;
}
}
/**
* TODO: ACF creates a new property in the parent for all properties found in the children.
* This new prperties are prefixed by their parent name and an underscore. We should remove them?
*/
return $posts;
}
/**
* Add theme settings page
*
* To use the settings in the client app, you need to manually add
* each settings field to `register_settings` in `wue-plugin/App.php`
*/
add_action( 'init', 'add_afc_options_page' );
function add_afc_options_page() {
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme Settings',
'menu_title' => 'Theme',
'menu_slug' => 'theme-settings',
'parent_slug' => 'options-general.php',
'capability' => 'edit_others_pages',
'icon_url' => 'dashicons-admin-settings',
'redirect' => false,
'post_id' => 'option'
));
}
}