/
action.php
44 lines (37 loc) · 1.33 KB
/
action.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
<?php
session_start();
if (empty($_REQUEST['action']) || empty($_REQUEST['_wpnonce'])) {
$_SESSION['message'] = 'Invalid request!';
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
}
/**
* Load wordpress
*/
require_once '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'wp-config.php';
/**
* Load theme base
*/
require_once rtrim(get_template_directory(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'rockharbor_theme_base.php';
$class = 'RockharborThemeBase';
$file = rtrim(get_stylesheet_directory(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'child_theme.php';
if (file_exists($file)) {
require_once $file;
$class = 'ChildTheme';
}
$theme = new $class;
$theme->init();
// verify nonce
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'action-nonce')) {
$_SESSION['message'] = 'Invalid request!';
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
}
// if an action is POSTed to the site, the action will be called here
if (method_exists($theme, $_REQUEST['action']) && in_array($_REQUEST['action'], $theme->allowedActions)) {
$result = call_user_func(array($theme, $_REQUEST['action']));
if (!empty($theme->messages)) {
$_SESSION['message'] = implode(', ', $theme->messages);
}
}
header('Location: '.$_SERVER['HTTP_REFERER']);