-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknot.php
More file actions
78 lines (46 loc) · 1.45 KB
/
knot.php
File metadata and controls
78 lines (46 loc) · 1.45 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
<?php
namespace Sef;
/**
*
/*
Plugin Name: Knot
Version: 0.0
Author: Sef
*/
/* main plugin file */
define('KNOT_FILE', (__FILE__));
define('KNOT_PATH', dirname((__FILE__)));
class Knot {
const VERSION = '0.0.0';
const AJAX_ACTION = 'knot';
public function __construct(){
add_action( 'plugins_loaded', array( $this, 'init' ));
// listen for requests
add_action( 'wp_ajax_' . self::AJAX_ACTION, array( $this, 'listener' ));
add_action( 'wp_ajax_nopriv_' . self::AJAX_ACTION, array( $this, 'listener' ));
$this->init();
}
public function init() {
require_once ( KNOT_PATH . '/autoload.php');
spl_autoload_register('sef_knot_autoloader');
}
public function listener() {
// get PAYLOAD
$request = file_get_contents('php://input');
$data = json_decode($request);
if( ! $data->handler || ! $data->method )
wp_send_json_error('missing parameter');
$classname = __NAMESPACE__ . '\\Knot\\Handler\\' . $data->handler;
$response = new Knot\Component\ClientResponse($data);
$handler = new $classname();
$handler->setClientResponse($response);
$handler->read();
wp_send_json_success($handler->getResponse());
}
}
new Knot();
add_action( 'init', function(){
$handler = new Knot\Handler\Post();
// echo '<pre>'; print_r($handler->getName()); echo '</pre>';
// echo '<pre>'; print_r($handler->getFields()); echo '</pre>';
});