PluginProbe
WANotifier for Forms and Actions / 2.0.7
WANotifier for Forms and Actions v2.0.7
3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 1.0.3 All 66 releases
notifier / includes / class-notifier.php

class-notifier.php in WANotifier for Forms and Actions 2.0.7, at includes/class-notifier.php

275 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The core plugin class.
4 *
5 * @package Notifier
6 */
7 class Notifier {
8 /**
9 * The single instance of the class.
10 */
11 protected static $_instance = null;
12
13 /**
14 * Notifier Constructor.
15 */
16 public function __construct() {
17 $this->define_constants();
18 $this->includes();
19 $this->init_hooks();
20 }
21
22 /**
23 * Define Constants.
24 */
25 private function define_constants() {
26 $this->define( 'NOTIFIER_VERSION', '2.0.7' );
27 $this->define( 'NOTIFIER_NAME', 'notifier' );
28 $this->define( 'NOTIFIER_PREFIX', 'notifier_' );
29 $this->define( 'NOTIFIER_URL', trailingslashit( plugins_url( '', dirname(__FILE__) ) ) );
30 $this->define( 'NOTIFIER_APP_API_URL', 'https://app.wanotifier.com/api/v1/' );
31 }
32
33 /**
34 * Define constant if not already set.
35 *
36 * @param string $name Constant name.
37 * @param string|bool $value Constant value.
38 */
39 private function define( $name, $value ) {
40 if ( ! defined( $name ) ) {
41 define( $name, $value );
42 }
43 }
44
45 /**
46 * Main Notifier Instance.
47 *
48 * @return Notifier instance.
49 */
50 public static function get_instance() {
51 if ( is_null( self::$_instance ) ) {
52 self::$_instance = new self();
53 }
54 return self::$_instance;
55 }
56
57 /**
58 * Include required core files used in admin and on the frontend.
59 */
60 private function includes() {
61 // Libraries
62 require_once NOTIFIER_PATH . 'libraries/action-scheduler/action-scheduler.php';
63
64 // Functions
65 require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-helpers.php';
66 require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-meta-box-fields.php';
67
68 // Classes
69 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-admin-notices.php';
70 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-dashboard.php';
71 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-merge-tags.php';
72 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-triggers.php';
73 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-settings.php';
74 }
75
76 /**
77 * Hook into actions and filters.
78 */
79 private function init_hooks() {
80 register_activation_hook ( NOTIFIER_FILE, array( $this, 'install') );
81
82 add_action( 'plugins_loaded', array( 'Notifier_Admin_Notices', 'init' ) );
83 add_action( 'plugins_loaded', array( 'Notifier_Dashboard', 'init' ) );
84 add_action( 'plugins_loaded', array( 'Notifier_Notification_Merge_Tags', 'init' ) );
85 add_action( 'plugins_loaded', array( 'Notifier_Notification_Triggers', 'init' ) );
86 add_action( 'plugins_loaded', array( 'Notifier_Settings', 'init' ) );
87
88 add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts') );
89 add_action( 'in_admin_header', array( $this , 'embed_page_header' ) );
90
91 add_action( 'plugins_loaded', array( $this, 'maybe_include_integrations' ) );
92 }
93
94 /**
95 * Setup during plugin activation
96 */
97 public function install() {
98
99 }
100
101 /**
102 * Check if plugin's page
103 */
104 public static function is_notifier_page() {
105 $current_screen = get_current_screen();
106 if ( strpos($current_screen->id, NOTIFIER_NAME) !== false) {
107 return true;
108 }
109
110 return false;
111 }
112
113 /**
114 * Add admin scripts and styles
115 */
116 public function admin_scripts () {
117 if (!self::is_notifier_page()) {
118 return;
119 }
120
121 // Select2
122 wp_enqueue_script(
123 NOTIFIER_NAME . '-select2-js',
124 NOTIFIER_URL . 'assets/js/select2.min.js',
125 array('jquery'),
126 NOTIFIER_VERSION,
127 true
128 );
129
130 // Admin JS file
131 wp_enqueue_script(
132 NOTIFIER_NAME . '-admin-js',
133 NOTIFIER_URL . 'assets/js/admin.js',
134 array('jquery'),
135 NOTIFIER_VERSION,
136 true
137 );
138 wp_localize_script(
139 NOTIFIER_NAME . '-admin-js',
140 'notifierObj',
141 apply_filters( 'notifier_js_variables', array('ajaxurl' => admin_url( 'admin-ajax.php' ) ) )
142 );
143
144 // Styles
145 wp_enqueue_style(
146 NOTIFIER_NAME . '-admin-css',
147 NOTIFIER_URL . 'assets/css/admin.css',
148 null,
149 NOTIFIER_VERSION
150 );
151 }
152
153 /**
154 * Set up a div for the header embed to render into.
155 * The initial contents here are meant as a place loader for when the PHP page initialy loads.
156 */
157 public static function embed_page_header() {
158 if (!self::is_notifier_page()) {
159 return;
160 }
161 $current_screen = get_current_screen();
162 $cpt = ( '' !== $current_screen->post_type) ? $current_screen->post_type : '';
163 $tax = ( '' !== $current_screen->taxonomy) ? $current_screen->taxonomy : '';
164 ?>
165 <div id="notifier-admin-header" data-post-type="<?php echo esc_attr($cpt); ?>">
166 <div class="notifier-admin-header-content">
167 <div class="header-page-title w-30">
168 <h2><?php echo esc_attr(get_admin_page_title()); ?></h2>
169 </div>
170 <div class="header-action-links w-30 d-flex justify-content-end">
171 <span class="header-version">Version: <?php echo esc_html(NOTIFIER_VERSION); ?></span>
172 <a href="https://wanotifier.com/support/" target="_blank">Help</a>
173 </div>
174 </div>
175 </div>
176 <?php
177 }
178
179 /**
180 * For sending API requests
181 */
182 public static function send_api_request ( $endpoint, $args, $method = 'POST', $headers = array() ) {
183 $api_key = get_option('notifier_api_key');
184 $api_key = trim($api_key);
185 if('' == $api_key) {
186 return false;
187 }
188
189 if(empty($headers)){
190 $headers = array(
191 'Content-Type' => 'application/json; charset=utf-8'
192 );
193 }
194
195 $request_url = NOTIFIER_APP_API_URL . $endpoint . '?key=' . $api_key;
196 $request_args = array(
197 'method' => $method,
198 'headers' => $headers,
199 'timeout' => 120,
200 'body' => json_encode($args),
201 'sslverify' => false
202 );
203
204 $response = wp_remote_request( $request_url, $request_args);
205
206 $response_body = wp_remote_retrieve_body( $response );
207
208 if ( is_wp_error( $response ) ) {
209 error_log( $response->get_error_message() );
210 return false;
211 } else {
212 $response_body = wp_remote_retrieve_body( $response );
213 return json_decode($response_body);
214 }
215 }
216
217 /**
218 * Load Woocommerce class if it's present is activated
219 */
220 public static function maybe_include_integrations () {
221 // Woocommerce
222 if ( class_exists( 'WooCommerce' ) ) {
223 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-woocommerce.php';
224 Notifier_Woocommerce::init();
225 }
226 if ( ! class_exists( 'WC_Session' ) ) {
227 include_once( WP_PLUGIN_DIR . '/woocommerce/includes/abstracts/abstract-wc-session.php' );
228 }
229
230 // Gravity Forms
231 if ( class_exists( 'GFCommon' ) ) {
232 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-gravityforms.php';
233 Notifier_GravityForms::init();
234 }
235
236 // Contact Form 7
237 if ( class_exists( 'WPCF7' ) ) {
238 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-cf7.php';
239 Notifier_ContactForm7::init();
240 }
241
242 // WPForms
243 if ( class_exists( 'WPForms' ) ) {
244 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-wpforms.php';
245 Notifier_WPForms::init();
246 }
247
248 // Ninja Forms
249 if ( class_exists( 'Ninja_Forms' ) ) {
250 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-ninjaforms.php';
251 Notifier_NinjaForms::init();
252 }
253
254 //FrmForm
255 if ( class_exists( 'FrmForm' ) ) {
256 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-formidable.php';
257 Notifier_Formidable::init();
258 }
259 }
260
261 /**
262 * Is connection to WANotifier.com active?
263 */
264 public static function is_api_active () {
265 $activated = get_option(NOTIFIER_PREFIX . 'api_activated');
266 if('yes' == $activated) {
267 return true;
268 }
269 else{
270 return false;
271 }
272 }
273
274 }
275