在主题的function.php文件中获取Json APi插件变量

时间:2019-01-03 09:29:44

标签: php wordpress plugins themes

我创建了一个以端点account_activate命名的API。我有一个价值 在请求中,键为flink,我只想在 function.php是儿童主题,我使用了SESSION,GLOBAL概念,但 无法在function.php中获得此值

API名称为account_activate

此API的基本功能是在注册后发送电子邮件 应用程式。应用程序用户将通过电子邮件激活其帐户。激活后 用户单击登录链接后,应用程序用户将重定向到应用程序。

public function account_activate() {

     global $wpdb, $json_api, $wp_hasher;

     $request_method=$_SERVER["REQUEST_METHOD"];

     if($request_method=='POST')
      {

       $data = json_decode(file_get_contents('php://input'), true); 

       $email = trim($data['email']);
       $activation_link = trim($data['link']);
        $firebase_link = trim($data['flink']);

       if(!$email)
       {
          $json_api->error("You must include 'email' var in your request. ",'401'); 
       }

       if(!$activation_link)
       {
          $json_api->error("You must include 'link' var in your request. ",'401'); 
       }

        if(!$firebase_link)
       {
          $json_api->error("You must include 'flink' var in your request. ",'401'); 
       } 

if (!session_id()) {
                session_start();
            }
        $_SESSION['flink'] = $firebase_link;

        $activatelink = '<a href= "'.$activation_link.'">Activate Yor Account</a><br>';

        $message = __('Thanks for registering!') . "<br><br>";

        //$message .= network_home_url() . "<br><br>";

        //$message .= sprintf(__('Username: %s'), $user_data->display_name) . "<br><br>";

        $message .= __('To complete the activation of your account, go to the following link:') . "<br><br>";

        //$message .= __('To reset your password, visit the following address:') . "<br><br>";

        $message .= $activatelink;

        if (is_multisite())
            $blogname = $GLOBALS['current_site']->site_name;
        else
            $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);


        $title = sprintf(__('[%s] Activate your account'), $blogname);

        $title = apply_filters('retrieve_password_title', $title);

        if (!wp_mail ($email,$title,$message)) 

            $json_api->error("The e-mail could not be sent. Possible reason: your host may have disabled the mail() function.",'401');
        else
            return array( "msg" => 'Link for activate your account has been emailed to you. Please check your email.');
      }
     else
        {
          $json_api->error('In-Correct Request Method.','401');   
        }


 }

MY function.php

    function redirectToApp()
{
    if(bp_account_was_activated())
    {
        if(wp_is_mobile())
        {
            if (!session_id()) {
                session_start();
            }
             $firebase_link =  $_SESSION['flink'];
            echo 'Your account was activated successfully! You can now <a href=" '.$firebase_link.' ">log in</a> with the username and password you provided when you signed up.' ;
        }
    }
}



add_action( 'bp_before_activate_content', 'redirectToApp' );

问题:我只想从插件到主题的function.php中获取$ firebase_link变量的值。

0 个答案:

没有答案