-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebor_functions.php
executable file
·273 lines (236 loc) · 8.43 KB
/
ebor_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
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
<?php
/**
* Update an option name with a value, both given by $_POST data
*/
function ebor_framework_update_option(){
update_option($_POST['optionName'], $_POST['optionValue']);
}
add_action('wp_ajax_ebor_framework_update_option', 'ebor_framework_update_option');
function ebor_framework_functions_backfill(){
if(!( function_exists('ebor_get_portfolio_layouts') )){
function ebor_get_portfolio_layouts(){
return array('Please Switch to a TommusRhodus Theme for this feature' => 'Please Switch to a TommusRhodus Theme for this feature');
}
}
if(!( function_exists('ebor_get_blog_layouts') )){
function ebor_get_blog_layouts(){
return array('Please Switch to a TommusRhodus Theme for this feature' => 'Please Switch to a TommusRhodus Theme for this feature');
}
}
if(!( function_exists('ebor_get_team_layouts') )){
function ebor_get_team_layouts(){
return array('Please Switch to a TommusRhodus Theme for this feature' => 'Please Switch to a TommusRhodus Theme for this feature');
}
}
if(!( function_exists('ebor_get_shop_layouts') )){
function ebor_get_shop_layouts(){
return array('Please Switch to a TommusRhodus Theme for this feature' => 'Please Switch to a TommusRhodus Theme for this feature');
}
}
if(!( function_exists('ebor_get_testimonial_layouts') )){
function ebor_get_testimonial_layouts(){
return array('Please Switch to a TommusRhodus Theme for this feature' => 'Please Switch to a TommusRhodus Theme for this feature');
}
}
}
add_action('after_setup_theme', 'ebor_framework_functions_backfill', 1);
/**
* Filters wp_title to print a neat <title> tag based on what is being viewed.
* @since 1.0.0
* @author tommusrhodus
*/
if(!( function_exists('ebor_framework_wp_title') )){
function ebor_framework_wp_title( $title, $sep ) {
global $page, $paged;
if( get_theme_support('title-tag') ){
return $title;
}
if ( is_feed() ){
return $title;
}
// Add the blog name
$title .= get_bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title .= " $sep $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
$title .= " $sep " . sprintf( __( 'Page %s', 'ebor-framework' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'ebor_framework_wp_title', 10, 2 );
}
function ebor_is_woocommerce() {
if( function_exists( "is_woocommerce" ) && is_woocommerce())
return true;
$woocommerce_keys = array (
"woocommerce_shop_page_id" ,
"woocommerce_terms_page_id" ,
"woocommerce_cart_page_id" ,
"woocommerce_checkout_page_id" ,
"woocommerce_pay_page_id" ,
"woocommerce_thanks_page_id" ,
"woocommerce_myaccount_page_id" ,
"woocommerce_edit_address_page_id" ,
"woocommerce_view_order_page_id" ,
"woocommerce_change_password_page_id" ,
"woocommerce_logout_page_id" ,
"woocommerce_lost_password_page_id"
);
foreach ( $woocommerce_keys as $wc_page_id ) {
if ( get_the_ID () == get_option ( $wc_page_id , 0 ) )
return true ;
}
return false;
}
/**
* Ebor Load Favicons
* Prints Custom Favicons to wp_head()
* @since 1.0.0
* @author TommusRhodus
*/
if(!( function_exists('ebor_framework_load_favicons') )){
function ebor_framework_load_favicons() {
if ( get_option('144_favicon') !=='' )
echo '<link rel="apple-touch-icon-precomposed" sizes="144x144" href="' . get_option('144_favicon') . '">';
if ( get_option('114_favicon') !=='' )
echo '<link rel="apple-touch-icon-precomposed" sizes="114x114" href="' . get_option('114_favicon') . '">';
if ( get_option('72_favicon') !=='' )
echo '<link rel="apple-touch-icon-precomposed" sizes="72x72" href="' . get_option('72_favicon') . '">';
if ( get_option('mobile_favicon') !=='' )
echo '<link rel="apple-touch-icon-precomposed" href="' . get_option('mobile_favicon') . '">';
if ( get_option('custom_favicon') !=='' )
echo '<link rel="shortcut icon" href="' . get_option('custom_favicon') . '">';
}
add_action('wp_head', 'ebor_framework_load_favicons');
}
/**
* Portfolio taxonomy terms output.
*
* Checks that terms exist in the portfolio-category taxonomy, then returns a comma seperated string of results.
* @todo Allow for taxonomy input for differing taxonmoies through the same function.
* @since 1.0.0
* @return string
*/
if(!( function_exists('ebor_the_terms') )){
function ebor_the_terms( $cat, $sep, $value, $args = array() ) {
global $post;
$terms = get_the_terms($post->ID, $cat, '', $sep, '');
if( is_array($terms) ) {
foreach( $terms as $term ){
$args[] = $value;
}
$terms = array_map('_simple_cb', $terms, $args);
return implode( $sep, $terms);
}
}
}
/**
* ebor sanitize title
* A replacement function for WordPress santize_title which breaks in Russian and other languages.
*
* @since 1.0.0
* @author tommusrhodus
*/
if(!( function_exists('ebor_sanitize_title') )){
function ebor_sanitize_title($string){
$string = strtolower(str_replace(' ', '-', $string)); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z\-]/', '', $string); // Removes special chars.
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
}
/**
* Term name return
*
* Returns the Pretty Name of a term array
* @param $t - the term array object
* @since 1.0.0
* @return string
*/
if(!( function_exists('_simple_cb') )){
function _simple_cb($t, $v) {
if( 'slug' == $v ){
return $t->slug;
} elseif( 'link' == $v ){
return '<a href="'.get_term_link( $t, 'portfolio_category' ).'">'.$t->name.'</a>';
} else {
return $t->name;
}
}
}
if(!( function_exists('ebor_add_post_thumbnail_column') )){
function ebor_add_post_thumbnail_column($cols){
$cols['ebor_post_thumb'] = __('Featured Image','ebor');
return $cols;
}
}
add_filter('manage_posts_columns', 'ebor_add_post_thumbnail_column', 5);
add_filter('manage_pages_columns', 'ebor_add_post_thumbnail_column', 5);
if(!( function_exists('ebor_display_post_thumbnail_column') )){
function ebor_display_post_thumbnail_column($col, $id){
switch($col){
case 'ebor_post_thumb':
if( function_exists('the_post_thumbnail') )
echo the_post_thumbnail( 'admin-list-thumb' );
else
echo 'Not supported in theme';
break;
}
}
}
add_action('manage_posts_custom_column', 'ebor_display_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'ebor_display_post_thumbnail_column', 5, 2);
/**
* HEX to RGB Converter
*
* Converts a HEX input to an RGB array.
* @param $hex - the inputted HEX code, can be full or shorthand, #ffffff or #fff
* @since 1.0.0
* @return string
* @author tommusrhodus
*/
if(!( function_exists('ebor_hex2rgb') )){
function ebor_hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = array($r, $g, $b);
return implode(",", $rgb); // returns the rgb values separated by commas
return $rgb; // returns an array with the rgb values
}
}
/**
* Add an additional link to the theme options on the dashboard
*
* @since 1.0.0
* @author tommusrhodus
*/
/*if(!( function_exists('ebor_framework_add_customize_page_link') )){
function ebor_framework_add_customize_page_link() {
$theme = wp_get_theme();
add_dashboard_page( $theme->get( 'Name' ) . ' Theme Readme', $theme->get( 'Name' ) . ' Theme Readme', 'edit_theme_options', 'themes.php?page=ebor_framework-getting-started' );
}
add_action ('admin_menu', 'ebor_framework_add_customize_page_link');
}*/
add_filter('widget_text', 'do_shortcode');
if( ! function_exists('ebor_wp_get_image_id') ) {
/**
* Custom mrancho WordPress Helper function to get attachment id from url
*/
function ebor_wp_get_image_id( $image_url )
{
global $wpdb;
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) );
if( $attachment ) :
return $attachment[0];
endif;
}
}