-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathfunctions.php
388 lines (326 loc) · 11.9 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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
/**
* Main Function
*
* Load functions and classes
*
* @package responsive_mobile
* @license license.txt
* @copyright 2014 CyberChimps Inc
* @since 0.0.1
*
* Please do not edit this file. This file is part of the responsive_mobile Framework and all modifications
* should be made in a child theme.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
$template_directory = get_template_directory();
/**
* Basic theme functionality
*/
require $template_directory . '/includes/functions.php';
/**
* Theme Options
*/
require $template_directory . '/libraries/class-responsive-options.php';
require $template_directory . '/includes/functions-theme-options.php';
require $template_directory . '/includes/functions-theme-options-page.php';
require( $template_directory . '/includes/customizer.php' );
require( $template_directory . '/includes/admin-about.php' );
/**
* Meta Box Options
*/
require $template_directory . '/libraries/class-meta-box.php';
require $template_directory . '/includes/functions-meta-box.php';
/**
* Custom template tags for this theme.
*/
require $template_directory . '/includes/functions-template-tags.php';
/**
* Support THA Theme hooks through Responsives own functions.
*/
require $template_directory . '/core/tha-theme-hooks.php';
//require $template_directory . '/core/functions-demodata.php';
require $template_directory . '/includes/responsive-hooks.php';
/**
* Theme Upsell
*/
//require $template_directory . '/core/functions-theme-upsell.php';
/**
* Create header items that hook into header.php
*/
require $template_directory . '/includes/functions-header.php';
/**
* Implement the Custom Header feature.
*/
require $template_directory . '/includes/functions-custom-header.php';
/**
* Custom functions that act independently to the theme templates.
*/
require $template_directory . '/includes/functions-extras.php';
require $template_directory . '/includes/functions-extentions.php';
require $template_directory . '/includes/functions-layout.php';
require $template_directory . '/includes/functions-front.php';
/**
* Register Menus
*/
require $template_directory . '/includes/functions-menu.php';
/**
* Register Sidebars
*/
require $template_directory . '/includes/functions-sidebar.php';
/**
* Plugin compatibility
*/
require $template_directory . '/includes/functions-plugins.php';
/**
* Theme Update
*/
require $template_directory . '/includes/functions-update.php';
/**
* Plugin dependency
*/
require $template_directory . '/core/functions-install.php';
/**
* Admin functionality
*/
require $template_directory . '/core/functions-admin.php';
if ( ! defined( 'ELEMENTOR_PARTNER_ID' ) ) {
define( 'ELEMENTOR_PARTNER_ID', 2126 );
}
// enabling theme support for title tag
function responsivemobile_title_setup()
{
add_theme_support( 'title-tag' );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
}
add_action( 'after_setup_theme', 'responsivemobile_title_setup' );
function responsive_mobile_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->selective_refresh->add_partial( 'blogname', array(
'selector' => '.site-name a',
) );
$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
'selector' => '.site-description',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[copyright_textbox]', array(
'selector' => '.copyright',
) );
$wp_customize->selective_refresh->add_partial( 'nav_menu_locations[top-menu]', array(
'selector' => '.main-nav',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[home_headline]', array(
'selector' => '.featured-title',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[home_subheadline]', array(
'selector' => '.featured-subtitle',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[home_content_area]', array(
'selector' => '.featured-text',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[cta_text]', array(
'selector' => '#call-to-action',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[featured_content]', array(
'selector' => '.featured-image',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[callout_headline]', array(
'selector' => '.callout-title',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[callout_content_area]', array(
'selector' => '.callout-text',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[callout_cta_text]', array(
'selector' => '#callout-cta',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[poweredby_link]', array(
'selector' => '.powered',
) );
$wp_customize->selective_refresh->add_partial( 'sidebars_widgets[home-widget-1]', array(
'selector' => '#home_widget_1',
) );
$wp_customize->selective_refresh->add_partial( 'sidebars_widgets[home-widget-2]', array(
'selector' => '#home_widget_2',
) );
$wp_customize->selective_refresh->add_partial( 'sidebars_widgets[home-widget-3]', array(
'selector' => '#home_widget_3',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[team_title]', array(
'selector' => '.section_title span',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[team_val]', array(
'selector' => '.team_first_row',
) );
$wp_customize->selective_refresh->add_partial( 'responsive_mobile_theme_options[team]', array(
'selector' => '#team_inner_div',
) );
}
add_action( 'customize_register', 'responsive_mobile_customize_register' );
add_theme_support( 'customize-selective-refresh-widgets' );
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( !is_plugin_active( 'cyberchimpsoptions/cc-pro-features.php' ) )
add_action( 'customize_controls_print_footer_scripts', 'responsive_mobile_add_upgrade_button' );
function responsive_mobile_add_upgrade_button() {
// Get the upgrade link.
$upgrade_link = esc_url_raw( 'https://cyberchimps.com/store/pro-features/' );
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
jQuery( '#customize-info .accordion-section-title' ).append( '<a target="_blank" class="button btn-upgrade" href="<?php echo esc_url( $upgrade_link ); ?>"><?php esc_html_e( 'Upgrade To Pro', 'responsive-mobile' ); ?></a>' );
jQuery( '#customize-info .btn-upgrade' ).click( function( event ) {
event.stopPropagation();
} );
} );
</script>
<style>
.wp-core-ui .btn-upgrade {
color: #fff;
background: none repeat scroll 0 0 #5BC0DE;
border-color: #CCCCCC;
box-shadow: 0 1px 0 #5BC0DE inset, 0 1px 0 rgba(0, 0, 0, 0.08);
float: right;
//margin-top: -23px;
margin-top: 15px;
font-size: 14px;
height: 30px;
margin-bottom: 15px;
}
.wp-core-ui .btn-upgrade:hover {
color: #fff;
background: none repeat scroll 0 0 #39B3D7;
box-shadow: 0 1px 0 #39B3D7 inset, 0 1px 0 rgba(0, 0, 0, 0.08);
}
.wp-core-ui #customize-info .theme-name{
word-break: break-all;
padding-right: 120px;
}
.wp-full-overlay-sidebar-content #customize-info {background-color: #fff;}
</style>
<?php
}
add_action( 'admin_notices', 'responsive_mobile_rating_notice' );
function responsive_mobile_rating_notice()
{
$check_screen = get_admin_page_title();
if ( $check_screen == 'Theme Options' )
{
?>
<div class="notice notice-success is-dismissible">
<b><p>Liked this theme? <a href="https://wordpress.org/support/theme/responsive-mobile/reviews/#new-post" target="_blank">Leave us</a> a ***** rating. Thank you! </p></b>
</div>
<?php
}
}
if( !function_exists('responsive_get_attachment_id_from_url') ) :
function responsive_get_attachment_id_from_url( $attachment_url = '' ) {
global $wpdb;
$attachment_id = false;
// If there is no url, return.
if ( '' == $attachment_url )
return;
// Get the upload directory paths
$upload_dir_paths = wp_upload_dir();
// Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) {
// If this is the URL of an auto-generated thumbnail, get the URL of the original image
$attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url );
// Remove the upload path base directory from the attachment URL
$attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url );
// Finally, run a custom database query to get the attachment ID from the modified attachment URL
$attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url ) );
}
return $attachment_id;
}
endif;
/* ================= Sticky Header Setting =========================== */
add_action( 'wp_footer', 'cyberchimps_fixed_menu_onscroll' );
function cyberchimps_fixed_menu_onscroll()
{
$responsive_options = responsive_mobile_get_options();
if ( isset( $responsive_options['sticky_header']) && $responsive_options['sticky_header'] == '1') {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$(window).scroll(function() {
if ($(this).scrollTop() > 0) {
$('#header_section').addClass("sticky-header");
}
else{
$('#header_section').removeClass("sticky-header");
}
});
});
</script>
<?php
}
}
if( !function_exists('responsive_exclude_post_cat') ) :
function responsive_exclude_post_cat( $query ){
$cat = get_theme_mod( 'responsive_mobile_exclude_post_cat' );
if( $cat && ! is_admin() && $query->is_main_query() ){
$cat = array_diff( array_unique( $cat ), array('') );
if( $query->is_home() || $query->is_archive() ) {
$query->set( 'category__not_in', $cat );
//$query->set( 'cat', '-5,-6,-65,-66' );
}
}
}
endif;
add_filter( 'pre_get_posts', 'responsive_exclude_post_cat' );
function responsive_custom_category_widget( $arg ) {
$cat = get_theme_mod( 'exclude_post_cat' );
if( $cat ){
$cat = array_diff( array_unique( $cat ), array('') );
$arg["exclude"] = $cat;
}
return $arg;
}
add_filter( "widget_categories_args", "responsive_custom_category_widget" );
add_filter( "widget_categories_dropdown_args", "responsive_custom_category_widget" );
function responsive_exclude_post_cat_recentpost_widget($array){
$s = '';
$i = 1;
$cat = get_theme_mod( 'exclude_post_cat' );
if( $cat ){
$cat = array_diff( array_unique( $cat ), array('') );
foreach( $cat as $c ){
$i++;
$s .= '-'.$c;
if( count($cat) >= $i )
$s .= ', ';
}
}
$array['cat']=array($s);
//$exclude = array( 'cat' => $s );
return $array;
}
add_filter( "widget_posts_args", "responsive_exclude_post_cat_recentpost_widget" );
function responsive_pro_categorylist_validate( ) {
// An array of valid results
$args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'taxonomy' => 'category'
);
$option_categories = array();
$category_lists = get_categories( $args );
$option_categories[''] = esc_html(__( 'Choose Category', 'responsive-mobile' ));
foreach( $category_lists as $category ){
$option_categories[$category->term_id] = $category->name;
}
return $option_categories;
}
/**
* Enqueue block styles in editor
*/
function responsive_mobile_block_styles() {
wp_enqueue_style( 'rm-gutenberg-blocks', get_stylesheet_directory_uri() . '/css/gutenberg-blocks.css', array(), '1.0' );
}
add_action( 'enqueue_block_editor_assets', 'responsive_mobile_block_styles' );