Advertisement
rohollah7

What`s Bug or Error in Php7 ???

Oct 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.92 KB | None | 0 0
  1. <?php
  2.  
  3. namespace WP_SMS\Pro;
  4.  
  5. use WP_SMS\Option;
  6.  
  7. if ( ! defined( 'ABSPATH' ) ) {
  8.     exit;
  9. } // Exit if accessed directly
  10.  
  11.  
  12. class AwesomeSupport {
  13.  
  14.     public $sms;
  15.     public $options;
  16.     public $main_options;
  17.  
  18.     public function __construct() {
  19.         global $sms;
  20.  
  21.         $this->sms          = $sms;
  22.         $this->options      = Option::getOptions(true);
  23.         $this->main_options = Option::getOptions();
  24.  
  25.         // Check new ticket option
  26.         if ( isset( $this->options['as_notify_open_ticket_status'] ) and $this->options['as_notify_open_ticket_status'] ) {
  27.             add_action( 'wpas_open_ticket_before', array( $this, 'notify_new_ticket' ) );
  28.         }
  29.  
  30.         // Check admin reply ticket option
  31.         if ( isset( $this->options['as_notify_admin_reply_ticket_status'] ) and $this->options['as_notify_admin_reply_ticket_status'] ) {
  32.             add_action( 'wpas_add_reply_public_after', array( $this, 'notify_admin_reply' ) );
  33.         }
  34.  
  35.         // Check user reply ticket
  36.         if ( isset( $this->options['as_notify_user_reply_ticket_status'] ) and $this->options['as_notify_user_reply_ticket_status'] ) {
  37.             add_action( 'wpas_add_reply_admin_after', array( $this, 'notify_user_reply' ) );
  38.         }
  39.     }
  40.  
  41.     /**
  42.      * Notify new ticket
  43.      *
  44.      * @param $data
  45.      * @param $post_id
  46.      * @param $incoming_data
  47.      */
  48.     public function notify_new_ticket( $data, $post_id, $incoming_data ) {
  49.         // Check admin mobile number
  50.         if ( empty( $this->main_options['admin_mobile_number'] ) ) {
  51.             return;
  52.         }
  53.  
  54.         $user     = get_userdata( $data['post_author'] );
  55.         $username = isset( $user->user_login ) ? $user->user_login : '';
  56.  
  57.         $template_vars = array(
  58.             '%ticket_content%'  => $data['post_content'],
  59.             '%ticket_title%'    => $data['post_title'],
  60.             '%ticket_username%' => $username,
  61.         );
  62.         $message       = str_replace( array_keys( $template_vars ), array_values( $template_vars ), $this->options['as_notify_open_ticket_message'] );
  63.  
  64.         // Send SMS
  65.         $this->sms->to  = array( $this->main_options['admin_mobile_number'] );
  66.         $this->sms->msg = $message;
  67.         $this->sms->SendSMS();
  68.     }
  69.  
  70.     /**
  71.      * Notify admin reply ticket
  72.      *
  73.      * @param $reply_id
  74.      * @param $data
  75.      */
  76.     public function notify_admin_reply( $reply_id, $data ) {
  77.         // Check admin mobile number
  78.         if ( empty( $this->main_options['admin_mobile_number'] ) ) {
  79.             return;
  80.         }
  81.  
  82.         $post        = get_post( $reply_id );
  83.         $post_parent = get_post( $post->post_parent );
  84.         $user        = get_userdata( $post->post_author );
  85.         $username    = isset( $user->user_login ) ? $user->user_login : '';
  86.  
  87.         $template_vars = array(
  88.             '%reply_content%'  => $post->post_content,
  89.             '%reply_title%'    => $post_parent->post_title,
  90.             '%reply_username%' => $username,
  91.         );
  92.         $message       = str_replace( array_keys( $template_vars ), array_values( $template_vars ), $this->options['as_notify_admin_reply_ticket_message'] );
  93.  
  94.         // Send SMS
  95.         $this->sms->to  = array( $this->main_options['admin_mobile_number'] );
  96.         $this->sms->msg = $message;
  97.         $this->sms->SendSMS();
  98.     }
  99.  
  100.     /**
  101.      * Notify user reply ticket
  102.      *
  103.      * @param $reply_id
  104.      * @param $data
  105.      */
  106.     public function notify_user_reply( $reply_id, $data ) {
  107.         $post        = get_post( $reply_id );
  108.         $post_parent = get_post( $post->post_parent );
  109.  
  110.         // Get user mobile
  111.         $user_mobile = get_user_meta( $post_parent->post_author, 'mobile', true );
  112.  
  113.         // Check user mobile number
  114.         if ( ! $user_mobile ) {
  115.             return;
  116.         }
  117.  
  118.         $user     = get_userdata( $post->post_author );
  119.         $username = isset( $user->user_login ) ? $user->user_login : '';
  120.  
  121.         $template_vars = array(
  122.             '%reply_content%'  => $post->post_content,
  123.             '%reply_title%'    => $post_parent->post_title,
  124.             '%reply_username%' => $username,
  125.         );
  126.         $message       = str_replace( array_keys( $template_vars ), array_values( $template_vars ), $this->options['as_notify_user_reply_ticket_message'] );
  127.  
  128.         // Send SMS
  129.         $this->sms->to  = array( $user_mobile );
  130.         $this->sms->msg = $message;
  131.         $this->sms->SendSMS();
  132.     }
  133. }
  134.  
  135. new AwesomeSupport();
  136. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement