/
functions.php
executable file
·316 lines (237 loc) · 8.48 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
<?php
/*
Functions
Author: Tyler Cunningham
Establishes the core theme functions.
Copyright (C) 2011 CyberChimps
Version 2.0
*/
// Define global variables.
$themename = 'droidpress';
$themenamefull = 'DroidPress';
$themeslug = 'dp';
$options = get_option($themename);
// Define Content Width.
if ( ! isset( $content_width ) ) $content_width = 600;
// Add support for post formats.
add_theme_support(
'post-formats',
array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat')
);
// Custom excerpt functions.
function droidpress_new_excerpt_more($more) {
global $themename, $themeslug, $options;
if ($options[$themeslug.'_excerpt_link_text'] == '') {
$linktext = '(Read More...)';
}
else {
$linktext = $options[$themeslug.'_excerpt_link_text'];
}
global $post;
return '<a href="'. get_permalink($post->ID) . '"> <br /><br /> '.$linktext.'</a>';
}
add_filter('excerpt_more', 'droidpress_new_excerpt_more');
function droidpress_new_excerpt_length($length) {
global $themename, $themeslug, $options;
if ($options[$themeslug.'_excerpt_length'] == '') {
$length = '55';
}
else {
$length = $options[$themeslug.'_excerpt_length'];
}
return $length;
}
add_filter('excerpt_length', 'droidpress_new_excerpt_length');
// Add auto-feed links support.
add_theme_support('automatic-feed-links');
// Add post-thumb support.
global $themename, $themeslug, $options;
if($options[$themeslug.'_featured_image_height'] == "") {
$featureheight = '100';
}
else {
$featureheight = $options[$themeslug.'_featured_image_height'];
}
if ($options[$themeslug.'_featured_image_width'] == "") {
$featurewidth = '100';
}
else {
$featurewidth = $options[$themeslug.'_featured_image_width'];
}
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( $featureheight, $featurewidth, true );
// This theme allows users to set a custom background
add_theme_support( 'custom-background' );
add_theme_support( "title-tag" );
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
// PIE
function droidpress_render_ie_pie() { ?>
<style type="text/css" media="screen">
#header li a, .postmetadata, .post_container, #navbackground, .wp-caption, .sidebar-widget-style, .sidebar-widget-title, .boxes, .box1, .box2, .box3, .box-widget-title,
{
behavior: url('<?php get_stylesheet_directory_uri('stylesheet_directory'); ?>/library/pie/PIE.htc');
}
</style>
<?php
}
add_action('wp_head', 'droidpress_render_ie_pie', 8);
// + 1 Button
function droidpress_plusone(){
$path = get_template_directory_uri() ."/library/js/";
$script = "
<script type=\"text/javascript\" src=\"".$path."plusone.js\"></script>
";
echo $script;
}
add_action('wp_head', 'droidpress_plusone');
// Call Superfish
if ( !is_admin() )
{
function droidpress_superfish()
{
// Adjust the below path to where scripts dir is, if you must.
$scriptdir = get_template_directory_uri() ."/library/sf/";
// Register the Superfish javascript file
wp_register_script( 'superfish', $scriptdir.'sf.js', false, '1.4.8');
wp_register_script( 'sf-menu', $scriptdir.'sf-menu.js');
//load the scripts.
wp_enqueue_script('jquery');
wp_enqueue_script('superfish');
wp_enqueue_script('sf-menu');
}
add_action('wp_enqueue_scripts', 'droidpress_superfish');
}
// Register menu names
function droidpress_register_menus() {
register_nav_menus(
array( 'header-menu' => 'Header Menu', 'footer-menu' => 'Footer Menu' )
);
}
add_action( 'init', 'droidpress_register_menus' );
// Menu fallback
function droidpress_menu_fallback() {
global $post; ?>
<ul id="menu-nav" class="sf-menu">
<?php wp_list_pages( 'title_li=&sort_column=menu_order&depth=3'); ?>
</ul><?php
}
//Add link to theme settings in Admin bar
function droidpress_admin_link() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array( 'id' => 'DroidPress', 'title' => 'DroidPress Settings', 'href' => admin_url('themes.php?page=theme_options') ) );
}
add_action( 'admin_bar_menu', 'droidpress_admin_link', 113 );
// DroidPress Widgits Init
function droidpress_widgets_init() {
register_sidebar(array(
'name' => 'Sidebar Widgets',
'id' => 'sidebar-widgets',
'description' => 'These are widgets for the sidebar.',
'before_widget' => '<div id="%1$s" class="sidebar-widget-style">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sidebar-widget-title">',
'after_title' => '</h2>'
));
register_sidebar(array(
'name' => 'Footer',
'id' => 'footer-widgets',
'description' => 'These are widgets for the footer',
'before_widget' => '<div class="footer-widgets">',
'after_widget' => '</div>',
'before_title' => '<h3 class="footer-widget-title">',
'after_title' => '</h3>',
));
}
add_action( 'widgets_init', 'droidpress_widgets_init' );
//Theme options files
require_once ( get_template_directory() . '/library/options/options-core.php' );
require_once ( get_template_directory() . '/library/options/meta-box.php' );
require_once ( get_template_directory() . '/library/options/options-themes.php' );
add_action( 'admin_notices', 'droidpress_admin_notice' );
function droidpress_admin_notice(){
global $droidpress_check_screen;
$droidpress_check_screen = get_admin_page_title();
if ( $droidpress_check_screen == 'DroidPress Settings' )
{
echo '<div class="notice notice-info is-dismissible"><p class="droidpress-upgrade-callout" style="font-size:18px; "><a href="https://cyberchimps.com/free-download-50-stock-images-use-please/?utm_source=DroidPress" target="_blank" style="text-decoration:none;">FREE - Download CyberChimps\' Pack of 50 High-Resolution Stock Images Now</a></p></div>';
}
}
function droidpress_customize_edit_links( $wp_customize ) {
$wp_customize->selective_refresh->add_partial( 'blogname', array(
'selector' => '.sitename a'
) );
$wp_customize->selective_refresh->add_partial( 'nav_menu_locations[header-menu]', array(
'selector' => '#navbackground'
) );
$wp_customize->selective_refresh->add_partial( 'nav_menu_locations[footer-menu]', array(
'selector' => '#credit'
) );
}
add_action( 'customize_register', 'droidpress_customize_edit_links' );
add_theme_support( 'customize-selective-refresh-widgets' );
add_action( 'admin_notices', 'droidpress_admin_notices' );
function droidpress_admin_notices()
{
$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' || $admin_check_screen == 'DroidPress Settings' )
{
?>
<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' ); ?>"><?php esc_html_e( 'Activate the SlideDeck Lite plugin', 'droidpress' ); ?></a>
<?php
}
else
{
?>
<a href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); ?>"><?php esc_html_e( 'Install the SlideDeck Lite plugin', 'droidpress' ); ?></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' || $admin_check_screen == 'DroidPress Settings' )
{
?>
<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' ); ?>"><?php esc_html_e( 'Activate the WPForms Lite plugin', 'droidpress' ); ?></a>
<?php
}
else
{
?>
<a href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); ?>"><?php esc_html_e( 'Install the WPForms Lite plugin', 'droidpress' ); ?></a>
<?php } ?>
</p>
</div>
<?php
}
}
if ( $admin_check_screen == 'Manage Themes' || $admin_check_screen == 'DroidPress Settings' )
{
?>
<div class="notice notice-success is-dismissible">
<b><p><?php esc_html_e( 'Liked this theme? ', 'droidpress' ); ?><a href="https://wordpress.org/support/theme/droidpress/reviews/#new-post" target="_blank"><?php esc_html_e( 'Leave us', 'droidpress' ); ?></a><?php esc_html_e( ' a ***** rating. Thank you! ', 'droidpress' ); ?></p></b>
</div>
<?php
}
}