-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
295 lines (271 loc) · 9.34 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
<?php
/**
* Customize Plus Demo Theme
*
* @package Customize_Plus
* @author Author's name <[email protected]>
* @copyright 2015 Author's name
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/K6
*/
class Customize_Plus_Demo {
/**
* Theme version
*
* @since 0.0.1
*/
const VERSION = '0.0.1';
/**
* Theme prefix constant
* @since 0.0.1
*/
const PREFIX = 'cpdemo';
/**
* Theme docs base url
* @since 0.0.1
*/
const DOCS_BASE_URL = 'https://knitkode.com/docs/';
/**
* Settings default values
*
* @since 0.0.1
* @var array
*/
public static $settings_defaults;
/**
* Constructor
*
* @since 0.0.1
*/
public function __construct() {
require_once dirname( __FILE__ ) . '/vendor/tgm/plugin-activation/class-tgm-plugin-activation.php';
add_action( 'tgmpa_register', array( __CLASS__, 'register_plugins' ) );
add_action( 'after_setup_theme', array( __CLASS__, 'add_theme_supports' ) );
add_action( 'kkcp_theme_is_configured', array( __CLASS__, 'set_settings_defaults' ), 10, 1 );
add_action( 'kkcp_customize_register_custom_classes', array( __CLASS__, 'register_custom_classes' ), 20, 1 );
add_action( 'kkcp_info_add_to_view', array( __CLASS__, 'add_contacts_to_customize' ) );
add_action( 'customize_register', array( __CLASS__, 'remove_wp_defaults' ), 10, 1 );
add_action( 'customize_controls_print_styles' , array( __CLASS__, 'customize_enqueue_css' ) );
add_action( 'customize_controls_print_footer_scripts' , array( __CLASS__, 'customize_enqueue_js' ) );
// the following pretty self-explanatory hooks are also available
// 'kkcp_customize_enqueue_css_admin_pre'
// 'kkcp_customize_enqueue_css_admin_post'
// 'kkcp_customize_enqueue_js_admin_pre'
// 'kkcp_customize_enqueue_js_admin_post'
add_action( 'customize_preview_init' , array( __CLASS__, 'customize_enqueue_js_preview' ) );
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_manager' ) );
}
/**
* Register the required plugins for this theme.
* This function is hooked into tgmpa_init, which is fired within the
* TGM_Plugin_Activation class constructor.
*
* @see http://tgmpluginactivation.com/configuration/
* @since 0.0.1
*/
public static function register_plugins() {
$plugins = array(
array(
'name' => 'Customize Plus',
'slug' => 'customize-plus',
'version' => '0.0.1',
'required' => true,
'force_activation' => false,
),
// @note this is only for Customize Plus Premium
array(
'name' => 'Customize Plus Premium',
'slug' => 'customize-plus-premium',
'version' => '0.0.1',
'required' => false, // @@note once released this should be false ... ? \\
'force_activation' => false, // @@note once released this should be false ... ? \\
),
);
$config = array(
'id' => 'tgmpa', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'message' => '', // Message to output right before the plugins table.
);
tgmpa( $plugins, $config );
}
/**
* Add Theme Support
*
* @since 0.0.1
*/
public static function add_theme_supports() {
// Customize Plus settings
add_theme_support( 'kkcp-customize', array(
'prefix' => self::PREFIX,
'customize_tree' => self::get_customize_tree(),
'images_base_url' => get_stylesheet_directory_uri() . '/images/',
'docs_base_url' => self::DOCS_BASE_URL,
'dynamic_controls_rendering' => false,
// @note this works only with Customize Plus Premium
'styles' => array(
array(
'id' => self::PREFIX . '-example',
'dependencies' => array(),
'version' => self::VERSION,
'path_uncompiled' => '/styles/theme.less',
),
),
// @note this works only with Customize Plus Premium
'components' => array(
'compiler' => 'required',
'advanced' => 'required',
'screenpreview' => 'recommended',
'reset' => 'recommended',
'resizer' => 'recommended',
'search' => 'recommended',
'import' => 'blocked',
'export' => 'recommended',
'editor' => 'optional',
'info' => 'recommended',
)
) );
}
/**
* Set settings default value on static property
*
* @since 0.0.1
* @param array $settings_defaults
*/
public static function set_settings_defaults( $settings_defaults ) {
self::$settings_defaults = $settings_defaults;
}
/**
* Add custom controls / settings / sections / panels classes
* to the Customize (we extend Customize Plus, so we use its hook).
*
* @since 0.0.1
* @param $customize_plus {KKcp_Customize} Customize Plus Customize instance
*/
public static function register_custom_classes( $customize_plus ) {
// require_once( get_stylesheet_directory() . '/class-customize-classes.php' );
// $customize_plus::register_custom_types( array(
// 'controls' => array(
// 'kkcpt_layout_columns' => 'KKcpt_Customize_Control_Layout_Columns',
// )
// ) );
}
/**
* Get customize tree
*
* @since 0.0.1
* @return array
*/
public static function get_customize_tree() {
$customize_tree = (array) require( get_stylesheet_directory() . '/options-demo.php' );
// $customize_tree_premium = (array) require( get_stylesheet_directory() . '/options-demo-premium.php' );
// return array_merge( $customize_tree_premium, $customize_tree );
return $customize_tree;
}
/**
* Add contact details to Customize screen (info component)
* @note this works only with Customize Plus Premium
*
* @since 0.0.1
*/
public static function add_contacts_to_customize () {
?>
<h3><?php esc_html_e( 'Contact and Social' ); ?></h3>
<p><?php esc_html_e( 'Website' ); ?>: <b><a href="https://knitkode.com" target="_blank">knitkode.com</a></b><br>
<?php esc_html_e( 'Mail' ); ?>: <b><a href="mailto:[email protected]" title="Contact the author" target="_blank">[email protected]</a></b></p>
<?php
}
/**
* Remove default WordPress panel/sections
*
* check here: http://wordpress.stackexchange.com/a/161110/25398
*
* @since 0.0.1
* @param {WP_Customize_Manager} $wp_customize Theme Customizer object
*/
public static function remove_wp_defaults( $wp_customize ) {
// $wp_customize->remove_panel( 'nav_menus' );
// $wp_customize->remove_panel( 'widgets' );
// $wp_customize->remove_section( 'colors' );
// $wp_customize->remove_section( 'static_front_page' );
// $wp_customize->remove_section( 'title_tagline' );
// $wp_customize->remove_section( 'background_image' );
// $wp_customize->remove_section( 'header_image' );
// $wp_customize->remove_control( 'background_color' );
// $wp_customize->remove_control( 'header_textcolor' );
}
/**
* Enqueue css in the admin page of the customize
*
* @since 0.0.1
*/
public static function customize_enqueue_css() {
wp_enqueue_style( self::PREFIX . '-customize', get_template_directory_uri() . '/styles/customize.css', self::VERSION, false );
}
/**
* Enqueue js in the admin page of the customize
*
* @since 0.0.1
*/
public static function customize_enqueue_js() {
wp_enqueue_script( self::PREFIX . '-customize', get_template_directory_uri() . '/scripts/customize.js', array( 'kkcp-customize' ), self::VERSION, false );
}
/**
* Enqueue js in the theme preview of the customize
*
* @since 0.0.1
*/
public static function customize_enqueue_js_preview() {
wp_enqueue_script( self::PREFIX . '-customize', get_template_directory_uri() . '/scripts/customize-preview.js', array( 'kkcp-customize-preview' ), self::VERSION, true );
}
/**
* Safe `get_theme_mod` with default fallback
*
* This is just to show an alternative to the function
* `kk_get_theme_mod( $opt_name )` available globally, they work the same
*
* @since 0.0.1
* @param string $opt_name
* @return ?
*/
public static function get_theme_mod( $opt_name ) {
if ( isset( self::$settings_defaults[ $opt_name ] ) ) {
return get_theme_mod( $opt_name, self::$settings_defaults[ $opt_name ] );
} else {
return get_theme_mod( $opt_name );
}
}
/**
* Safe `get_option` with default fallback
*
* This is just to show an alternative to the function
* `kk_get_option( $opt_name )` available globally, they work the same
*
* @since 0.0.1
* @param string $opt_name
* @return ?
*/
public static function get_option( $opt_name ) {
$full_id = self::PREFIX . '[' . $opt_name . ']';
$option_array = get_option( self::PREFIX );
if ( $option_array && isset( $option_array[ $opt_name ] ) ) {
return $option_array[ $opt_name ];
} else if ( isset( self::$settings_defaults[ $full_id ] ) ) {
return self::$settings_defaults[ $full_id ];
} else {
return null; // @@tocheck \\
}
}
/**
* Enqueue default style.css and bootstrap files required only for this demo
*
* @since 0.0.1
*/
public static function enqueue_manager() {
wp_enqueue_script( self::PREFIX . '-bootstrap', get_template_directory_uri() . '/scripts/bootstrap.js', array( 'jquery' ) );
wp_enqueue_style( self::PREFIX . '-bootstrap', get_template_directory_uri() . '/styles/bootstrap.css' );
wp_enqueue_style( self::PREFIX . '-theme', get_template_directory_uri() . '/style.css', array(), self::VERSION );
}
}
new Customize_Plus_Demo;