-
Notifications
You must be signed in to change notification settings - Fork 15
/
init.php
executable file
·256 lines (206 loc) · 9.01 KB
/
init.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
<?php
/**
* Title: Core Initializer
*
* Description: Initializes the core. Adds all required files.
*
* Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
* should be made in a child theme.
*
* @category Cyber Chimps Framework
* @package Framework
* @since 1.0
* @author CyberChimps
* @license http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
* @link http://www.cyberchimps.com/
*/
if ( ! function_exists( 'cyberchimps_core_setup_theme' ) ) :
// Setup the theme
function cyberchimps_core_setup_theme() {
// Set directory path
$directory = get_template_directory();
// Load core functions file
require_once $directory . '/cyberchimps/functions.php';
// Load core hooks file
require_once $directory . '/cyberchimps/inc/hooks.php';
// Load element files before meta and options
require_once $directory . '/elements/init.php';
// Load santize before options-init and options core
require_once $directory . '/cyberchimps/options/options-sanitize.php';
// Load core options file
require_once $directory . '/cyberchimps/options/options-init.php';
// Load default core settings
require_once $directory . '/cyberchimps/options/options-core.php';
// Load core hooks file
require_once $directory . '/cyberchimps/inc/cc-custom-background.php';
// Load pro features if a pro theme. Load prior to meta boxes so that filters work
if ( cyberchimps_theme_check() == 'pro' ) {
require_once $directory . '/elements/setup/features.php';
}
// Load new meta box class
require_once $directory . '/cyberchimps/options/meta-box-class/my-meta-box-class.php';
// Load new meta box options
require_once $directory . '/cyberchimps/options/meta-box-class/meta-box.php';
// Load theme upsell.
require_once $directory . '/cyberchimps/options/theme-upsell.php';
// Core Translations can be filed in the /inc/languages/ directory
load_theme_textdomain( 'cyberchimps_core', $directory . '/cyberchimps/lib/languages' );
load_theme_textdomain( 'cyberchimps_elements', $directory . '/elements/lib/languages' );
// Add support for the Aside Post Formats
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// Enable support for Post Thumbnails
add_theme_support( 'post-thumbnails' );
// add theme support for backgrounds
$defaults = array(
'default-color' => apply_filters( 'default_background_color', '' ),
'default-image' => apply_filters( 'default_background_image', '' ),
'wp-head-callback' => 'cyberchimps_custom_background_cb',
);
$defaults = apply_filters( 'cyberchimps_background_default_args', $defaults );
add_theme_support( 'custom-background', $defaults );
// This theme uses wp_nav_menu() in one location.
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'cyberchimps_core' ),
)
);
// set up defaults
$option_defaults = cyberchimps_get_default_values();
if ( ! get_option( 'cyberchimps_options' ) && isset( $_GET['activated'] ) ) {
update_option( 'cyberchimps_options', $option_defaults );
} //if not then set up defaults for this theme
elseif ( get_option( 'cyberchimps_options' ) && isset( $_GET['activated'] ) ) {
$options = get_option( 'cyberchimps_options' );
$options['header_section_order'] = $option_defaults['header_section_order'];
$options['theme_backgrounds'] = $option_defaults['theme_backgrounds'];
update_option( 'cyberchimps_options', $options );
}
}
endif; // cyberchimps_core_setup_theme
add_action( 'after_setup_theme', 'cyberchimps_core_setup_theme' );
function cyberchimps_custom_background_cb() {
$style = '';
// $background is the saved custom image, or the default image.
$background = get_background_image();
// $color is the saved custom color.
// A default has to be specified in style.css. It will not be printed here.
$color = get_theme_mod( 'background_color' );
// CyberChimps background image
$cc_background = get_theme_mod( 'cyberchimps_background' );
if ( ! $background && ! $color && ! $cc_background ) {
return;
}
if ( $background ) {
$image = " background-image: url('$background');";
$repeat = get_theme_mod( 'background_repeat', 'repeat' );
if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) {
$repeat = 'repeat';
}
$repeat = " background-repeat: $repeat;";
$position = get_theme_mod( 'background_position_x', 'left' );
if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) {
$position = 'left';
}
$position = " background-position: top $position;";
$attachment = get_theme_mod( 'background_attachment', 'scroll' );
if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) {
$attachment = 'scroll';
}
$attachment = " background-attachment: $attachment;";
$style = $image . $repeat . $position . $attachment;
} elseif ( $cc_background != 'none' && ! empty( $cc_background ) ) {
$img_url = get_template_directory_uri() . '/cyberchimps/lib/images/backgrounds/' . $cc_background . '.jpg';
$style = "background-image: url( '$img_url' );";
} elseif ( $color ) {
$style = "background-color: #$color;";
$style .= 'background-image: none;';
} ?>
<style type="text/css">
body {
<?php echo trim( $style ); ?>
}
</style>
<?php
}
// Register our sidebars and widgetized areas.
function cyberchimps_widgets_init() {
// Add left sidebar only to pro themes as it is not avialble in free.
if ( 'pro' == cyberchimps_theme_check() ) {
register_sidebar(
array(
'name' => __( 'Sidebar Left', 'cyberchimps_core' ),
'id' => 'sidebar-left',
'before_widget' => apply_filters( 'cyberchimps_sidebar_before_widget', '<aside id="%1$s" class="widget-container %2$s">' ),
'after_widget' => apply_filters( 'cyberchimps_sidebar_after_widget', '</aside>' ),
'before_title' => apply_filters( 'cyberchimps_sidebar_before_widget_title', '<h3 class="widget-title">' ),
'after_title' => apply_filters( 'cyberchimps_sidebar_after_widget_title', '</h3>' ),
)
);
}
register_sidebar(
array(
'name' => __( 'Sidebar Right', 'cyberchimps_core' ),
'id' => 'sidebar-right',
'before_widget' => apply_filters( 'cyberchimps_sidebar_before_widget', '<aside id="%1$s" class="widget-container %2$s">' ),
'after_widget' => apply_filters( 'cyberchimps_sidebar_after_widget', '</aside>' ),
'before_title' => apply_filters( 'cyberchimps_sidebar_before_widget_title', '<h3 class="widget-title">' ),
'after_title' => apply_filters( 'cyberchimps_sidebar_after_widget_title', '</h3>' ),
)
);
register_sidebar(
array(
'name' => __( 'Footer Widgets', 'cyberchimps_core' ),
'id' => 'cyberchimps-footer-widgets',
'before_widget' => apply_filters( 'cyberchimps_footer_before_widget', '<aside id="%1$s" class="widget-container span3 %2$s">' ),
'after_widget' => apply_filters( 'cyberchimps_footer_after_widget', '</aside>' ),
'before_title' => apply_filters( 'cyberchimps_footer_before_widget_title', '<h3 class="widget-title">' ),
'after_title' => apply_filters( 'cyberchimps_footer_after_widget_title', '</h3>' ),
)
);
}
add_action( 'widgets_init', 'cyberchimps_widgets_init' );
function cyberchimps_load_hooks() {
// Set the path to hooks directory.
$hooks_path = get_template_directory() . '/cyberchimps/hooks/';
require_once $hooks_path . 'wp-head-hooks.php';
require_once $hooks_path . 'header-hooks.php';
require_once $hooks_path . 'blog-hooks.php';
require_once $hooks_path . 'page-hooks.php';
require_once $hooks_path . 'footer-hooks.php';
}
add_action( 'after_setup_theme', 'cyberchimps_load_hooks' );
// after install redirect user to options page if it's a pro theme.
function cyberchimps_pro_welcome_notice() {
global $pagenow;
if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
if ( 'pro' == cyberchimps_theme_check() ) {
wp_redirect( 'themes.php?page=cyberchimps-theme-options' );
}
}
}
add_action( 'after_setup_theme', 'cyberchimps_pro_welcome_notice' );
// Function to check for additional CSS option in WP 4.7 and above
add_action( 'after_setup_theme', 'cyberchimps_custom_css_migrate' );
function cyberchimps_custom_css_migrate() {
if ( function_exists( 'wp_update_custom_css_post' ) ) {
$custom_css = cyberchimps_get_option( 'custom_css' );
if ( $custom_css ) {
$core_css = wp_get_custom_css(); // Preserve any CSS already added to the core option.
$return = wp_update_custom_css_post( $core_css . $custom_css );
if ( ! is_wp_error( $return ) ) {
// Remove the old theme_option, so that the CSS is stored in only one place moving forward.
remove_custom_css_option( 'custom_css' );
}
}
}
}
function remove_custom_css_option( $name ) {
$mods = get_option( 'cyberchimps_options' );
if ( ! isset( $mods[ $name ] ) ) {
return;
}
unset( $mods[ $name ] );
update_option( 'cyberchimps_options', $mods );
}