This repository was archived by the owner on Mar 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfunctions.php
More file actions
328 lines (261 loc) · 12.5 KB
/
functions.php
File metadata and controls
328 lines (261 loc) · 12.5 KB
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
<?php
$vendor_file = trailingslashit( get_template_directory() ) . 'vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
require_once $vendor_file;
}
add_filter( 'themeisle_sdk_products', 'flatx_load_sdk' );
/**
* Loads products array.
*
* @param array $products All products.
*
* @return array Products array.
*/
function flatx_load_sdk( $products ) {
$products[] = get_template_directory() . '/style.css';
return $products;
}
/**
* Flat initiation
*
* Initializes Flat's features and includes all necessary files.
*
* @package Flat
*/
# Prevent direct access to this file
if ( 1 == count( get_included_files() ) ) {
header( 'HTTP/1.1 403 Forbidden' );
die( 'Direct access of this file is prohibited. Thank you.' );
}
/**
* File inclusions
*/
require get_template_directory() . '/inc/customize.php'; # Enables user customization via admin panel
require get_template_directory() . '/inc/hooks.php'; # Enables user customization via WordPress plugin API
require get_template_directory() . '/inc/template-tags.php'; # Contains functions that output HTML
if (!class_exists( 'Flat_Plus' )) {
require_once( get_template_directory() . '/inc/customizer-info/class/class-singleton-customizer-info-section.php' );
}
/**
* Set the max width for embedded content
*
* @link http://codex.wordpress.org/Content_Width
*/
if ( ! isset( $content_width ) ) {
$content_width = 720;
}
if ( ! function_exists( 'flat_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
function flat_setup() {
# Localization
load_theme_textdomain( 'flat', get_template_directory() . '/languages' );
# Enable WordPress theme features
add_theme_support( 'automatic-feed-links' ); # @link http://codex.wordpress.org/Automatic_Feed_Links
$custom_background_support = array(
'default-color' => '',
'default-image' => get_template_directory_uri() . '/assets/img/default-background.jpg',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
/* tgm-plugin-activation */
require_once get_template_directory() . '/class-tgm-plugin-activation.php';
add_theme_support( 'custom-background', $custom_background_support ); # @link http://codex.wordpress.org/Custom_Backgrounds
add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'quote', 'status' ) ); # @link http://codex.wordpress.org/Post%20Formats
add_theme_support( 'post-thumbnails' ); # @link http://codex.wordpress.org/Post%20Thumbnails
add_theme_support( 'structured-post-formats', array( 'link', 'video' ) );
add_theme_support( 'title-tag' ); # @link http://codex.wordpress.org/Title_Tag
add_theme_support( 'tha-hooks', array( 'all' ) ); # @link https://github.com/zamoose/themehookalliance
# Add style to the post editor for a more WYSIWYG experience
add_editor_style( array( 'assets/css/editor-style.css' ) );
# Flat has one navigation menu; register it with WordPress
register_nav_menu( 'primary', __( 'Navigation Menu', 'flat' ) );
# Add filters
add_filter(
'comments_popup_link_attributes', function() {
return ' itemprop="discussionUrl"';
}
); # schema.org property on comments links
add_filter( 'current_theme_supports-tha_hooks', '__return_true' ); # Enables checking for THA hooks
add_filter( 'style_loader_tag', 'flat_filter_styles', 10, 2 ); # Filters style tags as needed
add_filter( 'the_content_more_link', 'flat_modify_read_more_link' ); # Enhances appearance of "Read more..." link
add_filter( 'use_default_gallery_style', '__return_false' ); # Disable default WordPress gallery styling
remove_filter( 'the_content','cwp_pac_before_content' );
# Add actions
add_action( 'flat_html_before', 'flat_doctype' ); # Outputs HTML doctype
add_action( 'flat_404_content', 'flat_output_404_content' ); # Outputs a helpful message on 404 pages
add_action( 'widgets_init', 'flat_widgets_init' ); # Registers Flat's sidebar
add_action( 'wp_enqueue_scripts', 'flat_scripts_styles' ); # Enqueue's Flat's scripts & styles
add_action( 'admin_enqueue_scripts', 'flat_admin_styles', 10 );
}
endif;
add_action( 'after_setup_theme', 'flat_setup' );
// unregister all widgets
function flat_remove_review_widgets() {
unregister_widget( 'cwp_latest_products_widget' );
unregister_widget( 'cwp_top_products_widget' );
}
add_action( 'widgets_init', 'flat_remove_review_widgets', 11 );
if ( ! function_exists( 'flat_widgets_init' ) ) :
/**
* Registers our sidebar with WordPress
*/
function flat_widgets_init() {
register_sidebar(
array(
'name' => __( 'Main Widget Area', 'flat' ),
'id' => 'sidebar-1',
'description' => __( 'Appears in the sidebar section of the site', 'flat' ),
'before_widget' => "\t\t\t\t\t" . '<aside id="%1$s" class="widget %2$s">' . "\n",
'after_widget' => "\t\t\t\t\t</aside>\n",
'before_title' => "\t\t\t\t\t\t<h3 class='widget-title'>",
'after_title' => "</h3>\n",
)
);
}
endif;
if ( ! function_exists( 'flat_scripts_styles' ) ) :
/**
* Sets up necessary scripts and styles
*/
function flat_scripts_styles() {
global $wp_version;
# Get the current version of Flat, even if a child theme is being used
$version = wp_get_theme( wp_get_theme()->template )->get( 'Version' );
# When needed, enqueue comment-reply script
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
# Minified versions of CSS & JS are used, unless a development constant is set
if ( defined( 'WP_ENV' ) && 'development' === WP_ENV ) {
$assets = array(
'css' => '/assets/css/flat.css',
'js' => '/assets/js/flat.js',
);
} else {
$assets = array(
'css' => '/assets/css/flat.min.css',
'js' => '/assets/js/flat.min.js',
);
}
wp_enqueue_style( 'flat-fonts', flat_fonts_url(), array(), null ); # Web fonts
wp_enqueue_style( 'flat-theme', get_template_directory_uri() . $assets['css'], array(), $version ); # Flat's styling
wp_enqueue_script( 'flat-js', get_template_directory_uri() . $assets['js'], array( 'jquery' ), $version, false ); # Flat's scripting
wp_enqueue_style( 'flat-style', get_stylesheet_uri() ); # Load main stylesheet, for child theme supports
if (class_exists( 'Flat_Plus' )) {
$flat_plus_sidebar_position = get_theme_mod( 'flat_plus_sidebar_position' );
$inline_style = '';
if ( !empty( $flat_plus_sidebar_position ) && $flat_plus_sidebar_position === 'right' ) {
$inline_style .= '@media (max-width: 1199px) { ' .
'#secondary .toggle-sidebar{ ' .
'float:right; border-width: 0 0 0 1px; } ' .
'#secondary .toggle-navigation { ' .
'float:left; border-width: 0 1px 0 0;} ' .
'.row-offcanvas-left.active {' .
'left: auto; right: 300px;}' .
'.row-offcanvas-left .sidebar-offcanvas {' .
'right: -300px; left: auto; }' .
'}';
}
wp_add_inline_style( 'flat-style', $inline_style );
}
# If the `script_loader_tag` filter is unavailable, this script will be added via the `wp_head` hook
if ( version_compare( '4.1', $wp_version, '<=' ) ) {
wp_enqueue_script( 'html5shiv', get_template_directory_uri() . '/assets/js/html5shiv.min.js', array(), '3.7.2', false );
}
}
endif;
function flat_admin_styles() {
wp_enqueue_style( 'flat_admin_stylesheet', get_template_directory_uri() . '/assets/css/admin-style.css', array(), '1.1', false );
}
# The following function uses a filter introduced in WP 4.1
if ( version_compare( '4.1', $wp_version, '<=' ) ) :
if ( ! function_exists( 'flat_filter_scripts' ) ) :
/**
* Filters enqueued script output to better suit Flat's needs
*/
function flat_filter_scripts( $tag, $handle, $src ) {
# Remove `type` attribute (unneeded in HTML5)
$tag = str_replace( ' type=\'text/javascript\'', '', $tag );
# Apply conditionals to html5shiv for legacy IE
if ( 'html5shiv' === $handle ) {
$tag = "<!--[if lt IE 9]>\n$tag<![endif]-->\n";
}
return $tag;
}
endif;
add_filter( 'script_loader_tag', 'flat_filter_scripts', 10, 3 );
else : # If the `script_loader_tag` filter is unavailable...
/**
* Adds html5shiv the "old" way (WP < 4.1)
*/
function flat_add_html5shiv() {
echo "<!--[if lt IE 9]>\n<scr" . 'ipt src="' . esc_url( get_template_directory_uri() ) . '/assets/js/html5shiv.min.js"></scr' . "ipt>\n<![endif]-->"; # This is a hack to disguise adding the script without using WordPress' enqueue function
}
add_action( 'wp_head', 'flat_add_html5shiv' );
endif;
if ( ! function_exists( 'flat_filter_styles' ) ) :
/**
* Filter enqueued style output to better suit HTML5
*/
function flat_filter_styles( $tag, $handle ) {
# Get rid of unnecessary `type` attribute
$tag = str_replace( ' type=\'text/css\'', '', $tag );
# Get rid of double-spaces
$tag = str_replace( ' ', ' ', $tag );
return $tag;
}
endif;
add_action( 'tgmpa_register', 'flat_register_required_plugins' );
function flat_register_required_plugins() {
$plugins = array(
array(
'name' => 'WP Product Review',
'slug' => 'wp-product-review',
'required' => false,
),
array(
'name' => 'Orbit Fox',
'slug' => 'themeisle-companion',
'required' => false,
),
);
$config = array(
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => false,
'message' => '',
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'flat' ),
'menu_title' => __( 'Install Plugins', 'flat' ),
'installing' => __( 'Installing Plugin: %s', 'flat' ),
'oops' => __( 'Something went wrong with the plugin API.', 'flat' ),
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.','flat' ),
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.','flat' ),
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.','flat' ),
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.','flat' ),
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.','flat' ),
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.','flat' ),
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.','flat' ),
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.','flat' ),
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins','flat' ),
'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins','flat' ),
'return' => __( 'Return to Required Plugins Installer', 'flat' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'flat' ),
'complete' => __( 'All plugins installed and activated successfully. %s', 'flat' ),
'nag_type' => 'updated',
),
);
tgmpa( $plugins, $config );
}
/**
* Enhances "Read more..." links with Bootstrap button styling
*/
function flat_modify_read_more_link() {
return '<a class="btn btn-default btn-sm" href="' . esc_url( get_permalink() ) . '">' . sprintf( __( 'Continue reading %s', 'flat' ), '<i class="fa fa-angle-double-right"></i></a>' );
}