-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.php
344 lines (299 loc) · 9.18 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
<?php
require( get_template_directory() . '/admin-about.php' );
add_action( 'after_setup_theme', 'fad_setup' );
function fad_setup()
{
load_theme_textdomain( 'fad', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
global $content_width;
if ( ! isset( $content_width ) ) $content_width = 640;
register_nav_menus(
array( 'main-menu' => __( 'Main Menu', 'fad' ) , 'top-menu' => __( 'Top Menu', 'fad' ))
);
add_theme_support( 'title-tag' );
}
add_action( 'wp_enqueue_scripts', 'fad_load_scripts' );
function fad_load_scripts()
{
wp_enqueue_script( 'jquery' );
wp_register_script( 'fad-videos', get_template_directory_uri() . '/js/videos.js' );
wp_enqueue_script( 'fad-videos' );
}
add_action( 'wp_head', 'fad_print_custom_scripts', 99 );
function fad_print_custom_scripts()
{
if ( !is_admin() ) {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$("#wrapper").vids();
});
</script>
<?php
}
}
add_action( 'comment_form_before', 'fad_enqueue_comment_reply_script' );
function fad_enqueue_comment_reply_script()
{
if ( get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); }
}
add_filter( 'the_title', 'fad_title' );
function fad_title( $title ) {
if ( $title == '' ) {
return '→';
} else {
return $title;
}
}
add_filter( 'wp_title', 'fad_filter_wp_title' );
function fad_filter_wp_title( $title )
{
return $title . esc_attr( get_bloginfo( 'name' ) );
}
add_action( 'widgets_init', 'fad_widgets_init' );
function fad_widgets_init()
{
register_sidebar( array (
'name' => __( 'Sidebar Widget Area', 'fad' ),
'id' => 'primary-widget-area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
function fad_custom_pings( $comment )
{
$GLOBALS['comment'] = $comment;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
<?php
}
add_filter( 'get_comments_number', 'fad_comments_number' );
function fad_comments_number( $count )
{
if ( !is_admin() ) {
global $id;
$comments_by_type = get_comments( 'status=approve&post_id=' . $id );
return count( $comments_by_type );
} else {
return $count;
}
}
add_action( 'customize_register', 'fad_customizer' );
function fad_customizer( $wp_customize ) {
$wp_customize->add_section( 'fad_design_section', array(
'title' => __( 'Colors', 'fad' ),
'priority' => 35,
) );
// Background Color
$wp_customize->add_setting( 'fad_background_colorpicker', array(
'default' => '#225277',
'type' => 'option',
'sanitize_callback' => 'fad_text_sanitization'
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_colorpicker', array(
'label' => __( 'Background Color', 'fad' ),
'section' => 'fad_design_section',
'settings' => 'fad_background_colorpicker',
) ) );
//Main Menu Text Color
$wp_customize->add_setting( 'fad_main_menu_text_colorpicker', array(
'default' => '#225277',
'type' => 'option',
'sanitize_callback' => 'fad_text_sanitization'
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'main_menu_text_colorpicker', array(
'label' => __( 'Main Menu Text Color', 'fad' ),
'section' => 'fad_design_section',
'settings' => 'fad_main_menu_text_colorpicker',
) ) );
// Top Menu Text Color
$wp_customize->add_setting( 'fad_top_menu_text_colorpicker', array(
'default' => '#333333',
'type' => 'option',
'sanitize_callback' => 'fad_text_sanitization'
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'top_menu_text_colorpicker', array(
'label' => __( 'Top Menu Text Color', 'fad' ),
'section' => 'fad_design_section',
'settings' => 'fad_top_menu_text_colorpicker',
) ) );
$wp_customize->add_section( 'fad_blog_section', array(
'title' => __( 'Blog Options', 'fad' ),
'priority' => 36,
) );
$wp_customize->add_setting( 'fad_post_excerpts', array(
'type' => 'option',
'sanitize_callback' => 'fad_sanitize_checkbox'
) );
$wp_customize->add_control( 'post_excerpts', array(
'label' => __( 'Post Excerpts', 'fad' ),
'section' => 'fad_blog_section',
'settings' => 'fad_post_excerpts',
'type' => 'checkbox'
) );
$wp_customize->add_setting( 'fad_options_blog_read_more_text', array(
'type' => 'option',
'sanitize_callback' => 'fad_text_sanitization'
) );
$wp_customize->add_control( 'fad_blog_read_more_text', array(
'label' => __( 'Read More Text', 'fad' ),
'section' => 'fad_blog_section',
'default' => __( 'Read More...', 'fad' ),
'settings' => 'fad_options_blog_read_more_text',
'type' => 'text'
) );
//Post Excerpts Length
$wp_customize->add_setting( 'fad_options_blog_excerpt_length', array(
'type' => 'option',
'sanitize_callback' => 'fad_text_sanitization'
) );
$wp_customize->add_control( 'fad_blog_excerpt_length', array(
'label' => __( 'Excerpt Length', 'fad' ),
'section' => 'fad_blog_section',
'default' => 55,
'settings' => 'fad_options_blog_excerpt_length',
'type' => 'text'
) );
}
function fad_text_sanitization( $text ) {
return sanitize_text_field( $text );
}
function fad_sanitize_checkbox( $input ) {
if( $input ) {
$output = '1';
}
else {
$output = false;
}
return $output;
}
add_action( 'wp_head', 'fad_css_styles', 50 );
function fad_css_styles(){
$main_menu_color = get_option('fad_main_menu_text_colorpicker');
$top_menu_color = get_option('fad_top_menu_text_colorpicker');
$background_color = get_option('fad_background_colorpicker');
?>
<style type="text/css" media="all">
<?php if ( !empty( $main_menu_color ) ) : ?>
#menu ul li a {
color:<?php echo $main_menu_color; ?>;
}
<?php endif; ?>
<?php if ( !empty( $top_menu_color ) ) : ?>
.top-menu li a {
color:<?php echo $top_menu_color; ?>;
}
<?php endif; ?>
<?php if ( !empty( $background_color ) ) : ?>
body {
background:<?php echo $background_color; ?>;
}
<?php endif; ?>
</style>
<?php
}
function fad_excerpt_more( $more ) {
$read_more_text = get_option( 'fad_options_blog_read_more_text');
if($read_more_text != ''){
global $post;
return '<p><a href="' . esc_url(get_permalink( $post->ID )) . '">' . $read_more_text . '</a></p>';
}else{
return $more;
}
}
add_filter( 'excerpt_more', 'fad_excerpt_more' );
function fad_custom_excerpt_length( $length ) {
$read_more_length = get_option( 'fad_options_blog_excerpt_length');
if($read_more_length != ''){
return $read_more_length;
}else{
return $length;
}
}
add_filter( 'excerpt_length', 'fad_custom_excerpt_length', 999 );
add_action( 'admin_notices', 'my_admin_notice' );
function my_admin_notice(){
global $fad_check_screen;
$fad_check_screen = get_admin_page_title();
if ( $fad_check_screen == 'Manage Themes' )
{
echo '<div class="notice notice-info is-dismissible"><p class="fad-upgrade-callout" style="font-size:18px; "><a href="https://cyberchimps.com/free-download-50-stock-images-use-please/?utm_source=Fad" target="_blank" style="text-decoration:none;">FREE - Download CyberChimps\' Pack of 50 High-Resolution Stock Images Now</a></p></div>';
}
}
function fad_customize_edit_links( $wp_customize ) {
$wp_customize->selective_refresh->add_partial( 'blogname', array(
'selector' => '#site-title h1'
) );
$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
'selector' => '#site-description'
) );
}
add_action( 'customize_register', 'fad_customize_edit_links' );
add_theme_support( 'customize-selective-refresh-widgets' );
add_action( 'admin_notices', 'fad_admin_notice' );
function fad_admin_notice(){
$admin_check_screen = get_admin_page_title();
if( !class_exists('SlideDeckPlugin') )
{
$plugin='slidedeck/slidedeck.php';
$slug = 'slidedeck';
$installed_plugins = get_plugins();
if ( $admin_check_screen == 'Manage Themes' )
{
?>
<div class="notice notice-info is-dismissible" style="margin-top:15px;">
<p>
<?php if( isset( $installed_plugins[$plugin] ) )
{
?>
<a href="<?php echo admin_url( 'plugins.php' ); ?>">Activate the SlideDeck Lite plugin</a>
<?php
}
else
{
?>
<a href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); ?>">Install the SlideDeck Lite plugin</a>
<?php } ?>
</p>
</div>
<?php
}
}
if( !class_exists('WPForms') )
{
$plugin = 'wpforms-lite/wpforms.php';
$slug = 'wpforms-lite';
$installed_plugins = get_plugins();
if ( $admin_check_screen == 'Manage Themes' )
{
?>
<div class="notice notice-info is-dismissible" style="margin-top:15px;">
<p>
<?php if( isset( $installed_plugins[$plugin] ) )
{
?>
<a href="<?php echo admin_url( 'plugins.php' ); ?>">Activate the WPForms Lite plugin</a>
<?php
}
else
{
?>
<a href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); ?>">Install the WP Forms Lite plugin</a>
<?php } ?>
</p>
</div>
<?php
}
}
if ( $admin_check_screen == 'Manage Themes' )
{
?>
<div class="notice notice-success is-dismissible">
<b><p>Liked this theme? <a href="https://wordpress.org/support/theme/fad/reviews/#new-post" target="_blank">Leave us</a> a ***** rating. Thank you! </p></b>
</div>
<?php
}
}