My WordPress plugin has to make some changes in a file when I get a POST command and after some time revert the changes. I’m struggling in making the timer work. I am trying to use the EvTimer class. Any ideas how to make it work?
EDIT: It looks it doesn’t find Ev Class and that is why it is not working. Is there a way to install/use the PECL extension/EV class if I don’t have access to apache/php? Or maybe there’s a way to use some different function instead of EvTimer to achieve the same functionality? Ty!
add_action( 'wp_loaded', function() {
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
do_action('onchangeapi', new PostListener($_POST));
}
} );
class PostListener {
private $valid = false;
private $pathToFile = "somefile.txt";
private $orgCode = "someCode";
private $noChangeColor = "#AAAAAA";
private $noChangeGradient = "#BBBBBB";
private $changeColor = "#123123";
private $changeGradient = "#345345";
public function __construct(array $postdata) {
$this->valid = $this->validatePostData($postdata);
if ($this->valid) {
//changes some things in file
$this->findAndReplace($this->pathToFile, $this->orgCode, $this- >changeColor, $this->changeGradient);
//reverts it after some seconds.
new EvTimer(15, 0, $this->findAndReplace($this->pathToFile, $this- >orgCode, $this->noChangeColor, $this->noChangeGradient));
}
}
private function findAndReplace($file, $code, $changeToColor, $changeToGradient) {
//makes some changes in file
}
private function validatePostData(array $postdata) {
//validates the postData
}
}