示例#1
0
文件: HubLogger.php 项目: dannyoz/tls
 /**
  * Method to log Error Messages
  *
  * @param      $msg
  * @param null $code
  *
  * @return mixed
  */
 public static function error($msg, $code = null)
 {
     $current_options = get_option(TlsHubSubscriberWP::get_option_name());
     //        if (isset($current_options['error_messages_switch']) && $current_options['log_messages_switch'] != 1) {
     //            return;
     //        }
     $errorMessage = self::logs_date_time() . $msg . "\n";
     if ($code != null) {
         $errorMessage = self::logs_date_time() . $msg . " (Code: " . $code . ")" . "\n";
     }
     $errorMessage .= "--------------\n";
     $current_options['error_messages'] = $current_options['error_messages'] . $errorMessage;
     update_option(TlsHubSubscriberWP::get_option_name(), $current_options);
 }
示例#2
0
<?php

/*
Template Name: Hub Pos Test
*/
$options = get_option(\Tls\TlsHubSubscriber\TlsHubSubscriberWP::get_option_name());
$guzzleClient = new \GuzzleHttp\Client();
// Start empty $hubUrl variable
$hubUrl = '';
$callbackUrl = site_url() . '/pushfeed/' . $options['subscription_id'];
// Check if the Hub URL finishes with a / or not to be able to create the correct subscribe URL
if (preg_match("/\\/\$/", $options['hub_url'])) {
    $hubUrl = $options['hub_url'];
} else {
    $hubUrl = $options['hub_url'];
}
// Json Data needed to send to the Hub for Subscription
$subscribeJson = json_encode(array("callbackUrl" => esc_url($callbackUrl), "topicId" => esc_url($options['topic_url'])), JSON_UNESCAPED_SLASHES);
$subscribeRequest = $guzzleClient->createRequest('POST', $hubUrl);
$subscribeRequest->setHeader('Content-Type', 'application/json');
$subscribeRequest->setBody(\GuzzleHttp\Stream\Stream::factory($subscribeJson));
$subscribeResponse = $guzzleClient->send($subscribeRequest);