-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
153 lines (134 loc) · 5.19 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
require_once('functions/base.php'); # Base theme functions
require_once('custom-taxonomies.php'); # Where per theme taxonomies are defined
require_once('custom-post-types.php'); # Where per theme post types are defined
require_once('functions/admin.php'); # Admin/login functions
require_once('functions/config.php'); # Where per theme settings are registered
require_once('shortcodes.php'); # Per theme shortcodes
//Add theme-specific functions here.
/**
* Returns a theme option value or NULL if it doesn't exist
**/
function get_theme_option($key) {
global $theme_options;
return isset($theme_options[$key]) ? $theme_options[$key] : NULL;
}
/**
* Disable the standard wysiwyg editor for this theme to prevent markup from being blown away by
* WYSIWYG users.
**/
function disable_wysiwyg($c) {
global $post_type;
if ('page' == $post_type && get_theme_option('enable_page_wysiwyg') == 1) {
return false;
}
return $c;
}
add_filter('user_can_richedit', 'disable_wysiwyg');
/**
* Returns the url of the parallax feature's/page's featured image by the
* size specified.
*
* @param int $feature_id - post ID of the parallax feature or page with featured image
* @param string $size - image size registered with Wordpress to fetch the image by
* @param string $cpt_field - name (including prefix) of the meta field for the potential overridden image
* @return string
**/
function get_parallax_feature_img($post_id, $size, $cpt_field) {
$featured_img_id = get_post_thumbnail_id($post_id);
$thumb = null;
$generated_thumb = wp_get_attachment_image_src($featured_img_id, $size);
$custom_thumb = wp_get_attachment_url(get_post_meta($post_id, $cpt_field, true));
$thumb = $custom_thumb ? $custom_thumb : $generated_thumb[0];
return preg_replace('/^http(s)?\:/', '', $thumb);
}
/**
* Output CSS necessary for responsive parallax features.
*
* @param int $post_id - post ID of the parallax feature or page
* @param string $d_cpt_field - name (including prefix) of the meta field for the potential overridden image for desktop browsers
* @param string $t_cpt_field - name (including prefix) of the meta field for the potential overridden image for tablet browsers
* @param string $m_cpt_field - name (including prefix) of the meta field for the potential overridden image for mobile browsers
**/
function get_parallax_feature_css($post_id, $d_cpt_field, $t_cpt_field, $m_cpt_field) {
$featured_img_id = get_post_thumbnail_id($post_id);
$featured_img_f = wp_get_attachment_image_src($featured_img_id, 'parallax_feature-full');
$featured_img_d = get_parallax_feature_img($post_id, 'parallax_feature-desktop', $d_cpt_field);
$featured_img_t = get_parallax_feature_img($post_id, 'parallax_feature-tablet', $t_cpt_field);
$featured_img_m = get_parallax_feature_img($post_id, 'parallax_feature-mobile', $m_cpt_field);
if ($featured_img_f) { $featured_img_f = preg_replace('/^http(s)?\:/', '', $featured_img_f[0]); }
ob_start();
?>
<style type="text/css">
<?php if ($featured_img_f) { ?>
@media all and (min-width: 1200px) { #photo_<?=$post_id?> { background-image: url('<?=$featured_img_f?>'); } }
<?php } ?>
<?php if ($featured_img_d) { ?>
@media all and (max-width: 1199px) and (min-width: 768px) { #photo_<?=$post_id?> { background-image: url('<?=$featured_img_d?>'); } }
<?php } ?>
<?php if ($featured_img_t) { ?>
@media all and (max-width: 767px) and (min-width: 481px) { #photo_<?=$post_id?> { background-image: url('<?=$featured_img_t?>'); } }
<?php } ?>
<?php if ($featured_img_m) { ?>
@media all and (max-width: 480px) { #photo_<?=$post_id?> { background-image: url('<?=$featured_img_m?>'); } }
<?php } ?>
</style>
<!--[if lt IE 9]>
<style type="text/css">
#photo_<?=$post_id?> { background-image: url('<?=$featured_img_d?>'); }
</style>
<![endif]-->
<?php
return ob_get_clean();
}
/**
* Display a subpage parallax header image.
**/
function get_parallax_page_header($page_id) {
$page = get_post($page_id);
ob_start();
print get_parallax_feature_css($page_id, 'page_image_d', 'page_image_t', 'page_image_m');
?>
<section class="parallax-content parallax-header">
<div class="parallax-photo" id="photo_<?=$page_id?>" data-stellar-background-ratio="0.5">
<div class="container parallax-header-inner">
<div class="row parallax-header-inner">
<div class="span12 parallax-header-inner">
<h1><?=$page->post_title?></h1>
<?php if ( $cta = get_cta_link() ) : ?>
<div class="cta">
<?php print $cta; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
<?php
return ob_get_clean();
}
/**
* Displays a call to action link, using the page link provided in Theme Options.
**/
function get_cta_link() {
$cta = get_theme_option('cta');
$cta_post = $cta ? get_post( $cta ) : null;
$link = ( $cta_post instanceof WP_Post ) ? get_permalink( $cta_post ) : null;
ob_start();
if ( $link ):
?>
<a href="<?=$link?>">Partner with us.</a>
<?php
endif;
return ob_get_clean();
}
/**
* Hide unused admin tools (Links, Comments, etc)
**/
function hide_admin_links() {
remove_menu_page('link-manager.php');
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'hide_admin_links');
?>