-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
368 lines (327 loc) · 9.29 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
/**
* Various definitions of global variables.
*
* Framework files and functions are hooked here.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Codexin
* @subpackage Core
* @since 1.0
*/
// Do not allow directly accessing this file.
defined( 'ABSPATH' ) OR die( esc_html__( 'This script cannot be accessed directly.', 'TEXT_DOMAIN' ) );
// Declaring constant for Theme Options
define( 'CODEXIN_THEME_OPTIONS', 'codexin_get_option' );
/**
* Codexin Themes Framework. Definition of main framework core class.
*
* @since 1.0
*/
if( ! class_exists( 'Codexin_Framework' ) ) {
/**
* Main class for the Codexin Themes Framework
*
* @since v1.0.0
*/
class Codexin_Framework {
/**
* Call all loading functions for the theme. They will be started right after theme setup.
*
* @since v1.0.0
*/
public function __construct() {
// Loading the theme framework files
$this -> codexin_includes();
// Run after installation setup.
$this -> codexin_setup();
// Register actions
$this -> codexin_actions();
// Loading admin related actions
$this -> codexin_admin_actions();
}
/**
* Loading the theme framework files. Register custom elements
* and functionality in the theme.
*
* @since v1.0.0
*/
public function codexin_includes() {
/**
* Registering Navigation Menus
*
*/
require_once trailingslashit( get_template_directory() ) . 'inc/lib/menus.php';
/**
* Register widgets locations
*
*/
require_once trailingslashit( get_template_directory() ) . 'inc/lib/widget-locations.php';
/**
* Adding the function to enqueue styles and javascripts
*
*/
require trailingslashit( get_template_directory() ) . 'inc/lib/scripts.php';
/**
* Adding the customizer
*
*/
require_once trailingslashit( get_template_directory() ) . 'inc/admin/customizer-init.php';
/**
* Include required plugins to run framework
*
*/
require trailingslashit( get_template_directory() ) . 'inc/admin/required-plugins.php';
/**
* Adding the function to show breadcrumbs
*
*/
require_once trailingslashit( get_template_directory() ) . 'inc/frontend/breadcrumbs.php';
/**
* Adding the helper functions
*
*/
require_once trailingslashit( get_template_directory() ) . 'inc/frontend/helpers.php';
/**
* Adding the functions for various paginations
*
*/
require_once trailingslashit( get_template_directory() ) . 'inc/frontend/paginations.php';
}
/**
* Initial Theme Setup
* @uses add_action()
* @since v1.0.0
*/
public function codexin_setup() {
/**
* Add after_setup_theme() for specific functions.
* The action call is here, because it fits more just for the theme
* setup, instead for all other actions during using of Subtle.
*/
add_action( 'after_setup_theme', array( $this, 'codexin_setup_core' ) );
/**
* Set content width for custom media information
*
*/
if( ! isset( $content_width ) ) {
$content_width = 1140;
}
}
/**
* The core functionality that has to be registred after the theme is setted up
*
* @since v1.0.0
*/
public function codexin_setup_core() {
/**
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on TEXT_DOMAIN, use a find and replace
* to change 'TEXT_DOMAIN' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'TEXT_DOMAIN', trailingslashit( get_template_directory() ) . 'languages' );
/**
* Add default posts and comments RSS feed links to head.
*
*/
add_theme_support( 'automatic-feed-links' );
/**
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/**
* Add support for post formats.
*
*/
add_theme_support( 'post-formats',
array(
'gallery',
'audio',
'video',
'quote',
'link',
)
);
/**
* Enable support for Post Thumbnails on posts and pages.
*
*/
add_theme_support( 'post-thumbnails' );
/**
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/**
* Enable support for adding custom image sizes
*
*/
if( function_exists( 'add_image_size' ) ) {
add_image_size('codexin-fr-rect-one', 600, 375, true);
add_image_size('codexin-fr-rect-two', 800, 354, true);
add_image_size('codexin-fr-rect-three', 1170, 400, true);
add_image_size('codexin-fr-rect-four', 800, 450, true);
}
/**
* Adding custom header support to the theme
*
*/
$theme_args = array(
'default-image' => '',
'default-text-color' => 'ee3733',
'width' => 1280,
'height' => 150,
'flex-height' => true,
'wp-head-callback' => 'codexin_header_style',
);
add_theme_support( 'custom-header', $theme_args );
/**
* Adding custom background support to the theme
*
*/
add_theme_support( 'custom-background' );
/**
* Adding custom logo support to the theme
*
*/
$logo_args = array(
'width' => 250,
'height' => 60,
'flex-width' => true,
'flex-height' => true
);
add_theme_support( 'custom-logo', $logo_args );
/**
* Partial refresh support in the Customize
*
*/
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Declaring woocommerce support
*
*/
add_action( 'after_setup_theme', 'codexin_woocommerce_support' );
function codexin_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
}
/**
* Add actions and filters in Codexin themes framework. All the actions will be hooked here.
*
* @since v1.0.0
*/
public function codexin_actions() {
/**
* Providing Shortcode Support on text widget
*
* @uses add_filter()
* @since v1.0.0
*/
add_filter( 'widget_text', 'do_shortcode' );
/**
* Removing srcset from featured image
*
* @uses add_filter()
* @since v1.0
*/
add_filter( 'max_srcset_image_width', function() { return 1; } );
/**
* Removing width & height from featured image
*
* @param string $html
* @param integer $post_id
* @param integer $post_image_id
* @return mixed
* @uses add_filter()
* @since v1.0
*/
add_filter( 'post_thumbnail_html', 'codexin_remove_thumbnail_dimensions', 10, 3 );
if( ! function_exists( 'codexin_remove_thumbnail_dimensions' ) ) {
function codexin_remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
}
/**
* Apply theme's stylesheet to the visual editor.
*
* @uses add_action()
* @uses add_editor_style() Links a stylesheet to visual editor
* @since v1.0
*/
add_action( 'admin_init', 'codexin_editor_styles' );
if( ! function_exists( 'codexin_editor_styles' ) ) {
function codexin_editor_styles() {
add_editor_style( 'assets/css/admin/editor-style.css' );
}
}
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*
* @uses add_action()
* @since v1.0
*/
add_action( 'wp_head', 'codexin_pingback_header' );
if( ! function_exists( 'codexin_pingback_header' ) ) {
function codexin_pingback_header() {
if( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
}
}
}
/**
* Adding woocommerce compitability to theme structure
*
* @uses add_action()
* @uses remove_action()
* @since v1.0
*/
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', 'codexin_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'codexin_wrapper_end', 10);
function codexin_wrapper_start() {
echo '<div class="container">';
}
function codexin_wrapper_end() {
echo '</div>';
}
}
/**
* Registering admin tasks
*
* @uses add_action()
* @since v1.0.0
*/
public function codexin_admin_actions() {
add_action( 'admin_enqueue_scripts', array( $this, 'codexin_post_formats_script' ), 10, 1 );
}
/**
* Enqueque admin scripts for post formats
*
* @uses wp_enqueue_script()
* @since v1.0
*/
public function codexin_post_formats_script( $hook ) {
global $post;
if( $hook == 'post-new.php' || $hook == 'post.php' ) {
if( 'post' === $post->post_type ) {
wp_enqueue_script( 'codexin-post-formats', trailingslashit( get_template_directory_uri() ) . 'assets/js/admin/post-format.js' );
}
}
}
}
}
// Instantiating framework
$framework_init = new Codexin_Framework;