-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
162 lines (135 loc) · 3.6 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
<?php
/**
* Functions and definitions
*
* @package Qoe
*/
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct script access denied.' );
}
define( 'QOE_VERSION', '1.0.4' );
define( 'QOE_DIR', rtrim( get_template_directory(), '/' ) );
define( 'QOE_URL', rtrim( get_template_directory_uri(), '/' ) );
// Load autoload.
if ( file_exists( QOE_DIR . '/vendor/autoload.php' ) ) {
require_once QOE_DIR . '/vendor/autoload.php';
}
/**
* Theme setup.
*
* @since 1.0.0
*/
function qoe_setup() {
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Enable support for Post Thumbnails.
add_theme_support( 'post-thumbnails' );
// Admin editor styles.
add_theme_support( 'editor-styles' );
// Switch default core markup for different forms to output valid HTML5.
add_theme_support( 'html5', array( 'comment-form', 'comment-list' ) );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Enable block styles.
add_theme_support( 'wp-block-styles' );
// Enqueue editor styles.
add_editor_style();
}
add_action( 'after_setup_theme', 'qoe_setup' );
/**
* Enqueue scripts and styles.
*
* @since 1.0.0
*/
function qoe_scripts() {
wp_enqueue_style( 'qoe-style', get_stylesheet_uri(), array(), QOE_VERSION );
wp_style_add_data( 'qoe-style', 'rtl', 'replace' );
wp_enqueue_script( 'qoe-frontend', QOE_URL . '/assets/js/frontend.js', array(), QOE_VERSION, true );
}
add_action( 'wp_enqueue_scripts', 'qoe_scripts' );
/**
* Register block patterns category.
*
* @since 1.0.0
*/
function qoe_register_block_patterns_category() {
register_block_pattern_category(
'qoe',
array(
'label' => esc_html__( 'Qoe', 'qoe' ),
)
);
}
add_action( 'init', 'qoe_register_block_patterns_category', 9 );
/**
* Register block styles.
*
* @since 1.0.0
*/
function qoe_register_block_styles() {
$block_styles = array(
'core/list' => array(
'square' => esc_html__( 'Square', 'qoe' ),
'none' => esc_html__( 'None', 'qoe' ),
),
'core/separator' => array(
'dotted' => esc_html__( 'Dotted', 'qoe' ),
'wide-thin-line' => esc_html__( 'Wide Thin Line', 'qoe' ),
'left-aligned' => esc_html__( 'Left Aligned', 'qoe' ),
'right-aligned' => esc_html__( 'Right Aligned', 'qoe' ),
),
);
foreach ( $block_styles as $block => $styles ) {
foreach ( $styles as $style_name => $style_label ) {
register_block_style(
$block,
array(
'name' => $style_name,
'label' => $style_label,
)
);
}
}
}
add_action( 'init', 'qoe_register_block_styles' );
/**
* Add back to top.
*
* @since 1.0.0
*/
function qoe_add_back_to_top() {
echo '<div id="back-to-top">↑</div>';
}
add_action( 'wp_footer', 'qoe_add_back_to_top' );
// WooCommerce customizations.
if ( class_exists( 'WooCommerce', false ) ) {
require_once QOE_DIR . '/inc/woocommerce.php';
}
/**
* Add admin notice.
*
* @since 1.0.0
*/
function qoe_add_admin_notice() {
\Nilambar\AdminNotice\Notice::init(
array(
'slug' => 'qoe',
'type' => 'theme',
'name' => esc_html__( 'Qoe', 'qoe' ),
)
);
}
add_action( 'admin_init', 'qoe_add_admin_notice' );
/**
* Add Buy Me a Coffee on admin notice.
*
* @since 1.0.0
*/
function qoe_add_donate_link() {
echo '<span style="font-weight: bold;"><a href="https://ko-fi.com/maneshtimilsina" target="_blank">Buy Me a Coffee</a></span>';
}
add_action( 'qoe_after_admin_notice_link_items', 'qoe_add_donate_link' );