Popups by OptinMonster – Best WordPress Lead Generation Plugin - Version 1.2.1

Version Description

  • Added additional checks during save routines for user capabilities.
Download this release

Release Info

Developer griffinjt
Plugin Icon 128x128 Popups by OptinMonster – Best WordPress Lead Generation Plugin
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.2.0 to 1.2.1

OMAPI/Api.php CHANGED
@@ -164,7 +164,7 @@ class OMAPI_Api {
164
  // If not a 200 status header, send back error.
165
  if ( 200 != $response_code ) {
166
  $type = ! empty( $response_body->type ) ? $response_body->type : 'api-error';
167
- $error = ! empty( $response_body->error ) ? stripslashes( $response_body->message ) : '';
168
  return new WP_Error( $type, sprintf( __( 'The API returned a <strong>%s</strong> response with this message: <strong>%s</strong>', 'optin-monster-api' ), $response_code, $error ) );
169
  }
170
 
164
  // If not a 200 status header, send back error.
165
  if ( 200 != $response_code ) {
166
  $type = ! empty( $response_body->type ) ? $response_body->type : 'api-error';
167
+ $error = ! empty( $response_body->error ) ? stripslashes( $response_body->error ) : '';
168
  return new WP_Error( $type, sprintf( __( 'The API returned a <strong>%s</strong> response with this message: <strong>%s</strong>', 'optin-monster-api' ), $response_code, $error ) );
169
  }
170
 
OMAPI/Output.php CHANGED
@@ -10,1035 +10,1038 @@
10
  class OMAPI_Output {
11
 
12
  /**
13
- * Holds the class object.
14
- *
15
- * @since 1.0.0
16
- *
17
- * @var object
18
- */
19
- public static $instance;
20
 
21
  /**
22
- * Path to the file.
23
- *
24
- * @since 1.0.0
25
- *
26
- * @var string
27
- */
28
- public $file = __FILE__;
29
-
30
- /**
31
- * Holds the base class object.
32
- *
33
- * @since 1.0.0
34
- *
35
- * @var object
36
- */
37
- public $base;
38
-
39
- /**
40
- * Holds the meta fields used for checking output statuses.
41
- *
42
- * @since 1.0.0
43
- *
44
- * @var array
45
- */
46
- public $fields = array(
47
- 'enabled',
48
- 'automatic',
49
- 'users',
50
- 'never',
51
- 'only',
52
- 'categories',
53
- 'taxonomies',
54
- 'show',
55
- 'type',
56
- 'shortcode',
57
- 'shortcode_output',
58
- 'mailpoet',
59
- 'test',
60
- 'show_on_woocommerce',
61
- 'is_wc_shop',
62
- 'is_wc_product',
63
- 'is_wc_cart',
64
- 'is_wc_checkout',
65
- 'is_wc_account',
66
- 'is_wc_endpoint',
67
- 'is_wc_endpoint_order_pay',
68
- 'is_wc_endpoint_order_received',
69
- 'is_wc_endpoint_view_order',
70
- 'is_wc_endpoint_edit_account',
71
- 'is_wc_endpoint_edit_address',
72
- 'is_wc_endpoint_lost_password',
73
- 'is_wc_endpoint_customer_logout',
74
- 'is_wc_endpoint_add_payment_method',
75
- 'is_wc_product_category',
76
- 'is_wc_product_tag',
77
- );
78
-
79
- /**
80
- * Flag for determining if localized JS variable is output.
81
- *
82
- * @since 1.0.0
83
- *
84
- * @var bool
85
- */
86
- public $localized = false;
87
-
88
- /**
89
- * Holds JS slugs for maybe parsing shortcodes.
90
- *
91
- * @since 1.0.0
92
- *
93
- * @var array
94
- */
95
- public $slugs = array();
96
-
97
- /**
98
- * Holds shortcode output.
99
- *
100
- * @since 1.0.0
101
- *
102
- * @var array
103
- */
104
- public $shortcodes = array();
105
-
106
- /**
107
- * Primary class constructor.
108
- *
109
- * @since 1.0.0
110
- */
111
- public function __construct() {
112
-
113
- // Set our object.
114
- $this->set();
115
-
116
- // If no credentials have been provided, do nothing.
117
- if ( ! $this->base->get_api_credentials() ) {
118
- return;
119
- }
120
 
121
  // Load actions and filters.
122
  add_action( 'wp_enqueue_scripts', array( $this, 'api_script' ) );
123
- add_action( 'wp_footer', array( $this, 'localize' ), 9999 );
124
- add_action( 'wp_footer', array( $this, 'maybe_parse_shortcodes' ), 11 );
125
-
126
- // Maybe load OptinMonster.
127
- $this->maybe_load_optinmonster();
128
-
129
- }
130
-
131
- /**
132
- * Sets our object instance and base class instance.
133
- *
134
- * @since 1.0.0
135
- */
136
- public function set() {
137
-
138
- self::$instance = $this;
139
- $this->base = OMAPI::get_instance();
140
- $this->fields = apply_filters( 'optin_monster_api_output_fields', $this->fields );
141
-
142
- }
143
-
144
- /**
145
- * Enqueues the OptinMonster API script.
146
- *
147
- * @since 1.0.0
148
- */
149
- public function api_script() {
150
-
151
- wp_enqueue_script( $this->base->plugin_slug . '-api-script', OPTINMONSTER_API, array( 'jquery' ), $this->base->version );
152
-
153
- if ( version_compare( get_bloginfo( 'version' ), '4.1.0', '>=' ) ) {
154
- add_filter( 'script_loader_tag', array( $this, 'filter_api_script' ), 10, 2 );
155
- } else {
156
- add_filter( 'clean_url', array( $this, 'filter_api_url' ) );
157
- }
158
-
159
- }
160
-
161
- /**
162
- * Filters the API script tag to add a custom ID.
163
- *
164
- * @since 1.0.0
165
- *
166
- * @param string $tag The HTML script output.
167
- * @param string $handle The script handle to target.
168
- * @return string $tag Amended HTML script with our ID attribute appended.
169
- */
170
- public function filter_api_script( $tag, $handle ) {
171
-
172
- // If the handle is not ours, do nothing.
173
- if ( $this->base->plugin_slug . '-api-script' !== $handle ) {
174
- return $tag;
175
- }
176
-
177
- // Adjust the output to add our custom script ID.
178
- return str_replace( ' src', ' data-cfasync="false" id="omapi-script" async="async" src', $tag );
179
-
180
- }
181
-
182
- /**
183
- * Filters the API script tag to add a custom ID.
184
- *
185
- * @since 1.0.0
186
- *
187
- * @param string $url The URL to filter.
188
- * @return string $url Amended URL with our ID attribute appended.
189
- */
190
- public function filter_api_url( $url ) {
191
-
192
- // If the handle is not ours, do nothing.
193
- if ( false === strpos( $url, 'a.optnmstr.com/app/js/api.min.js' ) ) {
194
- return $url;
195
- }
196
-
197
- // Adjust the URL to add our custom script ID.
198
- return "$url' async='async' id='omapi-script";
199
-
200
- }
201
-
202
- /**
203
- * Set the default query arg filter for OptinMonster.
204
- *
205
- * @since 1.0.0
206
- *
207
- * @param bool $bool Whether or not to alter the query arg filter.
208
- * @return bool True or false based on query arg detection.
209
- */
210
- public function query_filter( $bool ) {
211
-
212
- // If "omhide" is set, the query filter exists.
213
- if ( isset( $_GET['omhide'] ) && $_GET['omhide'] ) {
214
- return true;
215
- }
216
-
217
- return $bool;
218
-
219
- }
220
-
221
- /**
222
- * Conditionally loads the OptinMonster optin based on the query filter detection.
223
- *
224
- * @since 1.0.0
225
- */
226
- public function maybe_load_optinmonster() {
227
-
228
- // If a URL suffix is set to not load optinmonster, don't do anything.
229
- $bool = apply_filters( 'optin_monster_query_filter', false ); // Deprecated.
230
- $bool = apply_filters( 'optin_monster_api_query_filter', false );
231
- if ( $bool ) {
232
- // Default the global cookie to 30 days.
233
- $global_cookie = 30;
234
- $global_cookie = apply_filters( 'optin_monster_query_cookie', $global_cookie ); // Deprecated.
235
- $global_cookie = apply_filters( 'optin_monster_api_query_cookie', $global_cookie );
236
- if ( $global_cookie ) {
237
- setcookie( 'om-global-cookie', 1, time() + 3600 * 24 * (int) $global_cookie, COOKIEPATH, COOKIE_DOMAIN, false );
238
- }
239
-
240
- return;
241
- }
242
-
243
- // Add the hook to allow OptinMonster to process.
244
- add_action( 'pre_get_posts', array( $this, 'load_optinmonster_inline' ), 9999 );
245
- add_action( 'wp_footer', array( $this, 'load_optinmonster' ) );
246
-
247
- }
248
-
249
- /**
250
- * Loads an inline optin form (sidebar and after post) by checking against the current query.
251
- *
252
- * @since 1.0.0
253
- *
254
- * @param object $query The current main WP query object.
255
- */
256
- public function load_optinmonster_inline( $query ) {
257
-
258
- // If we are not on the main query or if in an rss feed, do nothing.
259
- if ( ! $query->is_main_query() || $query->is_feed() ) {
260
- return;
261
- }
262
 
263
  $priority = apply_filters( 'optin_monster_post_priority', 999 ); // Deprecated.
264
- $priority = apply_filters( 'optin_monster_api_post_priority', 999 );
265
- add_filter( 'the_content', array( $this, 'load_optinmonster_inline_content' ), $priority );
266
-
267
- }
268
-
269
- /**
270
- * Filters the content to output an optin form.
271
- *
272
- * @since 1.0.0
273
- *
274
- * @param string $content The current HTML string of main content.
275
- * @return string $content Amended content with possibly an optin.
276
- */
277
- public function load_optinmonster_inline_content( $content ) {
278
-
279
- global $post;
280
-
281
- // If the global $post is not set or the post status is not published, return early.
282
- if ( empty( $post ) || isset( $post->ID ) && 'publish' !== get_post_status( $post->ID ) ) {
283
- return $content;
284
- }
285
-
286
- // Don't do anything for excerpts.
287
- // This prevents the optin accidentally being output when get_the_excerpt() or wp_trim_excerpt() is
288
- // called by a theme or plugin, and there is no excerpt, meaning they call the_content and break us.
289
  global $wp_current_filter;
290
 
291
- if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) {
292
- return $content;
293
- }
294
-
295
- if ( in_array( 'wp_trim_excerpt', (array) $wp_current_filter ) ) {
296
- return $content;
297
- }
298
-
299
- // Prepare variables.
300
- $post_id = get_queried_object_id();
301
- if ( ! $post_id ) {
302
- if ( 'page' == get_option( 'show_on_front' ) ) {
303
- $post_id = get_option( 'page_for_posts' );
304
- }
305
- }
306
- $optins = $this->base->get_optins();
307
- $fields = array();
308
-
309
- // If no optins are found, return early.
310
- if ( ! $optins ) {
311
- return $content;
312
- }
313
-
314
- // Loop through each optin and optionally output it on the site.
315
- foreach ( $optins as $optin ) {
316
- // Grab all the fields to check against.
317
- foreach ( (array) $this->fields as $field ) {
318
- $fields[ $field ] = get_post_meta( $optin->ID, '_omapi_' . $field, true );
319
- }
320
-
321
- // Ensure the optin is enabled. If not, pass over it.
322
- if ( empty( $fields['enabled'] ) || ! $fields['enabled'] ) {
323
- continue;
324
- }
325
-
326
- // If in legacy test mode but not logged in, skip over the optin.
327
- if ( isset( $fields['test'] ) && $fields['test'] && ! is_user_logged_in() ) {
328
- continue;
329
- }
330
-
331
- // If the type is a sidebar or after post optin, pass over it.
332
- if ( isset( $fields['type'] ) && 'post' !== $fields['type'] ) {
333
- continue;
334
- }
335
-
336
- // If the optin is to be shown only to logged in users but is not logged in, pass over it.
337
- if ( isset( $fields['users'] ) && 'in' == $fields['users'] && ! is_user_logged_in() ) {
338
- continue;
339
- }
340
-
341
- // If the optin is to be shown only to visitors but is logged in, pass over it.
342
- if ( isset( $fields['users'] ) && 'out' == $fields['users'] && is_user_logged_in() ) {
343
- continue;
344
- }
345
-
346
- // Check to see if we need to load the WP API helper script.
347
- if ( isset( $fields['mailpoet'] ) && $fields['mailpoet'] ) {
348
- $this->wp_helper();
349
- }
350
-
351
- // Prepare the optin campaign.
352
- $html = trim( html_entity_decode( stripslashes( $optin->post_content ), ENT_QUOTES ), '\'' );
353
-
354
- // If the optin is only to be shown on specific post IDs, get the code and break.
355
- if ( ! empty( $fields['only'] ) ) {
356
- if ( $post_id && in_array( $post_id, (array) $fields['only'] ) ) {
357
- $content .= $html;
358
- $this->set_slug( $optin );
359
- continue;
360
- }
361
- }
362
-
363
- // Exclude posts/pages from optin display.
364
- if ( ! empty( $fields['never'] ) ) {
365
- if ( $post_id && in_array( $post_id, (array) $fields['never'] ) ) {
366
- continue;
367
- }
368
- }
369
-
370
- // If the optin is only to be shown on particular categories, get the code and break.
371
- if ( ! empty( $fields['categories'] ) && ( 'post' == get_post_type() ) ) {
372
- // If this is the home page, check to see if they have decided to load on certain archive pages.
373
- if ( is_home() ) {
374
- // Run a check for archive-type pages.
375
- if ( ! empty( $fields['show'] ) ) {
376
- // If showing on index pages and we are on an index page, show the optin.
377
- if ( in_array( 'index', (array) $fields['show'] ) ) {
378
- if ( is_front_page() || is_home() || is_archive() || is_search() ) {
379
- $content .= $html;
380
- $this->set_slug( $optin );
381
- continue;
382
- }
383
- }
384
-
385
- // Check if we should show on a selected post type.
386
- if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_archive() || is_search() ) ) {
387
- $content .= $html;
388
- $this->set_slug( $optin );
389
- continue;
390
- }
391
- }
392
- }
393
-
394
- $categories = wp_get_object_terms( $post_id, 'category', array( 'fields' => 'ids' ) );
395
- foreach ( (array) $categories as $category_id ) {
396
- if ( $category_id && in_array( $category_id, $fields['categories'] ) && ! is_archive() ) {
397
- $content .= $html;
398
- $this->set_slug( $optin );
399
- continue 2;
400
- }
401
- }
402
- }
403
-
404
- // If the optin is only to be shown on particular taxonomies, get the code and break.
405
- if ( ! empty( $fields['taxonomies'] ) && ( is_singular() ) ) {
406
- // If this is the home page, check to see if they have decided to load on certain archive pages.
407
- if ( is_home() ) {
408
- // Run a check for archive-type pages.
409
- if ( ! empty( $fields['show'] ) ) {
410
- // If showing on index pages and we are on an index page, show the optin.
411
- if ( in_array( 'index', (array) $fields['show'] ) ) {
412
- if ( is_front_page() || is_home() || is_archive() || is_search() ) {
413
- $content .= $html;
414
- $this->set_slug( $optin );
415
- continue;
416
- }
417
- }
418
-
419
- // Check if we should show on a selected post type.
420
- if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_archive() || is_search() ) ) {
421
- $content .= $html;
422
- $this->set_slug( $optin );
423
- continue;
424
- }
425
- }
426
- }
427
-
428
- $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
429
- $taxonomies['post_tag'] = 'post_tag';
430
- $taxonomies['post_format'] = 'post_format';
431
- $taxonomies = wp_get_object_terms( $post_id, $taxonomies, array( 'fields' => 'ids' ) );
432
- foreach ( $fields['taxonomies'] as $taxonomy => $taxonomy_id ) {
433
- $tax_ids = explode(',', $taxonomy_id[0] );
434
- foreach ( $tax_ids as $tax_id ) {
435
- if ( $post_id && $tax_id && has_term( $tax_id, $taxonomy, $post_id ) ) {
436
- $content .= $html;
437
- $this->set_slug( $optin );
438
- continue 2;
439
- }
440
- }
441
- }
442
- }
443
-
444
- // Run a check for specific post types.
445
- if ( ! empty( $fields['show'] ) ) {
446
- // Check if we should show on a selected post type.
447
- if ( in_array( get_post_type(), (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
448
- $content .= $html;
449
- $this->set_slug( $optin );
450
- continue;
451
- }
452
- }
453
-
454
- // If WooCommerce is enabled we can look for WooCommerce specific settings.
455
- if ( $this->base->is_woocommerce_active() ) {
456
-
457
- // is_woocommerce anything
458
- if ( isset( $fields['show_on_woocommerce'] ) && $fields['show_on_woocommerce'] ) {
459
- if( is_woocommerce() ) {
460
- $content .= $html;
461
- $this->set_slug( $optin );
462
- continue;
463
- }
464
- }
465
- // is_product
466
- if ( isset( $fields['is_wc_product'] ) && $fields['is_wc_product'] ) {
467
- $global = false;
468
- if( is_product() ) {
469
- $content .= $html;
470
- $this->set_slug( $optin );
471
- continue;
472
- }
473
- }
474
-
475
- // is_cart
476
- if ( isset( $fields['is_wc_cart'] ) && $fields['is_wc_cart'] ) {
477
- $global = false;
478
- if( is_cart() ) {
479
- $content .= $html;
480
- $this->set_slug( $optin );
481
- continue;
482
- }
483
- }
484
-
485
- // is_checkout
486
- if ( isset( $fields['is_wc_checkout'] ) && $fields['is_wc_checkout'] ) {
487
- $global = false;
488
- if( is_checkout() ) {
489
- $content .= $html;
490
- $this->set_slug( $optin );
491
- continue;
492
- }
493
- }
494
-
495
- // is_account_page
496
- if ( isset( $fields['is_wc_account'] ) && $fields['is_wc_account'] ) {
497
- $global = false;
498
- if( is_account_page() ) {
499
- $content .= $html;
500
- $this->set_slug( $optin );
501
- continue;
502
- }
503
- }
504
-
505
- // is_wc_endpoint_url
506
- if ( isset( $fields['is_wc_endpoint'] ) && $fields['is_wc_endpoint'] ) {
507
- $global = false;
508
- if( is_wc_endpoint_url() ) {
509
- $content .= $html;
510
- $this->set_slug( $optin );
511
- continue;
512
- }
513
- }
514
-
515
- // is_wc_endpoint_url( 'order-pay' )
516
- if ( isset( $fields['is_wc_endpoint_order_pay'] ) && $fields['is_wc_endpoint_order_pay'] ) {
517
- $global = false;
518
- if( is_wc_endpoint_url( 'order-pay' ) ) {
519
- $content .= $html;
520
- $this->set_slug( $optin );
521
- continue;
522
- }
523
- }
524
-
525
- // is_wc_endpoint_url( 'order-received' )
526
- if ( isset( $fields['is_wc_endpoint_order_received'] ) && $fields['is_wc_endpoint_order_received'] ) {
527
- $global = false;
528
- if( is_wc_endpoint_url( 'order-received' ) ) {
529
- $content .= $html;
530
- $this->set_slug( $optin );
531
- continue;
532
- }
533
- }
534
-
535
- // is_wc_endpoint_url( 'view-order' )
536
- if ( isset( $fields['is_wc_endpoint_view_order'] ) && $fields['is_wc_endpoint_view_order'] ) {
537
- $global = false;
538
- if( is_wc_endpoint_url( 'view-order' ) ) {
539
- $content .= $html;
540
- $this->set_slug( $optin );
541
- continue;
542
- }
543
- }
544
-
545
- // is_wc_endpoint_url( 'edit-account' )
546
- if ( isset( $fields['is_wc_endpoint_edit_account'] ) && $fields['is_wc_endpoint_edit_account'] ) {
547
- $global = false;
548
- if( is_wc_endpoint_url( 'edit-account' ) ) {
549
- $content .= $html;
550
- $this->set_slug( $optin );
551
- continue;
552
- }
553
- }
554
-
555
- // is_wc_endpoint_url( 'edit-address' )
556
- if ( isset( $fields['is_wc_endpoint_edit_address'] ) && $fields['is_wc_endpoint_edit_address'] ) {
557
- $global = false;
558
- if( is_wc_endpoint_url( 'edit-address' ) ) {
559
- $content .= $html;
560
- $this->set_slug( $optin );
561
- continue;
562
- }
563
- }
564
-
565
- // is_wc_endpoint_url( 'lost-password' )
566
- if ( isset( $fields['is_wc_endpoint_lost_password'] ) && $fields['is_wc_endpoint_lost_password'] ) {
567
- $global = false;
568
- if( is_wc_endpoint_url( 'lost-password' ) ) {
569
- $content .= $html;
570
- $this->set_slug( $optin );
571
- continue;
572
- }
573
- }
574
-
575
- // is_wc_endpoint_url( 'customer-logout' )
576
- if ( isset( $fields['is_wc_endpoint_customer_logout'] ) && $fields['is_wc_endpoint_customer_logout'] ) {
577
- $global = false;
578
- if( is_wc_endpoint_url( 'customer-logout' ) ) {
579
- $content .= $html;
580
- $this->set_slug( $optin );
581
- continue;
582
- }
583
- }
584
- // is_wc_endpoint_url( 'add-payment-method' )
585
- if ( isset( $fields['is_wc_endpoint_add_payment_method'] ) && $fields['is_wc_endpoint_add_payment_method'] ) {
586
- $global = false;
587
- if( is_wc_endpoint_url( 'add-payment-method' ) ) {
588
- $content .= $html;
589
- $this->set_slug( $optin );
590
- continue;
591
- }
592
- }
593
-
594
-
595
-
596
- }
597
 
598
  // If the optin is set to be automatically displayed, show it.
599
- if ( isset( $fields['automatic'] ) && $fields['automatic'] && is_singular( 'post' ) ) {
600
- $content .= $html;
601
- $this->set_slug( $optin );
602
- continue;
603
- }
604
-
605
- }
606
-
607
- // Return the content.
608
- return $content;
609
-
610
- }
611
-
612
- /**
613
- * Possibly loads an optin on a page.
614
- *
615
- * @since 1.0.0
616
- */
617
- public function load_optinmonster() {
618
-
619
- // Prepare variables.
620
- global $post;
621
- $post_id = get_queried_object_id();
622
- if ( ! $post_id ) {
623
- if ( 'page' == get_option( 'show_on_front' ) ) {
624
- $post_id = get_option( 'page_for_posts' );
625
- }
626
- }
627
- $optins = $this->base->get_optins();
628
- $init = array();
629
- $fields = array();
630
-
631
- // If no optins are found, return early.
632
- if ( ! $optins ) {
633
- return;
634
- }
635
-
636
- // Loop through each optin and optionally output it on the site.
637
- foreach ( $optins as $optin ) {
638
-
639
- // Grab all the fields to check against.
640
- foreach ( (array) $this->fields as $field ) {
641
- $fields[ $field ] = get_post_meta( $optin->ID, '_omapi_' . $field, true );
642
- }
643
-
644
- // Ensure the optin is enabled. If not, pass over it.
645
- if ( empty( $fields['enabled'] ) || ! $fields['enabled'] ) {
646
- continue;
647
- }
648
-
649
- // If in legacy test mode but not logged in, skip over the optin.
650
- if ( isset( $fields['test'] ) && $fields['test'] && ! is_user_logged_in() ) {
651
- continue;
652
- }
653
-
654
- // If the type is a sidebar or after post optin, pass over it.
655
- if ( isset( $fields['type'] ) && ( 'post' == $fields['type'] || 'sidebar' == $fields['type'] ) ) {
656
- continue;
657
- }
658
-
659
- // If the optin is to be shown only to logged in users but is not logged in, pass over it.
660
- if ( isset( $fields['users'] ) && 'in' == $fields['users'] && ! is_user_logged_in() ) {
661
- continue;
662
- }
663
-
664
- // If the optin is to be shown only to visitors but is logged in, pass over it.
665
- if ( isset( $fields['users'] ) && 'out' == $fields['users'] && is_user_logged_in() ) {
666
- continue;
667
- }
668
-
669
- // Check to see if we need to load the WP API helper script.
670
- if ( isset( $fields['mailpoet'] ) && $fields['mailpoet'] ) {
671
- $this->wp_helper();
672
- }
673
-
674
- // Prepare the optin campaign.
675
- $html = trim( html_entity_decode( stripslashes( $optin->post_content ), ENT_QUOTES ), '\'' );
676
- $global = true;
677
-
678
- // If the optin is only to be shown on specific post IDs, get the code and break.
679
- if ( ! empty( $fields['only'] ) ) {
680
- // Set flag for possibly not loading globally.
681
- $values = array_filter( array_values( $fields['only'] ) );
682
- if ( ! empty( $values ) ) {
683
- $global = false;
684
- }
685
-
686
- if ( $post_id && in_array( $post_id, (array) $fields['only'] ) ) {
687
- $init[ $optin->post_name ] = $html;
688
- $this->set_slug( $optin );
689
- continue;
690
- }
691
- }
692
-
693
- // Exclude posts/pages from optin display.
694
- if ( ! empty( $fields['never'] ) ) {
695
- // No global check on purpose. Global is still true if only this setting is populated.
696
- if ( $post_id && in_array( $post_id, (array) $fields['never'] ) ) {
697
- continue;
698
- }
699
- }
700
-
701
- // If the optin is only to be shown on particular categories, get the code and break.
702
- if ( ! empty( $fields['categories'] ) ) {
703
- // Set flag for possibly not loading globally.
704
- $values = array_filter( array_values( $fields['categories'] ) );
705
- if ( ! empty( $values ) ) {
706
- $global = false;
707
- }
708
-
709
- // Only load for the main "post" post type.
710
- if ( 'post' == get_post_type() ) {
711
- // Don't try to load on the blog home page even if a category that is selected appears in the loop.
712
- if ( is_home() ) {
713
- // Run a check for archive-type pages.
714
- if ( ! empty( $fields['show'] ) ) {
715
- // If showing on index pages and we are on an index page, show the optin.
716
- if ( in_array( 'index', (array) $fields['show'] ) ) {
717
- if ( is_front_page() || is_home() || is_search() ) {
718
- $init[ $optin->post_name ] = $html;
719
- $this->set_slug( $optin );
720
- continue;
721
- }
722
- }
723
-
724
- // Check if we should show on the 'post' post type.
725
- if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
726
- $init[ $optin->post_name ] = $html;
727
- $this->set_slug( $optin );
728
- continue;
729
- }
730
- }
731
- }
732
-
733
- $categories = wp_get_object_terms( $post_id, 'category', array( 'fields' => 'ids' ) );
734
-
735
- // Check againts singular.
736
- foreach ( (array) $categories as $category_id ) {
737
- if ( $category_id && in_array( $category_id, $fields['categories'] ) ) {
738
- $init[ $optin->post_name ] = $html;
739
- $this->set_slug( $optin );
740
- continue 2;
741
- }
742
- }
743
-
744
- // Check archives.
745
- if ( is_category( $fields['categories'] ) ) {
746
- $init[ $optin->post_name ] = $html;
747
- $this->set_slug( $optin );
748
- continue;
749
- }
750
- }
751
- }
752
-
753
- // If the optin is only to be shown on particular taxonomies, get the code and break.
754
- if ( ! empty( $fields['taxonomies'] ) ) {
755
- // Set flag for possibly not loading globally.
756
- $values = array_filter( array_values( $fields['taxonomies'] ) );
757
- if ( ! empty( $values ) ) {
758
- foreach ( $values as $i => $value ) {
759
- $value = array_filter( array_values( $value ) );
760
- if ( $value ) {
761
- $global = false;
762
- break;
763
- }
764
- }
765
- }
766
-
767
- // If this is the home page, check to see if they have decided to load on certain archive pages.
768
- if ( is_home() ) {
769
- // Run a check for archive-type pages.
770
- if ( ! empty( $fields['show'] ) ) {
771
- // If showing on index pages and we are on an index page, show the optin.
772
- if ( in_array( 'index', (array) $fields['show'] ) ) {
773
- if ( is_front_page() || is_home() || is_search() ) {
774
- $init[ $optin->post_name ] = $html;
775
- $this->set_slug( $optin );
776
- continue;
777
- }
778
- }
779
-
780
- // Check if we should show on the 'post' post type.
781
- if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
782
- $init[ $optin->post_name ] = $html;
783
- $this->set_slug( $optin );
784
- continue;
785
- }
786
- }
787
- }
788
-
789
- $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
790
- $taxonomies['post_tag'] = 'post_tag';
791
- $taxonomies['post_format'] = 'post_format';
792
- $taxonomies = wp_get_object_terms( $post_id, $taxonomies, array( 'fields' => 'ids' ) );
793
- foreach ( $fields['taxonomies'] as $taxonomy => $taxonomy_id ) {
794
- $tax_ids = explode(',', $taxonomy_id[0] );
795
- foreach ( $tax_ids as $tax_id ) {
796
- if ( $post_id && $tax_id && has_term( $tax_id, $taxonomy, $post_id ) ) {
797
- $init[ $optin->post_name ] = $html;
798
- $this->set_slug( $optin );
799
- continue 2;
800
- }
801
- }
802
- foreach ( $tax_ids as $tax_id ) {
803
- if ( is_tag($tax_id) ) {
804
- $init[ $optin->post_name ] = $html;
805
- $this->set_slug( $optin );
806
- continue 2;
807
- }
808
- }
809
- }
810
- }
811
-
812
- // Run a check for archive-type pages.
813
- if ( ! empty( $fields['show'] ) ) {
814
- // Set flag for possibly not loading globally.
815
- $values = array_filter( array_values( $fields['show'] ) );
816
- if ( ! empty( $values ) ) {
817
- $global = false;
818
- }
819
-
820
- // If showing on index pages and we are on an index page, show the optin.
821
- if ( in_array( 'index', (array) $fields['show'] ) ) {
822
- if ( is_front_page() || is_home() || is_search() ) {
823
- $init[ $optin->post_name ] = $html;
824
- $this->set_slug( $optin );
825
- continue;
826
- }
827
- }
828
-
829
- // Check if we should show on a selected post type.
830
- if ( in_array( get_post_type(), (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
831
- $init[ $optin->post_name ] = $html;
832
- $this->set_slug( $optin );
833
- continue;
834
- }
835
- }
836
-
837
- // If WooCommerce is enabled we can look for WooCommerce specific settings.
838
- if ( $this->base->is_woocommerce_active() ) {
839
-
840
- // Separate never checks for WooCommerce pages that don't ID match
841
- if ( ! empty( $fields['never'] ) ) {
842
- // No global check on purpose. Global is still true if only this setting is populated.
843
- if ( in_array( wc_get_page_id( 'shop' ), (array) $fields['never'] ) && is_shop() ) {
844
- continue;
845
- }
846
- }
847
-
848
- // is_woocommerce
849
- if ( isset( $fields['show_on_woocommerce'] ) && $fields['show_on_woocommerce'] ) {
850
- $global = false;
851
- if( is_woocommerce() ) {
852
- $init[ $optin->post_name ] = $html;
853
- $this->set_slug( $optin );
854
- continue;
855
- }
856
- }
857
-
858
- // is_shop
859
- if ( isset( $fields['is_wc_shop'] ) && $fields['is_wc_shop'] ) {
860
- $global = false;
861
- if( is_shop() ) {
862
- $init[ $optin->post_name ] = $html;
863
- $this->set_slug( $optin );
864
- continue;
865
- }
866
- }
867
-
868
- // is_product
869
- if ( isset( $fields['is_wc_product'] ) && $fields['is_wc_product'] ) {
870
- $global = false;
871
- if( is_product() ) {
872
- $init[ $optin->post_name ] = $html;
873
- $this->set_slug( $optin );
874
- continue;
875
- }
876
- }
877
-
878
- // is_cart
879
- if ( isset( $fields['is_wc_cart'] ) && $fields['is_wc_cart'] ) {
880
- $global = false;
881
- if( is_cart() ) {
882
- $init[ $optin->post_name ] = $html;
883
- $this->set_slug( $optin );
884
- continue;
885
- }
886
- }
887
-
888
- // is_checkout
889
- if ( isset( $fields['is_wc_checkout'] ) && $fields['is_wc_checkout'] ) {
890
- $global = false;
891
- if( is_checkout() ) {
892
- $init[ $optin->post_name ] = $html;
893
- $this->set_slug( $optin );
894
- continue;
895
- }
896
- }
897
-
898
- // is_account_page
899
- if ( isset( $fields['is_wc_account'] ) && $fields['is_wc_account'] ) {
900
- $global = false;
901
- if( is_account_page() ) {
902
- $init[ $optin->post_name ] = $html;
903
- $this->set_slug( $optin );
904
- continue;
905
- }
906
- }
907
-
908
- // is_wc_endpoint_url
909
- if ( isset( $fields['is_wc_endpoint'] ) && $fields['is_wc_endpoint'] ) {
910
- $global = false;
911
- if( is_wc_endpoint_url() ) {
912
- $init[ $optin->post_name ] = $html;
913
- $this->set_slug( $optin );
914
- continue;
915
- }
916
- }
917
-
918
- // is_wc_endpoint_url( 'order-pay' )
919
- if ( isset( $fields['is_wc_endpoint_order_pay'] ) && $fields['is_wc_endpoint_order_pay'] ) {
920
- $global = false;
921
- if( is_wc_endpoint_url( 'order-pay' ) ) {
922
- $init[ $optin->post_name ] = $html;
923
- $this->set_slug( $optin );
924
- continue;
925
- }
926
- }
927
-
928
- // is_wc_endpoint_url( 'order-received' )
929
- if ( isset( $fields['is_wc_endpoint_order_received'] ) && $fields['is_wc_endpoint_order_received'] ) {
930
- $global = false;
931
- if( is_wc_endpoint_url( 'order-received' ) ) {
932
- $init[ $optin->post_name ] = $html;
933
- $this->set_slug( $optin );
934
- continue;
935
- }
936
- }
937
-
938
- // is_wc_endpoint_url( 'view-order' )
939
- if ( isset( $fields['is_wc_endpoint_view_order'] ) && $fields['is_wc_endpoint_view_order'] ) {
940
- $global = false;
941
- if( is_wc_endpoint_url( 'view-order' ) ) {
942
- $init[ $optin->post_name ] = $html;
943
- $this->set_slug( $optin );
944
- continue;
945
- }
946
- }
947
-
948
- // is_wc_endpoint_url( 'edit-account' )
949
- if ( isset( $fields['is_wc_endpoint_edit_account'] ) && $fields['is_wc_endpoint_edit_account'] ) {
950
- $global = false;
951
- if( is_wc_endpoint_url( 'edit-account' ) ) {
952
- $init[ $optin->post_name ] = $html;
953
- $this->set_slug( $optin );
954
- continue;
955
- }
956
- }
957
-
958
- // is_wc_endpoint_url( 'edit-address' )
959
- if ( isset( $fields['is_wc_endpoint_edit_address'] ) && $fields['is_wc_endpoint_edit_address'] ) {
960
- $global = false;
961
- if( is_wc_endpoint_url( 'edit-address' ) ) {
962
- $init[ $optin->post_name ] = $html;
963
- $this->set_slug( $optin );
964
- continue;
965
- }
966
- }
967
-
968
- // is_wc_endpoint_url( 'lost-password' )
969
- if ( isset( $fields['is_wc_endpoint_lost_password'] ) && $fields['is_wc_endpoint_lost_password'] ) {
970
- $global = false;
971
- if( is_wc_endpoint_url( 'lost-password' ) ) {
972
- $init[ $optin->post_name ] = $html;
973
- $this->set_slug( $optin );
974
- continue;
975
- }
976
- }
977
-
978
- // is_wc_endpoint_url( 'customer-logout' )
979
- if ( isset( $fields['is_wc_endpoint_customer_logout'] ) && $fields['is_wc_endpoint_customer_logout'] ) {
980
- $global = false;
981
- if( is_wc_endpoint_url( 'customer-logout' ) ) {
982
- $init[ $optin->post_name ] = $html;
983
- $this->set_slug( $optin );
984
- continue;
985
- }
986
- }
987
- // is_wc_endpoint_url( 'add-payment-method' )
988
- if ( isset( $fields['is_wc_endpoint_add_payment_method'] ) && $fields['is_wc_endpoint_add_payment_method'] ) {
989
- $global = false;
990
- if( is_wc_endpoint_url( 'add-payment-method' ) ) {
991
- $init[ $optin->post_name ] = $html;
992
- $this->set_slug( $optin );
993
- continue;
994
- }
995
- }
996
-
997
-
998
- }
999
-
1000
- // If we should be loading globally, do it now.
1001
- if ( $global ) {
1002
- $init[ $optin->post_name ] = $html;
1003
- $this->set_slug( $optin );
1004
- continue;
1005
- }
1006
-
1007
- // Allow devs to filter the final output for more granular control over optin targeting.
1008
- // Devs should return the value for the slug key as false if the conditions are not met.
1009
- $init = apply_filters( 'optinmonster_output', $init ); // Deprecated.
1010
- $init = apply_filters( 'optin_monster_output', $init, $optin, $fields, $post_id ); // Deprecated.
1011
- $init = apply_filters( 'optin_monster_api_output', $init, $optin, $fields, $post_id );
1012
- }
1013
-
1014
- // Run a final filter for all items.
1015
- $init = apply_filters( 'optin_monster_api_final_output', $init, $post_id );
1016
-
1017
- // If the init code is empty, do nothing.
1018
- if ( empty( $init ) ) {
1019
- return;
1020
- }
1021
-
1022
- // Load the optins.
1023
- foreach ( (array) $init as $optin ) {
1024
- if ( $optin ) {
1025
- echo $optin;
1026
- }
1027
- }
1028
 
1029
  }
1030
 
1031
  /**
1032
- * Sets the slug for possibly parsing shortcodes.
1033
- *
1034
- * @since 1.0.0
1035
- *
1036
- * @param object $optin The optin object.
1037
- */
1038
  public function set_slug( $optin ) {
1039
 
1040
  // Set the slug.
1041
- $this->slugs[] = str_replace( '-', '_', $optin->post_name );
 
 
 
1042
 
1043
  // Maybe set shortcode.
1044
  $shortcode = get_post_meta( $optin->ID, '_omapi_shortcode', true );
@@ -1049,10 +1052,10 @@ class OMAPI_Output {
1049
  }
1050
 
1051
  /**
1052
- * Maybe outputs the JS variables to parse shortcodes.
1053
- *
1054
- * @since 1.0.0
1055
- */
1056
  public function maybe_parse_shortcodes() {
1057
 
1058
  // If no slugs have been set, do nothing.
@@ -1085,53 +1088,53 @@ class OMAPI_Output {
1085
  }
1086
 
1087
  // Output the JS variables to signify shortcode parsing is needed.
1088
- ?>
1089
- <script type="text/javascript"><?php foreach ( $this->slugs as $slug ) { echo 'var ' . $slug . '_shortcode = true;'; } ?></script>
1090
- <?php
1091
 
1092
  }
1093
 
1094
  /**
1095
- * Possibly localizes a JS variable for output use.
1096
- *
1097
- * @since 1.0.0
1098
- */
1099
- public function localize() {
1100
-
1101
- // If no slugs have been set, do nothing.
1102
- if ( empty( $this->slugs ) ) {
1103
- return;
1104
- }
1105
-
1106
- // If already localized, do nothing.
1107
- if ( $this->localized ) {
1108
- return;
1109
- }
1110
-
1111
- // Set flag to true.
1112
- $this->localized = true;
1113
-
1114
- // Output JS variable.
1115
- ?>
1116
- <script type="text/javascript">var omapi_localized = { ajax: '<?php echo esc_url_raw( add_query_arg( 'optin-monster-ajax-route', true, admin_url( 'admin-ajax.php' ) ) ); ?>', nonce: '<?php echo wp_create_nonce( 'omapi' ); ?>' };</script>
1117
- <?php
1118
 
1119
  }
1120
 
1121
  /**
1122
- * Outputs the WP helper script for storing local optins.
1123
- *
1124
- * @since 1.0.0
1125
- */
1126
  public function wp_helper() {
1127
 
1128
  wp_enqueue_script(
1129
- $this->base->plugin_slug . '-wp-helper',
1130
- plugins_url( 'assets/js/helper.js', OMAPI_FILE ),
1131
- array( 'jquery'),
1132
- $this->base->version,
1133
- true
1134
- );
1135
 
1136
  }
1137
 
10
  class OMAPI_Output {
11
 
12
  /**
13
+ * Holds the class object.
14
+ *
15
+ * @since 1.0.0
16
+ *
17
+ * @var object
18
+ */
19
+ public static $instance;
20
 
21
  /**
22
+ * Path to the file.
23
+ *
24
+ * @since 1.0.0
25
+ *
26
+ * @var string
27
+ */
28
+ public $file = __FILE__;
29
+
30
+ /**
31
+ * Holds the base class object.
32
+ *
33
+ * @since 1.0.0
34
+ *
35
+ * @var object
36
+ */
37
+ public $base;
38
+
39
+ /**
40
+ * Holds the meta fields used for checking output statuses.
41
+ *
42
+ * @since 1.0.0
43
+ *
44
+ * @var array
45
+ */
46
+ public $fields = array(
47
+ 'enabled',
48
+ 'automatic',
49
+ 'users',
50
+ 'never',
51
+ 'only',
52
+ 'categories',
53
+ 'taxonomies',
54
+ 'show',
55
+ 'type',
56
+ 'shortcode',
57
+ 'shortcode_output',
58
+ 'mailpoet',
59
+ 'test',
60
+ 'show_on_woocommerce',
61
+ 'is_wc_shop',
62
+ 'is_wc_product',
63
+ 'is_wc_cart',
64
+ 'is_wc_checkout',
65
+ 'is_wc_account',
66
+ 'is_wc_endpoint',
67
+ 'is_wc_endpoint_order_pay',
68
+ 'is_wc_endpoint_order_received',
69
+ 'is_wc_endpoint_view_order',
70
+ 'is_wc_endpoint_edit_account',
71
+ 'is_wc_endpoint_edit_address',
72
+ 'is_wc_endpoint_lost_password',
73
+ 'is_wc_endpoint_customer_logout',
74
+ 'is_wc_endpoint_add_payment_method',
75
+ 'is_wc_product_category',
76
+ 'is_wc_product_tag',
77
+ );
78
+
79
+ /**
80
+ * Flag for determining if localized JS variable is output.
81
+ *
82
+ * @since 1.0.0
83
+ *
84
+ * @var bool
85
+ */
86
+ public $localized = false;
87
+
88
+ /**
89
+ * Holds JS slugs for maybe parsing shortcodes.
90
+ *
91
+ * @since 1.0.0
92
+ *
93
+ * @var array
94
+ */
95
+ public $slugs = array();
96
+
97
+ /**
98
+ * Holds shortcode output.
99
+ *
100
+ * @since 1.0.0
101
+ *
102
+ * @var array
103
+ */
104
+ public $shortcodes = array();
105
+
106
+ /**
107
+ * Primary class constructor.
108
+ *
109
+ * @since 1.0.0
110
+ */
111
+ public function __construct() {
112
+
113
+ // Set our object.
114
+ $this->set();
115
+
116
+ // If no credentials have been provided, do nothing.
117
+ if ( ! $this->base->get_api_credentials() ) {
118
+ return;
119
+ }
120
 
121
  // Load actions and filters.
122
  add_action( 'wp_enqueue_scripts', array( $this, 'api_script' ) );
123
+ add_action( 'wp_footer', array( $this, 'localize' ), 9999 );
124
+ add_action( 'wp_footer', array( $this, 'maybe_parse_shortcodes' ), 11 );
125
+
126
+ // Maybe load OptinMonster.
127
+ $this->maybe_load_optinmonster();
128
+
129
+ }
130
+
131
+ /**
132
+ * Sets our object instance and base class instance.
133
+ *
134
+ * @since 1.0.0
135
+ */
136
+ public function set() {
137
+
138
+ self::$instance = $this;
139
+ $this->base = OMAPI::get_instance();
140
+ $this->fields = apply_filters( 'optin_monster_api_output_fields', $this->fields );
141
+
142
+ }
143
+
144
+ /**
145
+ * Enqueues the OptinMonster API script.
146
+ *
147
+ * @since 1.0.0
148
+ */
149
+ public function api_script() {
150
+
151
+ wp_enqueue_script( $this->base->plugin_slug . '-api-script', OPTINMONSTER_API, array( 'jquery' ), $this->base->version );
152
+
153
+ if ( version_compare( get_bloginfo( 'version' ), '4.1.0', '>=' ) ) {
154
+ add_filter( 'script_loader_tag', array( $this, 'filter_api_script' ), 10, 2 );
155
+ } else {
156
+ add_filter( 'clean_url', array( $this, 'filter_api_url' ) );
157
+ }
158
+
159
+ }
160
+
161
+ /**
162
+ * Filters the API script tag to add a custom ID.
163
+ *
164
+ * @since 1.0.0
165
+ *
166
+ * @param string $tag The HTML script output.
167
+ * @param string $handle The script handle to target.
168
+ * @return string $tag Amended HTML script with our ID attribute appended.
169
+ */
170
+ public function filter_api_script( $tag, $handle ) {
171
+
172
+ // If the handle is not ours, do nothing.
173
+ if ( $this->base->plugin_slug . '-api-script' !== $handle ) {
174
+ return $tag;
175
+ }
176
+
177
+ // Adjust the output to add our custom script ID.
178
+ return str_replace( ' src', ' data-cfasync="false" id="omapi-script" async="async" src', $tag );
179
+
180
+ }
181
+
182
+ /**
183
+ * Filters the API script tag to add a custom ID.
184
+ *
185
+ * @since 1.0.0
186
+ *
187
+ * @param string $url The URL to filter.
188
+ * @return string $url Amended URL with our ID attribute appended.
189
+ */
190
+ public function filter_api_url( $url ) {
191
+
192
+ // If the handle is not ours, do nothing.
193
+ if ( false === strpos( $url, 'a.optnmstr.com/app/js/api.min.js' ) ) {
194
+ return $url;
195
+ }
196
+
197
+ // Adjust the URL to add our custom script ID.
198
+ return "$url' async='async' id='omapi-script";
199
+
200
+ }
201
+
202
+ /**
203
+ * Set the default query arg filter for OptinMonster.
204
+ *
205
+ * @since 1.0.0
206
+ *
207
+ * @param bool $bool Whether or not to alter the query arg filter.
208
+ * @return bool True or false based on query arg detection.
209
+ */
210
+ public function query_filter( $bool ) {
211
+
212
+ // If "omhide" is set, the query filter exists.
213
+ if ( isset( $_GET['omhide'] ) && $_GET['omhide'] ) {
214
+ return true;
215
+ }
216
+
217
+ return $bool;
218
+
219
+ }
220
+
221
+ /**
222
+ * Conditionally loads the OptinMonster optin based on the query filter detection.
223
+ *
224
+ * @since 1.0.0
225
+ */
226
+ public function maybe_load_optinmonster() {
227
+
228
+ // If a URL suffix is set to not load optinmonster, don't do anything.
229
+ $bool = apply_filters( 'optin_monster_query_filter', false ); // Deprecated.
230
+ $bool = apply_filters( 'optin_monster_api_query_filter', false );
231
+ if ( $bool ) {
232
+ // Default the global cookie to 30 days.
233
+ $global_cookie = 30;
234
+ $global_cookie = apply_filters( 'optin_monster_query_cookie', $global_cookie ); // Deprecated.
235
+ $global_cookie = apply_filters( 'optin_monster_api_query_cookie', $global_cookie );
236
+ if ( $global_cookie ) {
237
+ setcookie( 'om-global-cookie', 1, time() + 3600 * 24 * (int) $global_cookie, COOKIEPATH, COOKIE_DOMAIN, false );
238
+ }
239
+
240
+ return;
241
+ }
242
+
243
+ // Add the hook to allow OptinMonster to process.
244
+ add_action( 'pre_get_posts', array( $this, 'load_optinmonster_inline' ), 9999 );
245
+ add_action( 'wp_footer', array( $this, 'load_optinmonster' ) );
246
+
247
+ }
248
+
249
+ /**
250
+ * Loads an inline optin form (sidebar and after post) by checking against the current query.
251
+ *
252
+ * @since 1.0.0
253
+ *
254
+ * @param object $query The current main WP query object.
255
+ */
256
+ public function load_optinmonster_inline( $query ) {
257
+
258
+ // If we are not on the main query or if in an rss feed, do nothing.
259
+ if ( ! $query->is_main_query() || $query->is_feed() ) {
260
+ return;
261
+ }
262
 
263
  $priority = apply_filters( 'optin_monster_post_priority', 999 ); // Deprecated.
264
+ $priority = apply_filters( 'optin_monster_api_post_priority', 999 );
265
+ add_filter( 'the_content', array( $this, 'load_optinmonster_inline_content' ), $priority );
266
+
267
+ }
268
+
269
+ /**
270
+ * Filters the content to output an optin form.
271
+ *
272
+ * @since 1.0.0
273
+ *
274
+ * @param string $content The current HTML string of main content.
275
+ * @return string $content Amended content with possibly an optin.
276
+ */
277
+ public function load_optinmonster_inline_content( $content ) {
278
+
279
+ global $post;
280
+
281
+ // If the global $post is not set or the post status is not published, return early.
282
+ if ( empty( $post ) || isset( $post->ID ) && 'publish' !== get_post_status( $post->ID ) ) {
283
+ return $content;
284
+ }
285
+
286
+ // Don't do anything for excerpts.
287
+ // This prevents the optin accidentally being output when get_the_excerpt() or wp_trim_excerpt() is
288
+ // called by a theme or plugin, and there is no excerpt, meaning they call the_content and break us.
289
  global $wp_current_filter;
290
 
291
+ if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) {
292
+ return $content;
293
+ }
294
+
295
+ if ( in_array( 'wp_trim_excerpt', (array) $wp_current_filter ) ) {
296
+ return $content;
297
+ }
298
+
299
+ // Prepare variables.
300
+ $post_id = get_queried_object_id();
301
+ if ( ! $post_id ) {
302
+ if ( 'page' == get_option( 'show_on_front' ) ) {
303
+ $post_id = get_option( 'page_for_posts' );
304
+ }
305
+ }
306
+ $optins = $this->base->get_optins();
307
+ $fields = array();
308
+
309
+ // If no optins are found, return early.
310
+ if ( ! $optins ) {
311
+ return $content;
312
+ }
313
+
314
+ // Loop through each optin and optionally output it on the site.
315
+ foreach ( $optins as $optin ) {
316
+ // Grab all the fields to check against.
317
+ foreach ( (array) $this->fields as $field ) {
318
+ $fields[ $field ] = get_post_meta( $optin->ID, '_omapi_' . $field, true );
319
+ }
320
+
321
+ // Ensure the optin is enabled. If not, pass over it.
322
+ if ( empty( $fields['enabled'] ) || ! $fields['enabled'] ) {
323
+ continue;
324
+ }
325
+
326
+ // If in legacy test mode but not logged in, skip over the optin.
327
+ if ( isset( $fields['test'] ) && $fields['test'] && ! is_user_logged_in() ) {
328
+ continue;
329
+ }
330
+
331
+ // If the type is a sidebar or after post optin, pass over it.
332
+ if ( isset( $fields['type'] ) && 'post' !== $fields['type'] ) {
333
+ continue;
334
+ }
335
+
336
+ // If the optin is to be shown only to logged in users but is not logged in, pass over it.
337
+ if ( isset( $fields['users'] ) && 'in' == $fields['users'] && ! is_user_logged_in() ) {
338
+ continue;
339
+ }
340
+
341
+ // If the optin is to be shown only to visitors but is logged in, pass over it.
342
+ if ( isset( $fields['users'] ) && 'out' == $fields['users'] && is_user_logged_in() ) {
343
+ continue;
344
+ }
345
+
346
+ // Check to see if we need to load the WP API helper script.
347
+ if ( isset( $fields['mailpoet'] ) && $fields['mailpoet'] ) {
348
+ $this->wp_helper();
349
+ }
350
+
351
+ // Prepare the optin campaign.
352
+ $html = trim( html_entity_decode( stripslashes( $optin->post_content ), ENT_QUOTES ), '\'' );
353
+
354
+ // If the optin is only to be shown on specific post IDs, get the code and break.
355
+ if ( ! empty( $fields['only'] ) ) {
356
+ if ( $post_id && in_array( $post_id, (array) $fields['only'] ) ) {
357
+ $content .= $html;
358
+ $this->set_slug( $optin );
359
+ continue;
360
+ }
361
+ }
362
+
363
+ // Exclude posts/pages from optin display.
364
+ if ( ! empty( $fields['never'] ) ) {
365
+ if ( $post_id && in_array( $post_id, (array) $fields['never'] ) ) {
366
+ continue;
367
+ }
368
+ }
369
+
370
+ // If the optin is only to be shown on particular categories, get the code and break.
371
+ if ( ! empty( $fields['categories'] ) && ( 'post' == get_post_type() ) ) {
372
+ // If this is the home page, check to see if they have decided to load on certain archive pages.
373
+ if ( is_home() ) {
374
+ // Run a check for archive-type pages.
375
+ if ( ! empty( $fields['show'] ) ) {
376
+ // If showing on index pages and we are on an index page, show the optin.
377
+ if ( in_array( 'index', (array) $fields['show'] ) ) {
378
+ if ( is_front_page() || is_home() || is_archive() || is_search() ) {
379
+ $content .= $html;
380
+ $this->set_slug( $optin );
381
+ continue;
382
+ }
383
+ }
384
+
385
+ // Check if we should show on a selected post type.
386
+ if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_archive() || is_search() ) ) {
387
+ $content .= $html;
388
+ $this->set_slug( $optin );
389
+ continue;
390
+ }
391
+ }
392
+ }
393
+
394
+ $categories = wp_get_object_terms( $post_id, 'category', array( 'fields' => 'ids' ) );
395
+ foreach ( (array) $categories as $category_id ) {
396
+ if ( $category_id && in_array( $category_id, $fields['categories'] ) && ! is_archive() ) {
397
+ $content .= $html;
398
+ $this->set_slug( $optin );
399
+ continue 2;
400
+ }
401
+ }
402
+ }
403
+
404
+ // If the optin is only to be shown on particular taxonomies, get the code and break.
405
+ if ( ! empty( $fields['taxonomies'] ) && ( is_singular() ) ) {
406
+ // If this is the home page, check to see if they have decided to load on certain archive pages.
407
+ if ( is_home() ) {
408
+ // Run a check for archive-type pages.
409
+ if ( ! empty( $fields['show'] ) ) {
410
+ // If showing on index pages and we are on an index page, show the optin.
411
+ if ( in_array( 'index', (array) $fields['show'] ) ) {
412
+ if ( is_front_page() || is_home() || is_archive() || is_search() ) {
413
+ $content .= $html;
414
+ $this->set_slug( $optin );
415
+ continue;
416
+ }
417
+ }
418
+
419
+ // Check if we should show on a selected post type.
420
+ if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_archive() || is_search() ) ) {
421
+ $content .= $html;
422
+ $this->set_slug( $optin );
423
+ continue;
424
+ }
425
+ }
426
+ }
427
+
428
+ $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
429
+ $taxonomies['post_tag'] = 'post_tag';
430
+ $taxonomies['post_format'] = 'post_format';
431
+ $taxonomies = wp_get_object_terms( $post_id, $taxonomies, array( 'fields' => 'ids' ) );
432
+ foreach ( $fields['taxonomies'] as $taxonomy => $taxonomy_id ) {
433
+ $tax_ids = explode(',', $taxonomy_id[0] );
434
+ foreach ( $tax_ids as $tax_id ) {
435
+ if ( $post_id && $tax_id && has_term( $tax_id, $taxonomy, $post_id ) ) {
436
+ $content .= $html;
437
+ $this->set_slug( $optin );
438
+ continue 2;
439
+ }
440
+ }
441
+ }
442
+ }
443
+
444
+ // Run a check for specific post types.
445
+ if ( ! empty( $fields['show'] ) ) {
446
+ // Check if we should show on a selected post type.
447
+ if ( in_array( get_post_type(), (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
448
+ $content .= $html;
449
+ $this->set_slug( $optin );
450
+ continue;
451
+ }
452
+ }
453
+
454
+ // If WooCommerce is enabled we can look for WooCommerce specific settings.
455
+ if ( $this->base->is_woocommerce_active() ) {
456
+
457
+ // is_woocommerce anything
458
+ if ( isset( $fields['show_on_woocommerce'] ) && $fields['show_on_woocommerce'] ) {
459
+ if( is_woocommerce() ) {
460
+ $content .= $html;
461
+ $this->set_slug( $optin );
462
+ continue;
463
+ }
464
+ }
465
+ // is_product
466
+ if ( isset( $fields['is_wc_product'] ) && $fields['is_wc_product'] ) {
467
+ $global = false;
468
+ if( is_product() ) {
469
+ $content .= $html;
470
+ $this->set_slug( $optin );
471
+ continue;
472
+ }
473
+ }
474
+
475
+ // is_cart
476
+ if ( isset( $fields['is_wc_cart'] ) && $fields['is_wc_cart'] ) {
477
+ $global = false;
478
+ if( is_cart() ) {
479
+ $content .= $html;
480
+ $this->set_slug( $optin );
481
+ continue;
482
+ }
483
+ }
484
+
485
+ // is_checkout
486
+ if ( isset( $fields['is_wc_checkout'] ) && $fields['is_wc_checkout'] ) {
487
+ $global = false;
488
+ if( is_checkout() ) {
489
+ $content .= $html;
490
+ $this->set_slug( $optin );
491
+ continue;
492
+ }
493
+ }
494
+
495
+ // is_account_page
496
+ if ( isset( $fields['is_wc_account'] ) && $fields['is_wc_account'] ) {
497
+ $global = false;
498
+ if( is_account_page() ) {
499
+ $content .= $html;
500
+ $this->set_slug( $optin );
501
+ continue;
502
+ }
503
+ }
504
+
505
+ // is_wc_endpoint_url
506
+ if ( isset( $fields['is_wc_endpoint'] ) && $fields['is_wc_endpoint'] ) {
507
+ $global = false;
508
+ if( is_wc_endpoint_url() ) {
509
+ $content .= $html;
510
+ $this->set_slug( $optin );
511
+ continue;
512
+ }
513
+ }
514
+
515
+ // is_wc_endpoint_url( 'order-pay' )
516
+ if ( isset( $fields['is_wc_endpoint_order_pay'] ) && $fields['is_wc_endpoint_order_pay'] ) {
517
+ $global = false;
518
+ if( is_wc_endpoint_url( 'order-pay' ) ) {
519
+ $content .= $html;
520
+ $this->set_slug( $optin );
521
+ continue;
522
+ }
523
+ }
524
+
525
+ // is_wc_endpoint_url( 'order-received' )
526
+ if ( isset( $fields['is_wc_endpoint_order_received'] ) && $fields['is_wc_endpoint_order_received'] ) {
527
+ $global = false;
528
+ if( is_wc_endpoint_url( 'order-received' ) ) {
529
+ $content .= $html;
530
+ $this->set_slug( $optin );
531
+ continue;
532
+ }
533
+ }
534
+
535
+ // is_wc_endpoint_url( 'view-order' )
536
+ if ( isset( $fields['is_wc_endpoint_view_order'] ) && $fields['is_wc_endpoint_view_order'] ) {
537
+ $global = false;
538
+ if( is_wc_endpoint_url( 'view-order' ) ) {
539
+ $content .= $html;
540
+ $this->set_slug( $optin );
541
+ continue;
542
+ }
543
+ }
544
+
545
+ // is_wc_endpoint_url( 'edit-account' )
546
+ if ( isset( $fields['is_wc_endpoint_edit_account'] ) && $fields['is_wc_endpoint_edit_account'] ) {
547
+ $global = false;
548
+ if( is_wc_endpoint_url( 'edit-account' ) ) {
549
+ $content .= $html;
550
+ $this->set_slug( $optin );
551
+ continue;
552
+ }
553
+ }
554
+
555
+ // is_wc_endpoint_url( 'edit-address' )
556
+ if ( isset( $fields['is_wc_endpoint_edit_address'] ) && $fields['is_wc_endpoint_edit_address'] ) {
557
+ $global = false;
558
+ if( is_wc_endpoint_url( 'edit-address' ) ) {
559
+ $content .= $html;
560
+ $this->set_slug( $optin );
561
+ continue;
562
+ }
563
+ }
564
+
565
+ // is_wc_endpoint_url( 'lost-password' )
566
+ if ( isset( $fields['is_wc_endpoint_lost_password'] ) && $fields['is_wc_endpoint_lost_password'] ) {
567
+ $global = false;
568
+ if( is_wc_endpoint_url( 'lost-password' ) ) {
569
+ $content .= $html;
570
+ $this->set_slug( $optin );
571
+ continue;
572
+ }
573
+ }
574
+
575
+ // is_wc_endpoint_url( 'customer-logout' )
576
+ if ( isset( $fields['is_wc_endpoint_customer_logout'] ) && $fields['is_wc_endpoint_customer_logout'] ) {
577
+ $global = false;
578
+ if( is_wc_endpoint_url( 'customer-logout' ) ) {
579
+ $content .= $html;
580
+ $this->set_slug( $optin );
581
+ continue;
582
+ }
583
+ }
584
+ // is_wc_endpoint_url( 'add-payment-method' )
585
+ if ( isset( $fields['is_wc_endpoint_add_payment_method'] ) && $fields['is_wc_endpoint_add_payment_method'] ) {
586
+ $global = false;
587
+ if( is_wc_endpoint_url( 'add-payment-method' ) ) {
588
+ $content .= $html;
589
+ $this->set_slug( $optin );
590
+ continue;
591
+ }
592
+ }
593
+
594
+
595
+
596
+ }
597
 
598
  // If the optin is set to be automatically displayed, show it.
599
+ if ( isset( $fields['automatic'] ) && $fields['automatic'] && is_singular( 'post' ) ) {
600
+ $content .= $html;
601
+ $this->set_slug( $optin );
602
+ continue;
603
+ }
604
+
605
+ }
606
+
607
+ // Return the content.
608
+ return $content;
609
+
610
+ }
611
+
612
+ /**
613
+ * Possibly loads an optin on a page.
614
+ *
615
+ * @since 1.0.0
616
+ */
617
+ public function load_optinmonster() {
618
+
619
+ // Prepare variables.
620
+ global $post;
621
+ $post_id = get_queried_object_id();
622
+ if ( ! $post_id ) {
623
+ if ( 'page' == get_option( 'show_on_front' ) ) {
624
+ $post_id = get_option( 'page_for_posts' );
625
+ }
626
+ }
627
+ $optins = $this->base->get_optins();
628
+ $init = array();
629
+ $fields = array();
630
+
631
+ // If no optins are found, return early.
632
+ if ( ! $optins ) {
633
+ return;
634
+ }
635
+
636
+ // Loop through each optin and optionally output it on the site.
637
+ foreach ( $optins as $optin ) {
638
+
639
+ // Grab all the fields to check against.
640
+ foreach ( (array) $this->fields as $field ) {
641
+ $fields[ $field ] = get_post_meta( $optin->ID, '_omapi_' . $field, true );
642
+ }
643
+
644
+ // Ensure the optin is enabled. If not, pass over it.
645
+ if ( empty( $fields['enabled'] ) || ! $fields['enabled'] ) {
646
+ continue;
647
+ }
648
+
649
+ // If in legacy test mode but not logged in, skip over the optin.
650
+ if ( isset( $fields['test'] ) && $fields['test'] && ! is_user_logged_in() ) {
651
+ continue;
652
+ }
653
+
654
+ // If the type is a sidebar or after post optin, pass over it.
655
+ if ( isset( $fields['type'] ) && ( 'post' == $fields['type'] || 'sidebar' == $fields['type'] ) ) {
656
+ continue;
657
+ }
658
+
659
+ // If the optin is to be shown only to logged in users but is not logged in, pass over it.
660
+ if ( isset( $fields['users'] ) && 'in' == $fields['users'] && ! is_user_logged_in() ) {
661
+ continue;
662
+ }
663
+
664
+ // If the optin is to be shown only to visitors but is logged in, pass over it.
665
+ if ( isset( $fields['users'] ) && 'out' == $fields['users'] && is_user_logged_in() ) {
666
+ continue;
667
+ }
668
+
669
+ // Check to see if we need to load the WP API helper script.
670
+ if ( isset( $fields['mailpoet'] ) && $fields['mailpoet'] ) {
671
+ $this->wp_helper();
672
+ }
673
+
674
+ // Prepare the optin campaign.
675
+ $html = trim( html_entity_decode( stripslashes( $optin->post_content ), ENT_QUOTES ), '\'' );
676
+ $global = true;
677
+
678
+ // If the optin is only to be shown on specific post IDs, get the code and break.
679
+ if ( ! empty( $fields['only'] ) ) {
680
+ // Set flag for possibly not loading globally.
681
+ $values = array_filter( array_values( $fields['only'] ) );
682
+ if ( ! empty( $values ) ) {
683
+ $global = false;
684
+ }
685
+
686
+ if ( $post_id && in_array( $post_id, (array) $fields['only'] ) ) {
687
+ $init[ $optin->post_name ] = $html;
688
+ $this->set_slug( $optin );
689
+ continue;
690
+ }
691
+ }
692
+
693
+ // Exclude posts/pages from optin display.
694
+ if ( ! empty( $fields['never'] ) ) {
695
+ // No global check on purpose. Global is still true if only this setting is populated.
696
+ if ( $post_id && in_array( $post_id, (array) $fields['never'] ) ) {
697
+ continue;
698
+ }
699
+ }
700
+
701
+ // If the optin is only to be shown on particular categories, get the code and break.
702
+ if ( ! empty( $fields['categories'] ) ) {
703
+ // Set flag for possibly not loading globally.
704
+ $values = array_filter( array_values( $fields['categories'] ) );
705
+ if ( ! empty( $values ) ) {
706
+ $global = false;
707
+ }
708
+
709
+ // Only load for the main "post" post type.
710
+ if ( 'post' == get_post_type() ) {
711
+ // Don't try to load on the blog home page even if a category that is selected appears in the loop.
712
+ if ( is_home() ) {
713
+ // Run a check for archive-type pages.
714
+ if ( ! empty( $fields['show'] ) ) {
715
+ // If showing on index pages and we are on an index page, show the optin.
716
+ if ( in_array( 'index', (array) $fields['show'] ) ) {
717
+ if ( is_front_page() || is_home() || is_search() ) {
718
+ $init[ $optin->post_name ] = $html;
719
+ $this->set_slug( $optin );
720
+ continue;
721
+ }
722
+ }
723
+
724
+ // Check if we should show on the 'post' post type.
725
+ if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
726
+ $init[ $optin->post_name ] = $html;
727
+ $this->set_slug( $optin );
728
+ continue;
729
+ }
730
+ }
731
+ }
732
+
733
+ $categories = wp_get_object_terms( $post_id, 'category', array( 'fields' => 'ids' ) );
734
+
735
+ // Check againts singular.
736
+ foreach ( (array) $categories as $category_id ) {
737
+ if ( $category_id && in_array( $category_id, $fields['categories'] ) ) {
738
+ $init[ $optin->post_name ] = $html;
739
+ $this->set_slug( $optin );
740
+ continue 2;
741
+ }
742
+ }
743
+
744
+ // Check archives.
745
+ if ( is_category( $fields['categories'] ) ) {
746
+ $init[ $optin->post_name ] = $html;
747
+ $this->set_slug( $optin );
748
+ continue;
749
+ }
750
+ }
751
+ }
752
+
753
+ // If the optin is only to be shown on particular taxonomies, get the code and break.
754
+ if ( ! empty( $fields['taxonomies'] ) ) {
755
+ // Set flag for possibly not loading globally.
756
+ $values = array_filter( array_values( $fields['taxonomies'] ) );
757
+ if ( ! empty( $values ) ) {
758
+ foreach ( $values as $i => $value ) {
759
+ $value = array_filter( array_values( $value ) );
760
+ if ( $value ) {
761
+ $global = false;
762
+ break;
763
+ }
764
+ }
765
+ }
766
+
767
+ // If this is the home page, check to see if they have decided to load on certain archive pages.
768
+ if ( is_home() ) {
769
+ // Run a check for archive-type pages.
770
+ if ( ! empty( $fields['show'] ) ) {
771
+ // If showing on index pages and we are on an index page, show the optin.
772
+ if ( in_array( 'index', (array) $fields['show'] ) ) {
773
+ if ( is_front_page() || is_home() || is_search() ) {
774
+ $init[ $optin->post_name ] = $html;
775
+ $this->set_slug( $optin );
776
+ continue;
777
+ }
778
+ }
779
+
780
+ // Check if we should show on the 'post' post type.
781
+ if ( in_array( 'post', (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
782
+ $init[ $optin->post_name ] = $html;
783
+ $this->set_slug( $optin );
784
+ continue;
785
+ }
786
+ }
787
+ }
788
+
789
+ $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
790
+ $taxonomies['post_tag'] = 'post_tag';
791
+ $taxonomies['post_format'] = 'post_format';
792
+ $taxonomies = wp_get_object_terms( $post_id, $taxonomies, array( 'fields' => 'ids' ) );
793
+ foreach ( $fields['taxonomies'] as $taxonomy => $taxonomy_id ) {
794
+ $tax_ids = explode(',', $taxonomy_id[0] );
795
+ foreach ( $tax_ids as $tax_id ) {
796
+ if ( $post_id && $tax_id && has_term( $tax_id, $taxonomy, $post_id ) ) {
797
+ $init[ $optin->post_name ] = $html;
798
+ $this->set_slug( $optin );
799
+ continue 2;
800
+ }
801
+ }
802
+ foreach ( $tax_ids as $tax_id ) {
803
+ if ( is_tag($tax_id) ) {
804
+ $init[ $optin->post_name ] = $html;
805
+ $this->set_slug( $optin );
806
+ continue 2;
807
+ }
808
+ }
809
+ }
810
+ }
811
+
812
+ // Run a check for archive-type pages.
813
+ if ( ! empty( $fields['show'] ) ) {
814
+ // Set flag for possibly not loading globally.
815
+ $values = array_filter( array_values( $fields['show'] ) );
816
+ if ( ! empty( $values ) ) {
817
+ $global = false;
818
+ }
819
+
820
+ // If showing on index pages and we are on an index page, show the optin.
821
+ if ( in_array( 'index', (array) $fields['show'] ) ) {
822
+ if ( is_front_page() || is_home() || is_search() ) {
823
+ $init[ $optin->post_name ] = $html;
824
+ $this->set_slug( $optin );
825
+ continue;
826
+ }
827
+ }
828
+
829
+ // Check if we should show on a selected post type.
830
+ if ( in_array( get_post_type(), (array) $fields['show'] ) && ! ( is_front_page() || is_home() || is_search() ) ) {
831
+ $init[ $optin->post_name ] = $html;
832
+ $this->set_slug( $optin );
833
+ continue;
834
+ }
835
+ }
836
+
837
+ // If WooCommerce is enabled we can look for WooCommerce specific settings.
838
+ if ( $this->base->is_woocommerce_active() ) {
839
+
840
+ // Separate never checks for WooCommerce pages that don't ID match
841
+ if ( ! empty( $fields['never'] ) ) {
842
+ // No global check on purpose. Global is still true if only this setting is populated.
843
+ if ( in_array( wc_get_page_id( 'shop' ), (array) $fields['never'] ) && is_shop() ) {
844
+ continue;
845
+ }
846
+ }
847
+
848
+ // is_woocommerce
849
+ if ( isset( $fields['show_on_woocommerce'] ) && $fields['show_on_woocommerce'] ) {
850
+ $global = false;
851
+ if( is_woocommerce() ) {
852
+ $init[ $optin->post_name ] = $html;
853
+ $this->set_slug( $optin );
854
+ continue;
855
+ }
856
+ }
857
+
858
+ // is_shop
859
+ if ( isset( $fields['is_wc_shop'] ) && $fields['is_wc_shop'] ) {
860
+ $global = false;
861
+ if( is_shop() ) {
862
+ $init[ $optin->post_name ] = $html;
863
+ $this->set_slug( $optin );
864
+ continue;
865
+ }
866
+ }
867
+
868
+ // is_product
869
+ if ( isset( $fields['is_wc_product'] ) && $fields['is_wc_product'] ) {
870
+ $global = false;
871
+ if( is_product() ) {
872
+ $init[ $optin->post_name ] = $html;
873
+ $this->set_slug( $optin );
874
+ continue;
875
+ }
876
+ }
877
+
878
+ // is_cart
879
+ if ( isset( $fields['is_wc_cart'] ) && $fields['is_wc_cart'] ) {
880
+ $global = false;
881
+ if( is_cart() ) {
882
+ $init[ $optin->post_name ] = $html;
883
+ $this->set_slug( $optin );
884
+ continue;
885
+ }
886
+ }
887
+
888
+ // is_checkout
889
+ if ( isset( $fields['is_wc_checkout'] ) && $fields['is_wc_checkout'] ) {
890
+ $global = false;
891
+ if( is_checkout() ) {
892
+ $init[ $optin->post_name ] = $html;
893
+ $this->set_slug( $optin );
894
+ continue;
895
+ }
896
+ }
897
+
898
+ // is_account_page
899
+ if ( isset( $fields['is_wc_account'] ) && $fields['is_wc_account'] ) {
900
+ $global = false;
901
+ if( is_account_page() ) {
902
+ $init[ $optin->post_name ] = $html;
903
+ $this->set_slug( $optin );
904
+ continue;
905
+ }
906
+ }
907
+
908
+ // is_wc_endpoint_url
909
+ if ( isset( $fields['is_wc_endpoint'] ) && $fields['is_wc_endpoint'] ) {
910
+ $global = false;
911
+ if( is_wc_endpoint_url() ) {
912
+ $init[ $optin->post_name ] = $html;
913
+ $this->set_slug( $optin );
914
+ continue;
915
+ }
916
+ }
917
+
918
+ // is_wc_endpoint_url( 'order-pay' )
919
+ if ( isset( $fields['is_wc_endpoint_order_pay'] ) && $fields['is_wc_endpoint_order_pay'] ) {
920
+ $global = false;
921
+ if( is_wc_endpoint_url( 'order-pay' ) ) {
922
+ $init[ $optin->post_name ] = $html;
923
+ $this->set_slug( $optin );
924
+ continue;
925
+ }
926
+ }
927
+
928
+ // is_wc_endpoint_url( 'order-received' )
929
+ if ( isset( $fields['is_wc_endpoint_order_received'] ) && $fields['is_wc_endpoint_order_received'] ) {
930
+ $global = false;
931
+ if( is_wc_endpoint_url( 'order-received' ) ) {
932
+ $init[ $optin->post_name ] = $html;
933
+ $this->set_slug( $optin );
934
+ continue;
935
+ }
936
+ }
937
+
938
+ // is_wc_endpoint_url( 'view-order' )
939
+ if ( isset( $fields['is_wc_endpoint_view_order'] ) && $fields['is_wc_endpoint_view_order'] ) {
940
+ $global = false;
941
+ if( is_wc_endpoint_url( 'view-order' ) ) {
942
+ $init[ $optin->post_name ] = $html;
943
+ $this->set_slug( $optin );
944
+ continue;
945
+ }
946
+ }
947
+
948
+ // is_wc_endpoint_url( 'edit-account' )
949
+ if ( isset( $fields['is_wc_endpoint_edit_account'] ) && $fields['is_wc_endpoint_edit_account'] ) {
950
+ $global = false;
951
+ if( is_wc_endpoint_url( 'edit-account' ) ) {
952
+ $init[ $optin->post_name ] = $html;
953
+ $this->set_slug( $optin );
954
+ continue;
955
+ }
956
+ }
957
+
958
+ // is_wc_endpoint_url( 'edit-address' )
959
+ if ( isset( $fields['is_wc_endpoint_edit_address'] ) && $fields['is_wc_endpoint_edit_address'] ) {
960
+ $global = false;
961
+ if( is_wc_endpoint_url( 'edit-address' ) ) {
962
+ $init[ $optin->post_name ] = $html;
963
+ $this->set_slug( $optin );
964
+ continue;
965
+ }
966
+ }
967
+
968
+ // is_wc_endpoint_url( 'lost-password' )
969
+ if ( isset( $fields['is_wc_endpoint_lost_password'] ) && $fields['is_wc_endpoint_lost_password'] ) {
970
+ $global = false;
971
+ if( is_wc_endpoint_url( 'lost-password' ) ) {
972
+ $init[ $optin->post_name ] = $html;
973
+ $this->set_slug( $optin );
974
+ continue;
975
+ }
976
+ }
977
+
978
+ // is_wc_endpoint_url( 'customer-logout' )
979
+ if ( isset( $fields['is_wc_endpoint_customer_logout'] ) && $fields['is_wc_endpoint_customer_logout'] ) {
980
+ $global = false;
981
+ if( is_wc_endpoint_url( 'customer-logout' ) ) {
982
+ $init[ $optin->post_name ] = $html;
983
+ $this->set_slug( $optin );
984
+ continue;
985
+ }
986
+ }
987
+ // is_wc_endpoint_url( 'add-payment-method' )
988
+ if ( isset( $fields['is_wc_endpoint_add_payment_method'] ) && $fields['is_wc_endpoint_add_payment_method'] ) {
989
+ $global = false;
990
+ if( is_wc_endpoint_url( 'add-payment-method' ) ) {
991
+ $init[ $optin->post_name ] = $html;
992
+ $this->set_slug( $optin );
993
+ continue;
994
+ }
995
+ }
996
+
997
+
998
+ }
999
+
1000
+ // If we should be loading globally, do it now.
1001
+ if ( $global ) {
1002
+ $init[ $optin->post_name ] = $html;
1003
+ $this->set_slug( $optin );
1004
+ continue;
1005
+ }
1006
+
1007
+ // Allow devs to filter the final output for more granular control over optin targeting.
1008
+ // Devs should return the value for the slug key as false if the conditions are not met.
1009
+ $init = apply_filters( 'optinmonster_output', $init ); // Deprecated.
1010
+ $init = apply_filters( 'optin_monster_output', $init, $optin, $fields, $post_id ); // Deprecated.
1011
+ $init = apply_filters( 'optin_monster_api_output', $init, $optin, $fields, $post_id );
1012
+ }
1013
+
1014
+ // Run a final filter for all items.
1015
+ $init = apply_filters( 'optin_monster_api_final_output', $init, $post_id );
1016
+
1017
+ // If the init code is empty, do nothing.
1018
+ if ( empty( $init ) ) {
1019
+ return;
1020
+ }
1021
+
1022
+ // Load the optins.
1023
+ foreach ( (array) $init as $optin ) {
1024
+ if ( $optin ) {
1025
+ echo $optin;
1026
+ }
1027
+ }
1028
 
1029
  }
1030
 
1031
  /**
1032
+ * Sets the slug for possibly parsing shortcodes.
1033
+ *
1034
+ * @since 1.0.0
1035
+ *
1036
+ * @param object $optin The optin object.
1037
+ */
1038
  public function set_slug( $optin ) {
1039
 
1040
  // Set the slug.
1041
+ $this->slugs[ str_replace( '-', '_', $optin->post_name ) ] = array(
1042
+ 'slug' => str_replace( '-', '_', $optin->post_name ),
1043
+ 'mailpoet' => (bool) get_post_meta( $optin->ID, '_omapi_mailpoet', true )
1044
+ );
1045
 
1046
  // Maybe set shortcode.
1047
  $shortcode = get_post_meta( $optin->ID, '_omapi_shortcode', true );
1052
  }
1053
 
1054
  /**
1055
+ * Maybe outputs the JS variables to parse shortcodes.
1056
+ *
1057
+ * @since 1.0.0
1058
+ */
1059
  public function maybe_parse_shortcodes() {
1060
 
1061
  // If no slugs have been set, do nothing.
1088
  }
1089
 
1090
  // Output the JS variables to signify shortcode parsing is needed.
1091
+ ?>
1092
+ <script type="text/javascript"><?php foreach ( $this->slugs as $slug => $data ) { echo 'var ' . $slug . '_shortcode = true;'; } ?></script>
1093
+ <?php
1094
 
1095
  }
1096
 
1097
  /**
1098
+ * Possibly localizes a JS variable for output use.
1099
+ *
1100
+ * @since 1.0.0
1101
+ */
1102
+ public function localize() {
1103
+
1104
+ // If no slugs have been set, do nothing.
1105
+ if ( empty( $this->slugs ) ) {
1106
+ return;
1107
+ }
1108
+
1109
+ // If already localized, do nothing.
1110
+ if ( $this->localized ) {
1111
+ return;
1112
+ }
1113
+
1114
+ // Set flag to true.
1115
+ $this->localized = true;
1116
+
1117
+ // Output JS variable.
1118
+ ?>
1119
+ <script type="text/javascript">var omapi_localized = { ajax: '<?php echo esc_url_raw( add_query_arg( 'optin-monster-ajax-route', true, admin_url( 'admin-ajax.php' ) ) ); ?>', nonce: '<?php echo wp_create_nonce( 'omapi' ); ?>', slugs: <?php echo json_encode( $this->slugs ); ?> };</script>
1120
+ <?php
1121
 
1122
  }
1123
 
1124
  /**
1125
+ * Outputs the WP helper script for storing local optins.
1126
+ *
1127
+ * @since 1.0.0
1128
+ */
1129
  public function wp_helper() {
1130
 
1131
  wp_enqueue_script(
1132
+ $this->base->plugin_slug . '-wp-helper',
1133
+ plugins_url( 'assets/js/helper.js', OMAPI_FILE ),
1134
+ array( 'jquery'),
1135
+ $this->base->version,
1136
+ true
1137
+ );
1138
 
1139
  }
1140
 
OMAPI/Save.php CHANGED
@@ -90,6 +90,11 @@ class OMAPI_Save {
90
  return;
91
  }
92
 
 
 
 
 
 
93
  // Verify the nonce field.
94
  check_admin_referer( 'omapi_nonce_' . $this->view, 'omapi_nonce_' . $this->view );
95
 
90
  return;
91
  }
92
 
93
+ // Run a current user check on saving.
94
+ if ( ! current_user_can( apply_filters( 'optin_monster_api_save_cap', 'manage_options' ) ) ) {
95
+ return;
96
+ }
97
+
98
  // Verify the nonce field.
99
  check_admin_referer( 'omapi_nonce_' . $this->view, 'omapi_nonce_' . $this->view );
100
 
assets/js/clipboard.min.js CHANGED
File without changes
assets/js/helper.js CHANGED
@@ -6,15 +6,28 @@
6
  * ========================================================== */
7
  jQuery(document).ready(function($){
8
  $(document).on('OptinMonsterPreOptin', function(event, optin, object){
9
- // Send a request to force optin to work even if no provider is set.
10
- var data = optin.optin_data;
11
- data.no_provider = true;
12
- object.setProp('optin_data', data);
13
-
14
- // Now make an ajax request to make the optin locally.
15
- data.action = 'mailpoet';
16
- data.nonce = omapi_localized.nonce;
17
- data.optin = optin.original_optin;
18
- $.post(omapi_localized.ajax, data, function(){}, 'json');
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  });
20
  });
6
  * ========================================================== */
7
  jQuery(document).ready(function($){
8
  $(document).on('OptinMonsterPreOptin', function(event, optin, object){
9
+ $.each(omapi_localized.slugs, function(i, v) {
10
+
11
+ if ( i !== optin.optin ) {
12
+ return;
13
+ }
14
+
15
+ if ( ! v.mailpoet ) {
16
+ return;
17
+ }
18
+
19
+ // Send a request to force optin to work even if no provider is set.
20
+ var data = optin.optin_data;
21
+ data.no_provider = true;
22
+ object.setProp('optin_data', data);
23
+
24
+ // Now make an ajax request to make the optin locally.
25
+ data.action = 'mailpoet';
26
+ data.nonce = omapi_localized.nonce;
27
+ data.optin = optin.original_optin;
28
+ $.post(omapi_localized.ajax, data, function(){}, 'json');
29
+
30
+ return false;
31
+ });
32
  });
33
  });
assets/js/jspdf.min.js CHANGED
File without changes
optin-monster-wp-api.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: OptinMonster API plugin to connect your WordPress site to your OptinMonster forms.
6
  * Author: OptinMonster Team
7
  * Author URI: https://optinmonster.com
8
- * Version: 1.2.0
9
  * Text Domain: optin-monster-api
10
  * Domain Path: languages
11
  *
@@ -60,7 +60,7 @@ class OMAPI {
60
  *
61
  * @var string
62
  */
63
- public $version = '1.2.0';
64
 
65
  /**
66
  * The name of the plugin.
5
  * Description: OptinMonster API plugin to connect your WordPress site to your OptinMonster forms.
6
  * Author: OptinMonster Team
7
  * Author URI: https://optinmonster.com
8
+ * Version: 1.2.1
9
  * Text Domain: optin-monster-api
10
  * Domain Path: languages
11
  *
60
  *
61
  * @var string
62
  */
63
+ public $version = '1.2.1';
64
 
65
  /**
66
  * The name of the plugin.
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: optinmonster, griffinjt, smub
3
  Tags: wordpress popup, popup, lightbox popup, mailchimp, aweber, campaign monitor, constant contact, exit-intent, madmimi, infusionsoft, getresponse, hubspot, marketo, activecampaign, pardot, totalsend, emma, icontact, mailerlite, mailpoet, google analytics, pop over, optin forms, email list, subscribers, wordpress popup form, lightbox, wordpress popups, popups, lightbox popups, optin form, wordpress optin form, sidebar optin form, sidebar optin, sidebar form, wordpress overlay popup, wordpress popup plugin, popup plugin, wordpress lightbox optin, wordpress lightbox optin form, after post optin form, wordpress after post optin form, after post optin form plugin, lightbox popup plugin, wordpress popup solution, exit intent, exit-intent, optinmonster, optin monster, optin-monster, mobile popup, mobile popups, mobile optin forms, mobile optins, lightbox optins, wordpress mobile popup, wordpress mobile popups, wordpress mobile optin forms, wordpress lightbox optins, lead gen, lead generation, wordpress lead generation, lead generation wordpress, wordpress lead gen, fullscreen, welcome gate, interstitial
4
  Requires at least: 3.5.1
5
  Tested up to: 4.8
6
- Stable tag: 1.2.0
7
  License: GNU General Public License v2.0 or later
8
 
9
  OptinMonster helps you grow your email list by converting visitors into subscribers and customers. Get more email subscribers now!
@@ -160,6 +160,9 @@ OptinMonster is the <a href="http://optinmonster.com" rel="friend" title="OptinM
160
 
161
  == Changelog ==
162
 
 
 
 
163
  = 1.2.0 =
164
  * Added additional support for WooCommerce display settings.
165
  * Updated language for legacy migrations.
3
  Tags: wordpress popup, popup, lightbox popup, mailchimp, aweber, campaign monitor, constant contact, exit-intent, madmimi, infusionsoft, getresponse, hubspot, marketo, activecampaign, pardot, totalsend, emma, icontact, mailerlite, mailpoet, google analytics, pop over, optin forms, email list, subscribers, wordpress popup form, lightbox, wordpress popups, popups, lightbox popups, optin form, wordpress optin form, sidebar optin form, sidebar optin, sidebar form, wordpress overlay popup, wordpress popup plugin, popup plugin, wordpress lightbox optin, wordpress lightbox optin form, after post optin form, wordpress after post optin form, after post optin form plugin, lightbox popup plugin, wordpress popup solution, exit intent, exit-intent, optinmonster, optin monster, optin-monster, mobile popup, mobile popups, mobile optin forms, mobile optins, lightbox optins, wordpress mobile popup, wordpress mobile popups, wordpress mobile optin forms, wordpress lightbox optins, lead gen, lead generation, wordpress lead generation, lead generation wordpress, wordpress lead gen, fullscreen, welcome gate, interstitial
4
  Requires at least: 3.5.1
5
  Tested up to: 4.8
6
+ Stable tag: 1.2.1
7
  License: GNU General Public License v2.0 or later
8
 
9
  OptinMonster helps you grow your email list by converting visitors into subscribers and customers. Get more email subscribers now!
160
 
161
  == Changelog ==
162
 
163
+ = 1.2.1 =
164
+ * Added additional checks during save routines for user capabilities.
165
+
166
  = 1.2.0 =
167
  * Added additional support for WooCommerce display settings.
168
  * Updated language for legacy migrations.