-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
294 lines (247 loc) · 9.72 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
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Registers theme supported feature.
*
* @return void
*/
function actcourse_after_setup_theme() {
add_theme_support( 'title-tag' );
add_theme_support( 'custom-logo', array(
'height' => 36,
'flex-height' => true,
'flex-width' => true,
'unlink-homepage-logo' => true,
) );
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'actcourse_after_setup_theme' );
/**
* Include theme assets.
*
* @return void
*/
function actcourse_include_assets() {
// Include bootstrap css.
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/vendor/bootstrap/css/bootstrap.min.css', array(), '1.0' );
wp_enqueue_style( 'bootstrap-icons', get_template_directory_uri() . '/assets/vendor/bootstrap-icons/bootstrap-icons.css', array(), '1.0' );
wp_enqueue_style( 'aos-style', get_template_directory_uri() . '/assets/vendor/aos/aos.css', array(), '1.0' );
wp_enqueue_style( 'glightbox-style', get_template_directory_uri() . '/assets/vendor/glightbox/css/glightbox.min.css', array(), '1.0' );
wp_enqueue_style( 'swiper-style', get_template_directory_uri() . '/assets/vendor/swiper/swiper-bundle.min.css', array(), '1.0' );
wp_enqueue_style( 'main-style', get_template_directory_uri() . '/assets/css/main.css', array(), '1.2' );
wp_enqueue_style( 'theme-style', get_stylesheet_uri(), array(), '1.2' );
// Include JS files.
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/vendor/bootstrap/js/bootstrap.bundle.min.js', array(), '1.0', true );
wp_enqueue_script( 'aos', get_template_directory_uri() . '/assets/vendor/aos/aos.js', array(), '1.0', true );
wp_enqueue_script( 'glightbox', get_template_directory_uri() . '/assets/vendor/glightbox/js/glightbox.min.js', array(), '1.0', true );
wp_enqueue_script( 'purecounter_vanilla', get_template_directory_uri() . '/assets/vendor/purecounter/purecounter_vanilla.js', array(), '1.0', true );
wp_enqueue_script( 'swiper', get_template_directory_uri() . '/assets/vendor/swiper/swiper-bundle.min.js', array(), '1.0', true );
wp_enqueue_script( 'imagesloaded', get_template_directory_uri() . '/assets/vendor/imagesloaded/imagesloaded.pkgd.min.js', array(), '1.0', true );
wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/vendor/isotope-layout/isotope.pkgd.min.js', array(), '1.0', true );
wp_enqueue_script( 'main', get_template_directory_uri() . '/assets/js/main.js', array(), '1.0', true );
wp_enqueue_script( 'theme-functions', get_template_directory_uri() . '/assets/js/theme-functions.js', array( 'jquery' ), filemtime( get_template_directory() . '/assets/js/theme-functions.js' ), true );
wp_localize_script( 'theme-functions', 'act_data', array(
'act_ajax_url' => admin_url( 'admin-ajax.php' ),
'posts_per_page' => 8, // Todo: Add theme option.
'texts' => array(
'loading' => __( 'Loading', 'actcourse' ),
'loadmore' => __( 'Load More', 'actcourse' ),
'nomoreservices' => __( 'No more services', 'actcourse' ),
),
) );
}
add_action( 'wp_enqueue_scripts', 'actcourse_include_assets' );
/**
* Register menus.
*
* @return void
*/
function actcourse_menu_register() {
register_nav_menu( 'actcourse-header', __( 'Header menu', 'actcourse' ) );
}
add_action( 'init', 'actcourse_menu_register' );
/**
* Register service post type.
*
* @return void
*/
function actcourse_create_services_post_type() {
$labels = array(
'name' => __( 'Services', 'actcourse' ),
'singular_name' => __( 'Service', 'sima-law' ),
'add_new' => __( 'Add New', 'sima-law' ),
'add_new_item' => __( 'Add New Service', 'sima-law' ),
'edit_item' => __( 'Edit Service', 'sima-law' ),
'new_item' => __( 'New Service', 'sima-law' ),
'view_item' => __( 'View Service', 'sima-law' ),
'search_items' => __( 'Search Services', 'sima-law' ),
'not_found' => __( 'No services found.', 'sima-law' ),
'not_found_in_trash' => __( 'No services found in Trash.', 'sima-law' ),
'all_items' => __( 'All Services', 'sima-law' ),
'menu_name' => __( 'Services', 'sima-law' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'services' ),
'supports' => array( 'title', 'editor', 'thumbnail' ),
//'show_in_rest' => true,
);
register_post_type( 'service', $args );
}
add_action( 'init', 'actcourse_create_services_post_type', 10 );
/**
* Register service taxonomies.
*/
function actcourse_register_taxonomy() {
$args = array(
'label' => __( 'Services type', 'actcourse' ),
'public' => true,
'hierarchical' => true,
);
register_taxonomy( 'service_type', 'service', $args );
}
add_action( 'init', 'actcourse_register_taxonomy' );
/**
* Register sidebars.
*
* @return void
*/
function actcourse_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Sidebar', 'actcourse' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_sidebar' => '<div class="col-lg-4" data-aos="fade-up" data-aos-delay="100">',
'after_sidebar' => '</div>',
) );
register_sidebar( array(
'name' => __( 'Services Sidebar', 'actcourse' ),
'id' => 'services-side',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_sidebar' => '<div class="col-lg-4" data-aos="fade-up" data-aos-delay="100">',
'after_sidebar' => '</div>',
) );
}
add_action( 'widgets_init', 'actcourse_widgets_init' );
/**
* Modify excerpt length.
*
* @param int $length Excerpt length.
*
* @return int
*/
function actcourse_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'actcourse_excerpt_length' );
/**
* Register meta box for post.
*/
function actcourse_register_meta_box() {
$screen = array(
'service',
);
add_meta_box( 'service_custom_data', esc_html__( 'Service Data', 'actcourse' ), 'actcourse_service_data_box', $screen );
}
add_action( 'add_meta_boxes', 'actcourse_register_meta_box' );
function actcourse_service_data_box() {
global $post;
$service_price = get_post_meta( $post->ID, 'actcourse_service_price', true );
?>
<label for="service_price"><?php echo esc_html__( 'Price:', 'actcourse' );?></label>
<input type="number" name="service_price" id="service_price" value="<?php echo $service_price ? intval( $service_price ) : 0 ;?>">
<?php
}
function actcourse_save_service_data( $post_id ) {
if ( array_key_exists( 'service_price', $_POST ) ) {
update_post_meta( $post_id, 'actcourse_service_price', sanitize_text_field( $_POST['service_price'] ) );
}
}
add_action( 'save_post', 'actcourse_save_service_data' );
/**
* Service data.
*/
function actcourse_get_service_data( int $service_id ) {
$service_meta = get_post_meta( $service_id );
return array(
'price' => $service_meta['actcourse_service_price'][0] ?? '',
'features' => $service_meta['actcourse_service_features'] ?? array(),
);
}
/**
* Get services pagination
*/
function actcourse_get_services_pagination() {
$pagination_type ='load_more'; // ToDO: Add theme option for pagination type;
if ( 'pagination' === $pagination_type ) {
the_posts_pagination(
array(
'before_page_number' => '<span class="page-number">',
'after_page_number' => '</span>',
)
);
}
if ( 'load_more' === $pagination_type ) {
echo '<button id="load-more" data-paged="1">' . esc_html__( 'Load more', 'actcourse' ) . '</button>';
}
}
function actcourse_load_more_services() {
$service_query = new WP_Query(
array(
'post_type' => 'service',
'post_status' => 'publish',
'posts_per_page' => $_POST['posts_per_page'],
'paged' => $_POST['page'],
)
);
if ( $service_query->have_posts() ) : while ( $service_query->have_posts() ) : $service_query->the_post();
get_template_part( 'template-parts/services/service-content' );
endwhile;
else:
return '';
endif;
wp_reset_postdata();
wp_die();
}
add_action( 'wp_ajax_actcourse_load_more_services', 'actcourse_load_more_services' );
add_action( 'wp_ajax_nopriv_actcourse_load_more_services', 'actcourse_load_more_services' );
/**
* Send contact us emails.
*
* @return void
*/
function actcourse_contact_us_send_email() {
if ( ! isset( $_POST['contact_nonce'] ) || ! wp_verify_nonce( $_POST['contact_nonce'], 'actcourse_contact_form' ) ) {
wp_send_json_error( 'Invalid nonce' );
wp_die();
}
parse_str( $_POST['form_data'], $contact_data );
$name = sanitize_text_field( $contact_data['name'] );
$email = sanitize_email( $contact_data['email'] );
$subject = sanitize_text_field( $contact_data['subject'] );
$message = sanitize_text_field( $contact_data['message'] );
if ( empty( $name ) || empty( $email ) || empty( $message ) || empty( $subject ) ) {
wp_send_json_error( 'All fields are required' );
}
$to = get_option( 'admin_email' );
$headers[] = 'From: '.$name.' <'.$email.'>';
if ( wp_mail( $to, $subject, $message, $headers ) ) {
wp_send_json_success( __( 'Your message has been sent.', 'actcourse' ) );
} else {
wp_send_json_error( 'Failed to send your message!' );
}
wp_die();
}
add_action( 'wp_ajax_actcourse_contact_us_send_email', 'actcourse_contact_us_send_email' );
add_action( 'wp_ajax_nopriv_actcourse_contact_us_send_email', 'actcourse_contact_us_send_email' );
/**
* Includes required files.
*/
require_once get_template_directory() . '/includes/theme-options.php';
require_once get_template_directory() . '/includes/theme-settings.php';