-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathajax.php
More file actions
57 lines (46 loc) · 1.35 KB
/
ajax.php
File metadata and controls
57 lines (46 loc) · 1.35 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
<?php
/**
* Enqueue the calendar AJAX javascript
*/
function cgit_events_scripts_init()
{
wp_enqueue_script('cgit-events-calendar', plugins_url('/js/calendar.js', __FILE__));
/**
* Define the AJAX handler
*/
wp_localize_script(
'cgit-events-calendar',
'ajax_object',
array(
'ajax_url' => admin_url('admin-ajax.php')
)
);
}
add_action('wp_enqueue_scripts', 'cgit_events_scripts_init');
/**
* AJAX handler function
*/
function cgit_events_calendar_callback()
{
if (isset($_POST['year']) && isset($_POST['month'])) {
$year = (int)$_POST['year'];
$month = (int)$_POST['month'];
// Prevent infinite indexing of calendar pages by restricting display
// to fifteen year in the past/future
if ($year > date('Y') + 15 || $year < date('Y') - 15) {
$year = date('Y');
}
$calendar = new Cgit_event_calendar(
$year,
$month
);
$calendar->full = (bool) ($_POST['full'] ?? false);
echo $calendar->getAjax();
}
wp_die();
}
/**
* Filter must be applied to front end requests only, privileged and non privileged users
*/
add_action('wp_ajax_cgit_events_calendar', 'cgit_events_calendar_callback');
add_action('wp_ajax_nopriv_cgit_events_calendar', 'cgit_events_calendar_callback');