This repository was archived by the owner on Jan 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·281 lines (242 loc) · 9.53 KB
/
Copy pathfunctions.php
File metadata and controls
executable file
·281 lines (242 loc) · 9.53 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
/**
* Set the content width based on the theme's design and stylesheet.
*/
if (!isset($content_width)) {
$content_width = 1200; /* pixels */
}
if (! function_exists('silencio_setup')) {
function silencio_setup() {
require_once(dirname(__FILE__) . '/res/functions/admin.php');
require(get_template_directory() . '/res/functions/template-tags.php');
require(get_template_directory() . '/res/functions/shortcodes.php');
require(get_template_directory() . '/res/functions/widgets.php');
require(get_template_directory() . '/res/functions/excerpts.php');
require(get_template_directory() . '/res/functions/tinymce.php');
require(get_template_directory() . '/res/functions/users.php');
require(get_template_directory() . '/res/functions/metaboxes.php');
require(get_template_directory() . '/res/functions/jetpack.php');
// require(get_template_directory() . '/res/functions/mime-types.php');
// require(get_template_directory() . '/res/functions/post-types.php');
// require(get_template_directory() . '/res/functions/taxonomies.php');
add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
// add_theme_support('post-formats', array( 'aside', 'image', 'link', 'quote', 'video', 'gallery'));
register_nav_menu('primary', __('Primary Menu', 'silencio'));
register_nav_menu('ancillary', __('Ancillary Menu', 'silencio'));
// register_nav_menu('footer-menu', __('Footer Menu', 'silencio'));
}
}
add_action('after_setup_theme', 'silencio_setup');
// Custom Thumbnail Sizes
if (function_exists('add_image_size')) {
add_image_size('blog-thumb', 200, 160, true); //(cropped)
add_image_size('header-thumb', 1170, 400, true); //(cropped)
}
//Custom Content Image Sizes Attribute
add_filter('wp_calculate_image_sizes', function ($sizes, $size) use ($content_width) {
$width = $size[0];
if (is_null($content_width) || $width < $content_width) {
return $sizes;
}
return '(min-width: ' . $content_width . 'px) ' . $content_width . 'px, 100vw';
}, 10, 2);
//Custom Thumbnail Sizes Attribute
function silencio_post_thumbnail_sizes_attr($attr, $attachment, $size) {
//Calculate Image Sizes by type and breakpoint
//Header Images
if ($size === 'header-thumb') {
$attr['sizes'] = '(max-width: 768px) 92vw, (max-width: 992px) 450px, (max-width: 1200px) 597px, 730px';
//Blog Thumbnails
} elseif ($size === 'blog-thumb') {
$attr['sizes'] = '(max-width: 992px) 200px, (max-width: 1200px) 127px, 160px';
}
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'silencio_post_thumbnail_sizes_attr', 10, 3);
/**
* Enqueue scripts and styles
*/
function silencio_scripts() {
$vendor = 'build/vendor.min.js';
wp_enqueue_script(
'vendor',
get_template_directory_uri() . '/res/' . $vendor,
array('jquery'),
defined('VIA_DEPLOYMENT') ? VIA_DEPLOYMENT : filemtime(get_stylesheet_directory() . '/res/' . $vendor),
true
);
$bundle = 'build/bundle.js';
wp_enqueue_script(
'bundle',
get_template_directory_uri() . '/res/' . $bundle,
array('jquery'),
defined('VIA_DEPLOYMENT') ? VIA_DEPLOYMENT : filemtime(get_stylesheet_directory() . '/res/' . $bundle),
true
);
wp_register_style(
'vendor',
get_template_directory_uri() . '/res/build/vendor.min.css',
array(),
defined('VIA_DEPLOYMENT') ? VIA_DEPLOYMENT : filemtime(get_stylesheet_directory() . '/res/build/vendor.min.css'),
'all'
);
wp_register_style(
'global',
get_template_directory_uri() . '/res/build/global.min.css',
array(),
defined('VIA_DEPLOYMENT') ? VIA_DEPLOYMENT : filemtime(get_stylesheet_directory() . '/res/build/global.min.css'),
'all'
);
// enqueing:
wp_enqueue_style('vendor');
wp_enqueue_style('global');
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'silencio_scripts');
function jr3_enqueue_gutenberg() {
wp_register_style('jr3-gutenberg', get_stylesheet_directory_uri() . '/res/build/editor.min.css');
wp_enqueue_style('jr3-gutenberg');
}
/**
* Add oEmbed support for widgets
*/
add_filter('widget_text', array($wp_embed, 'run_shortcode'), 8);
add_filter('widget_text', array($wp_embed, 'autoembed'), 8);
/**
* Register widgetized area and update sidebar with default widgets
*/
function silencio_widgets_init() {
register_sidebar(array(
'name' => __('Home Sidebar', 'silencio'),
'id' => 'home-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => __('Page Sidebar', 'silencio'),
'id' => 'page-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => __('Post Sidebar', 'silencio'),
'id' => 'post-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => __('Footer Sidebar', 'silencio'),
'id' => 'footer-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
}
add_action('widgets_init', 'silencio_widgets_init');
/*
* Gravityforms Markup Customization:
*/
add_filter('gform_submit_button', function ($button, $form) {
$dom = new DOMDocument();
$dom->loadHTML($button);
$input = $dom->getElementsByTagName('input')->item(0);
$tabindex = $input->getAttribute('tabindex');
return "<button type=\"submit\" tabindex=\"{$tabindex}\" class=\"btn btn-primary\" id=\"gform_submit_button_{$form['id']}\">{$form['button']['text']}</button>";
}, 10, 2);
add_filter('gform_validation_message', function ($message, $form) {
return "<div class=\"alert alert-danger\"><h4>Error</h4><p>" . esc_html__('There was a problem with your submission.', 'gravityforms') . ' ' . esc_html__('Errors have been highlighted below.', 'gravityforms') . '</p></div>';
}, 10, 2);
add_filter('gform_confirmation', function ($confirmation, $form, $entry, $ajax) {
foreach ($form['confirmations'] as $confirm) {
if ($confirm['type'] === 'message') {
$confirmation = "<div class=\"alert alert-success\"><h4>Success</h4>$confirmation</div>";
}
}
return $confirmation;
}, 10, 4);
/**
* Fix Uncaught Reference Error from Gravity Forms - Puts js call in the footer, where it should be.
*/
add_filter("gform_init_scripts_footer", "init_scripts");
function init_scripts() {
return true;
}
/*
* Registering Theme Options:
*/
require_once('res/functions/silencio-theme-settings-basic.php');
/*
* Takes our theme option's location info and produces a maps link appropriate to the user's device.
* @return string URL to appropriate maps service.
*/
function silencio_build_directions_url($street, $city, $state, $zip) {
// Format our address for URLs
$address = str_replace(' ', '+', implode('+', array($street, $city, $state, $zip))); // replaces all spaces w/ +
// Check UA to see if this is an iPhone
$is_iOS = strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone');
// If yes, parse out the version of iOS
if ($is_iOS !== false) {
$results = array();
preg_match('/iPhone OS (\d+)_(\d+)\s+/', $_SERVER['HTTP_USER_AGENT'], $results);
$iOS_version = $results[1] . '.' . $results[2];
}
// Serve up an Apple Maps link if on an iOS 6 device, otherwise serve up a Google Maps link.
if (isset($iOS_version) && $iOS_version >= 6) {
return "https://maps.apple.com/maps?q=" . $address;
} else {
return "https://maps.google.com/maps?q=" . $address;
}
}
/*
* Helper function for debugging variables
*
*/
if (!function_exists('debug')) {
function debug($var) {
$bt = debug_backtrace();
$caller = array_shift($bt);
echo '<p><strong>' . basename($caller['file']) . ' - Line: ' . $caller['line'] . '</strong></p>';
echo '<pre>';
var_dump($var);
echo '</pre>';
}
}
/*
* Helper function for getting post thumbnail url
*
*/
function get_post_thumbnail_url($size) {
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, $size, true);
$thumb_url = $thumb_url_array[0];
return $thumb_url;
}
/**
* Load a template part & pass in variables declared in caller scope. Optionally return as a string.
* @param string $path path to template file, minus .php (eg. `content-page`, `partial/folder/template-name`)
* @param array $args map of variables to load into scope
* @param bool $echo echo or return rendered template
* @return null or rendered template string
*/
function silencio_partial($path, $args = [], $echo = true) {
if (!empty($args)) {
extract($args);
}
if ($echo) {
include(locate_template($path . '.php'));
return;
}
ob_start();
include(locate_template($path . '.php'));
return ob_get_clean();
}