wp_schedule_single_event无法成功运行

时间:2019-08-17 12:34:58

标签: php android wordpress

我为Wordpress网站编写了一个Android应用程序。我想要一个像电报这样的登录系统。因此,我在服务器端创建了一个php文件,该文件获得了电话号码表单应用程序。

如果数据库中存在具有该电话号码的用户,请创建随机代码,并将其作为发布元添加到数据库中并将其发送给用户。现在我想在5分钟后删除帖子元。所以我用了“ wp_schedule_single_event”。但这行不通。我该如何解决?

我的代码是:

<?php

/* 
get phone from app
cheack phone is exist or not 
if is exist : create random code and send to app 
if not exist create user after that create random code  and send to app 
if get error send to app text "error" 
*/
require_once("../wp-load.php");
require_once("../wp-cron.php");
require_once("../wp-includes/cron.php");
require_once("class.aesCrypt.php");
$tellenc = $_POST['tell'];

$randomcode=generateRandomString();
$postmetavalue="";


$tellenc="xDdW6n3pqbxqELXLsuLleg==";

//decrypt tell
$encryption = new MCrypt();
$tell= $encryption->decrypt($tellenc);


//create meta post key=tell ,value=random code
update_post_meta( 1, $tell, $randomcode );
$user_id = username_exists( $tell );
//if exist user: send to app isexist+random code
if ( $user_id ) {

   echo "true{".$randomcode;

   wp_schedule_single_event( time() + 60, 'my_new_event' );

 }//end if user is exist
 // if user is not exist: send to app isnotexist+random code
 else {

      echo "false{".$randomcode;
     //register user as customer 

 }
 // echo  $output.= "notExist";

 // function genrate random code
 function generateRandomString($length = 4) {
        $characters = '0123456789';
        $charactersLength = strlen($characters);
        $randomString = '';
       for ($i = 0; $i < $length; $i++) {
             $randomString .= $characters[rand(0, $charactersLength - 1)];
       }
       return $randomString;
  }

  function do_this_in_an_hour() {

        update_post_meta( 1, 'mytest', 'tesstziroq' );
  }
  add_action( 'my_new_event','do_this_in_an_hour' );

 ?>

0 个答案:

没有答案