Skip to content

Commit 43932df

Browse files
committed
Update
1 parent 38a734f commit 43932df

2 files changed

Lines changed: 142 additions & 148 deletions

File tree

src/AbstractAsyncRequest.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
* @link : https://jakiboy.github.io/VanillePluginTask/
88
* @license : MIT
99
*
10-
* This file if a part of VanillePluginTask Framework
10+
* This file if a part of VanillePluginTask
11+
* Cloned from deliciousbrains/wp-background-processing
1112
*/
1213

1314
namespace VanillePluginTask;
1415

15-
use VanillePlugin\lib\PluginOptions;
16+
use VanillePlugin\int\PluginNameSpaceInterface;
17+
use VanillePlugin\lib\Db;
1618
use VanillePlugin\lib\Request;
1719
use VanillePlugin\inc\Stringify;
1820
use VanillePlugin\inc\Server;
1921

20-
abstract class AbstractAsyncRequest extends PluginOptions
22+
abstract class AbstractAsyncRequest extends Db
2123
{
2224
/**
2325
* @access protected
@@ -30,13 +32,14 @@ abstract class AbstractAsyncRequest extends PluginOptions
3032
protected $data = [];
3133

3234
/**
33-
* Initiate new async request
35+
* Init new async request
3436
*
3537
* @param void
3638
*/
3739
public function __construct()
3840
{
39-
$this->id = "{$this->getNameSpace()}-{$this->action}";
41+
$this->init();
42+
$this->id = $this->action;
4043
$this->addAction("wp_ajax_{$this->id}", [$this,'maybeHandle']);
4144
$this->addAction("wp_ajax_nopriv_{$this->id}", [$this,'maybeHandle']);
4245
}
@@ -67,6 +70,23 @@ public function dispatch()
6770
return $res->getBody();
6871
}
6972

73+
/**
74+
* Check for correct nonce and pass to handler
75+
*
76+
* @param void
77+
* @return void
78+
*/
79+
public function maybeHandle()
80+
{
81+
// Prevent other requests while processing
82+
$this->closeSession();
83+
// Security
84+
$this->checkAjaxReferer($this->id,'nonce');
85+
// Handle request
86+
$this->handle();
87+
die();
88+
}
89+
7090
/**
7191
* Get request query args
7292
*
@@ -120,25 +140,6 @@ protected function getPostArgs()
120140
];
121141
}
122142

123-
/**
124-
* Check for correct nonce and pass to handler
125-
*
126-
* @param void
127-
* @return void
128-
*/
129-
public function maybeHandle()
130-
{
131-
// Prevent other requests while processing
132-
$this->closeSession();
133-
134-
// Security
135-
$this->checkAjaxReferer($this->id,'nonce');
136-
137-
// Handle request
138-
$this->handle();
139-
die();
140-
}
141-
142143
/**
143144
* Handle request
144145
*

0 commit comments

Comments
 (0)