PluginProbe
WANotifier for Forms and Actions / 2.1.3
WANotifier for Forms and Actions v2.1.3
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.1.3, at includes/class-notifier.php

295 lines 7.9 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.1.3' );
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 // Functions
62 require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-helpers.php';
63 require_once NOTIFIER_PATH . 'includes/functions/functions-notifier-meta-box-fields.php';
64
65 // Classes
66 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-admin-notices.php';
67 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-dashboard.php';
68 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-merge-tags.php';
69 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-notification-triggers.php';
70 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-settings.php';
71 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-frontend.php';
72 }
73
74 /**
75 * Hook into actions and filters.
76 */
77 private function init_hooks() {
78 register_activation_hook ( NOTIFIER_FILE, array( $this, 'install') );
79
80 add_action( 'after_setup_theme', array( 'Notifier_Admin_Notices', 'init' ) );
81 add_action( 'after_setup_theme', array( 'Notifier_Dashboard', 'init' ) );
82 add_action( 'after_setup_theme', array( 'Notifier_Notification_Merge_Tags', 'init' ) );
83 add_action( 'after_setup_theme', array( 'Notifier_Notification_Triggers', 'init' ) );
84 add_action( 'after_setup_theme', array( 'Notifier_Settings', 'init' ) );
85 add_action( 'after_setup_theme', array( 'Notifier_Frontend', 'init' ) );
86 add_action( 'admin_enqueue_scripts', array( $this , 'admin_scripts') );
87 add_action( 'wp_enqueue_scripts', array( $this , 'frontend_scripts') );
88 add_action( 'in_admin_header', array( $this , 'embed_page_header' ) );
89
90 add_action( 'after_setup_theme', array( $this, 'maybe_include_integrations' ) );
91 }
92
93 /**
94 * Setup during plugin activation
95 */
96 public function install() {
97
98 }
99
100 /**
101 * Check if plugin's page
102 */
103 public static function is_notifier_page() {
104 $current_screen = get_current_screen();
105 if ( strpos($current_screen->id, NOTIFIER_NAME) !== false) {
106 return true;
107 }
108
109 return false;
110 }
111
112 /**
113 * Add admin scripts and styles
114 */
115 public function admin_scripts () {
116 if (!self::is_notifier_page()) {
117 return;
118 }
119
120 // Select2
121 wp_enqueue_script(
122 NOTIFIER_NAME . '-select2-js',
123 NOTIFIER_URL . 'assets/js/select2.min.js',
124 array('jquery'),
125 NOTIFIER_VERSION,
126 true
127 );
128
129 // Admin JS file
130 wp_enqueue_script(
131 NOTIFIER_NAME . '-admin-js',
132 NOTIFIER_URL . 'assets/js/admin.js',
133 array('jquery'),
134 NOTIFIER_VERSION,
135 true
136 );
137 wp_localize_script(
138 NOTIFIER_NAME . '-admin-js',
139 'notifierObj',
140 apply_filters( 'notifier_js_variables', array('ajaxurl' => admin_url( 'admin-ajax.php' ) ) )
141 );
142
143 // Styles
144 wp_enqueue_style(
145 NOTIFIER_NAME . '-admin-css',
146 NOTIFIER_URL . 'assets/css/admin.css',
147 null,
148 NOTIFIER_VERSION
149 );
150 }
151
152 /**
153 * Add frontend scripts and styles
154 */
155 public function frontend_scripts () {
156 if('yes' === get_option('notifier_ctc_enable')){
157 // Styles
158 wp_enqueue_style(
159 NOTIFIER_NAME . '-frontend-css',
160 NOTIFIER_URL . 'assets/css/frontend.css',
161 null,
162 NOTIFIER_VERSION
163 );
164 }
165 }
166
167 /**
168 * Set up a div for the header embed to render into.
169 * The initial contents here are meant as a place loader for when the PHP page initialy loads.
170 */
171 public static function embed_page_header() {
172 if (!self::is_notifier_page()) {
173 return;
174 }
175 $current_screen = get_current_screen();
176 $cpt = ( '' !== $current_screen->post_type) ? $current_screen->post_type : '';
177 $tax = ( '' !== $current_screen->taxonomy) ? $current_screen->taxonomy : '';
178 ?>
179 <div id="notifier-admin-header" data-post-type="<?php echo esc_attr($cpt); ?>">
180 <div class="notifier-admin-header-content">
181 <div class="header-page-title w-30">
182 <h2><?php echo esc_attr(get_admin_page_title()); ?></h2>
183 </div>
184 <div class="header-action-links w-30 d-flex justify-content-end">
185 <span class="header-version">Version: <?php echo esc_html(NOTIFIER_VERSION); ?></span>
186 <a href="https://wanotifier.com/support/" target="_blank">Help</a>
187 </div>
188 </div>
189 </div>
190 <?php
191 }
192
193 /**
194 * For sending API requests
195 */
196 public static function send_api_request ( $endpoint, $args, $method = 'POST', $headers = array() ) {
197 $api_key = get_option('notifier_api_key');
198 $api_key = trim($api_key);
199 if('' == $api_key) {
200 return false;
201 }
202
203 if(empty($headers)){
204 $headers = array(
205 'Content-Type' => 'application/json; charset=utf-8'
206 );
207 }
208
209 $request_url = NOTIFIER_APP_API_URL . $endpoint . '?key=' . $api_key;
210 $request_args = array(
211 'method' => $method,
212 'headers' => $headers,
213 'timeout' => 120,
214 'body' => json_encode($args),
215 'sslverify' => false
216 );
217
218 $response = wp_remote_request( $request_url, $request_args);
219
220 $response_body = wp_remote_retrieve_body( $response );
221
222 if ( is_wp_error( $response ) ) {
223 error_log( $response->get_error_message() );
224 return false;
225 } else {
226 $response_body = wp_remote_retrieve_body( $response );
227 return json_decode($response_body);
228 }
229 }
230
231 /**
232 * Load Woocommerce class if it's present is activated
233 */
234 public static function maybe_include_integrations () {
235 // Woocommerce
236 if ( class_exists( 'WooCommerce' ) ) {
237 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-woocommerce.php';
238 Notifier_Woocommerce::init();
239 }
240 if ( ! class_exists( 'WC_Session' ) ) {
241 include_once( WP_PLUGIN_DIR . '/woocommerce/includes/abstracts/abstract-wc-session.php' );
242 }
243
244 // Gravity Forms
245 if ( class_exists( 'GFCommon' ) ) {
246 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-gravityforms.php';
247 Notifier_GravityForms::init();
248 }
249
250 // Contact Form 7
251 if ( class_exists( 'WPCF7' ) ) {
252 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-cf7.php';
253 Notifier_ContactForm7::init();
254 }
255
256 // WPForms
257 if ( class_exists( 'WPForms' ) ) {
258 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-wpforms.php';
259 Notifier_WPForms::init();
260 }
261
262 // Ninja Forms
263 if ( class_exists( 'Ninja_Forms' ) ) {
264 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-ninjaforms.php';
265 Notifier_NinjaForms::init();
266 }
267
268 //FrmForm
269 if ( class_exists( 'FrmForm' ) ) {
270 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-formidable.php';
271 Notifier_Formidable::init();
272 }
273
274 //WPFluentForm
275 if ( function_exists( 'fluentFormApi' ) ) {
276 require_once NOTIFIER_PATH . 'includes/classes/class-notifier-fluentforms.php';
277 Notifier_FluentForms::init();
278 }
279 }
280
281 /**
282 * Is connection to WANotifier.com active?
283 */
284 public static function is_api_active () {
285 $activated = get_option(NOTIFIER_PREFIX . 'api_activated');
286 if('yes' == $activated) {
287 return true;
288 }
289 else{
290 return false;
291 }
292 }
293
294 }
295