adekherry

class.jnews-push-notification-widget.php

Sep 5th, 2018
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. <?php
  2. /**
  3. * @author : Jegtheme
  4. */
  5.  
  6. if ( ! defined( 'ABSPATH' ) )
  7. {
  8. exit;
  9. }
  10.  
  11. Class JNews_Push_Notification_Widget extends WP_Widget
  12. {
  13. /**
  14. * @var JNews_Push_Notification
  15. */
  16. private $push_notification_instance;
  17.  
  18. /**
  19. * Register widget with WordPress.
  20. */
  21. public function __construct()
  22. {
  23. parent::__construct (
  24. 'jnews_push_notification', // Base ID
  25. esc_html__('Push Notification', 'jnews'), // Name
  26. array(
  27. 'description' => esc_html__('Push Notification for JNews', 'jnews'),
  28. 'customize_selective_refresh' => true
  29. ), // Args
  30. null
  31. );
  32. }
  33.  
  34. public function form($instance)
  35. {
  36. $options = array (
  37. 'title' => array(
  38. 'title' => esc_html__('Title', 'jnews-push-notification'),
  39. 'desc' => esc_html__('Title on widget header.', 'jnews-push-notification'),
  40. 'type' => 'text'
  41. ),
  42. 'description' => array(
  43. 'title' => esc_html__('Subscribe Description', 'jnews-push-notification'),
  44. 'desc' => esc_html__('You may use standard HTML tags and attributes for subscribe description.', 'jnews-push-notification'),
  45. 'type' => 'textarea'
  46. ),
  47. 'btn_subscribe' => array(
  48. 'title' => esc_html__('Subscribe Button Text', 'jnews-push-notification'),
  49. 'desc' => esc_html__('Insert text for subscribe button.', 'jnews-push-notification'),
  50. 'type' => 'text',
  51. ),
  52. 'btn_unsubscribe' => array(
  53. 'title' => esc_html__('Unsubscribe Button Text', 'jnews-push-notification'),
  54. 'desc' => esc_html__('Insert text for unsubscribe button.', 'jnews-push-notification'),
  55. 'type' => 'text',
  56. ),
  57. 'btn_processing' => array(
  58. 'title' => esc_html__('Processing Button Text', 'jnews-push-notification'),
  59. 'desc' => esc_html__('Insert text for processing button.', 'jnews-push-notification'),
  60. 'type' => 'text'
  61. ),
  62. );
  63.  
  64. $generator = new \JNews\Widget\WidgetGenerator($this);
  65. $generator->render_form($options, $instance);
  66. }
  67.  
  68. /**
  69. * Init widget
  70. *
  71. * @param array $args
  72. * @param array $instance
  73. *
  74. */
  75. public function widget( $args, $instance )
  76. {
  77. $title = apply_filters( 'widget_title', isset($instance['title']) ? $instance['title'] : "" );
  78.  
  79. echo $args['before_widget'];
  80.  
  81. if ( ! empty( $title ) )
  82. {
  83. echo $args['before_title'] . wp_kses( $title, wp_kses_allowed_html() ) . $args['after_title'];
  84. }
  85.  
  86. $this->render_content( $instance );
  87.  
  88. echo $args['after_widget'];
  89. }
  90.  
  91. /**
  92. * Render widget content
  93. *
  94. * @param array $instance
  95. *
  96. */
  97. public function render_content( $instance )
  98. {
  99. if ( empty( $instance['btn_subscribe'] ) )
  100. {
  101. $instance['btn_subscribe'] = jnews_return_translation( 'Subscribe', 'jnews-push-notification', 'push_notification_subscribe' );
  102. }
  103.  
  104. if ( empty( $instance['btn_unsubscribe'] ) )
  105. {
  106. $instance['btn_unsubscribe'] = jnews_return_translation( 'Unsubscribe', 'jnews-push-notification', 'push_notification_unsubscribe' );
  107. }
  108.  
  109. if ( empty( $instance['btn_processing'] ) )
  110. {
  111. $instance['btn_processing'] = jnews_return_translation( 'Processing . . .', 'jnews-push-notification', 'push_notification_processing' );
  112. }
  113.  
  114. $description = isset( $instance['description'] ) ? $instance['description'] : '';
  115.  
  116. $output = "<div class=\"jeg_push_notification loading\">
  117. <div class=\"jeg_push_notification_content\">
  118. <p>" . str_replace( PHP_EOL, "<br>", $description ) . "</p>
  119. <div class=\"jeg_push_notification_button\">
  120. <input type=\"hidden\" name=\"button-subscribe\" value=\"{$instance['btn_subscribe']}\">
  121. <input type=\"hidden\" name=\"button-unsubscribe\" value=\"{$instance['btn_unsubscribe']}\">
  122. <input type=\"hidden\" name=\"button-processing\" value=\"{$instance['btn_processing']}\">
  123. <a data-action=\"subscribe\" class=\"button\" data-type=\"general\" href=\"#\">
  124. <i class=\"fa fa-bell-o\"></i>
  125. {$instance['btn_subscribe']}
  126. </a>
  127. </div>
  128. </div>
  129. </div>";
  130.  
  131. if ( ! class_exists('OneSignal_Admin') )
  132. {
  133. $output =
  134. "<div class=\"alert alert-error\">
  135. <strong>" . esc_html__('Plugin Install','jnews') . "</strong>" . ' : ' . esc_html__('Subscribe Push Notification need OneSignal plugin to be installed', 'jnews') .
  136. "</div>";
  137. }
  138.  
  139. echo $output;
  140. }
  141. }
Add Comment
Please, Sign In to add comment