Wordpress插件WP_error

时间:2015-09-06 04:21:17

标签: wordpress plugins

我在我的wordpress中安装了ISMS插件,以便通过Wordpress尝试短信服务。但是,当我单击插件菜单上的iSMS设置时出现错误。

这是错误: ** 致命错误:不能在第17行的C:\ wamp \ www \ wordpress \ wp-content \ plugins \ isms \ isms-model.php中使用WP_Error类型的对象**

这里是第17行的代码:

$result = $response[body];

这是isms-model.php的完整代码

<?php

   class Mobiweb_ISMS_Model {
   // iSMS API
    protected static $api_balance = 'https://www.isms.com.my/isms_balance.php';
    protected static $api_send = 'https://www.isms.com.my/isms_send.php';

public static function get_balance() {
   $username = get_option('setting_username');
   $password = get_option('setting_password');

   $link = self::$api_balance.'?';
   $link .= "un=".urlencode($username);
   $link .= "&pwd=".urlencode($password);

   $response = wp_remote_get($link);
   $result = $response[body];
   $balance = (float)$result;

   if ($balance < 0) return substr($result, 8);
   else return $result;


   }

   public static function send_isms($destination, $message, $messageType, $senderID = '') {
   $username = get_option('setting_username');
   $password = get_option('setting_password');

   $link = self::$api_send.'?';
   $link .= "un=".urlencode($username);
   $link .= "&pwd=".urlencode($password);
   $link .= "&dstno=".urlencode($destination);
   $link .= "&msg=".urlencode($message);
   $link .= "&type=".urlencode($messageType);
   $link .= "&sendid=".urlencode($senderID);

   $response = wp_remote_get($link);
   try {
       $result = $response[body];

       $resultValue = (float)$result;
       if ($resultValue < 0) {
           return array(
               'code'=>$resultValue,
               'message'=>substr($result, 8)
           );
       } else {
           return array(
               'code'=>'2000',
               'message'=>$result
           );
       }
   } catch (Exception $e) {
       $message = $e->getMessage();
       return array(
           'code'=>'-9999',
           'message'=>$message
       );
   }
  }
 }

?>

我应该怎么做才能修复它?有什么建议吗?

1 个答案:

答案 0 :(得分:2)

这个插件编写得很糟糕。

当出现错误时,

wp_remote_get()会返回WP_Error个对象。因此,至少为了调试它并查看错误是什么,我建议你改为:

'func': 'application.utilities.views:job1'

$response = wp_remote_get($link);
$result = $response[body];