forked from hrsetyono/edje-wp-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
132 lines (106 loc) · 4.11 KB
/
Copy pathfunctions.php
File metadata and controls
132 lines (106 loc) · 4.11 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
<?php
require_once __DIR__ . '/_lib/helpers.php';
// Abort if required plugins is inactive
if (!Helper::has_required_plugins()) { return; }
$THEME = wp_get_theme();
define('MY_VERSION', $THEME->get('Version'));
define('MY_NAMESPACE', 'my/v1');
define('MY_DIST', get_stylesheet_directory_uri() . '/_dist');
define('MY_IMAGES', get_stylesheet_directory_uri() . '/images');
require_once __DIR__ . '/modules/modules.php';
require_once __DIR__ . '/gutenberg/gutenberg.php';
if (class_exists('WooCommerce')) {
require_once __DIR__ . '/woocommerce/_shop-functions.php';
}
// Initial setup
my_before_setup_theme();
add_action('after_setup_theme', 'my_after_setup_theme');
add_action('wp_enqueue_scripts', 'my_enqueue_public_assets', 99);
add_action('admin_enqueue_scripts', 'my_enqueue_admin_assets', 100);
add_action('enqueue_block_editor_assets', 'my_enqueue_editor_assets', 1000);
/////
/**
* Function that run first
*/
function my_before_setup_theme() {
// Do something
}
/**
* Setup theme supports
*
* @action after_setup_theme
*/
function my_after_setup_theme() {
add_theme_support('post-thumbnails');
add_theme_support('menus');
add_theme_support('custom-logo');
add_theme_support('title-tag');
add_theme_support('html5', [
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'navigation-widgets', 'style', 'script'
]);
add_post_type_support('page', 'excerpt'); // allow page to have excerpt
// Pixel Library Support
add_theme_support('px-megamenu');
add_theme_support('px-faq-block');
add_theme_support('px-icon-block', 'v6'); // v6-regular, v6-light, v6-duotone
add_theme_support('px-tabs-block');
add_theme_support('h-comment-editor'); // Enable this if you allow comment in the website
// Gutenberg support
add_theme_support('responsive-embeds');
remove_theme_support('core-block-patterns');
// Nav
register_nav_menu('main-menu', 'Main Menu');
register_nav_menu('footer-menu', 'Footer Menu');
}
// add_action('widgets_init', 'my_widgets_init');
// function my_widgets_init() {
// register_sidebar([
// 'name' => 'Sidebar',
// 'id' => 'sidebar',
// 'description' => 'Appear besides post',
// 'before_widget' => '<div id="%1$s" class="widget %2$s">',
// 'after_widget' => '</div>',
// 'before_title' => '<h3 class="widgettitle">',
// 'after_title' => '</h3>',
// ]);
// }
/**
* Front-end CSS and JS
* @action wp_enqueue_scripts 100
*/
function my_enqueue_public_assets() {
wp_enqueue_style('my-theme', MY_DIST . '/my-theme.css', [], MY_VERSION);
wp_enqueue_script('my-theme', MY_DIST . '/my-theme.js', [], MY_VERSION, true);
wp_enqueue_script('swiper', 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-element-bundle.min.js', [], '11.0.0', true);
// wp_enqueue_script('h-scroll'); // enable if using Animation
// @todo - enable this if you need to use AJAX with PixelFetch.js
// wp_localize_script('my-theme', 'myApiSettings', [
// 'nonce' => wp_create_nonce('wp_rest'),
// 'myUrl' => esc_url_raw(rest_url()) . MY_NAMESPACE,
// 'wpUrl' => esc_url_raw(rest_url()) . 'wp/v2',
// ]);
// Disable gutenberg default styling
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('global-styles');
}
/**
* WP Admin assets
* @action admin_enqueue_scripts 100
*/
function my_enqueue_admin_assets() {
wp_enqueue_script('my-admin', MY_DIST . '/my-admin.js', [], MY_VERSION , true);
wp_enqueue_style('my-admin', MY_DIST . '/my-admin.css', [], MY_VERSION);
// @todo - enable this if you need to use AJAX with PixelFetch.js within admin panel
// wp_localize_script('my-admin', 'myApiSettings', [
// 'nonce' => wp_create_nonce('wp_rest'),
// 'myUrl' => esc_url_raw(rest_url()) . MY_NAMESPACE,
// 'wpUrl' => esc_url_raw(rest_url()) . 'wp/v2',
// ]);
wp_dequeue_style('global-styles-css-custom-properties');
}
function my_enqueue_editor_assets() {
if (!is_admin()) { return; }
wp_enqueue_script('my-editor', MY_DIST . '/my-editor.js', [ 'wp-blocks', 'wp-dom' ] , MY_VERSION, true);
wp_enqueue_style('my-editor', MY_DIST . '/my-editor.css', [ 'wp-edit-blocks' ], MY_VERSION);
}