contact-forms
1 year ago
contact-forms.php
1 year ago
fluent-booking.php
9 months ago
index.php
1 month ago
newsletters.php
1 year ago
recommendation-page-post-type.php
1 year ago
recommendations-trait.php
3 months ago
siteleads.php
3 months ago
newsletters.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | use IlluminateAgnostic\Arr\Support\Arr; |
| 4 | use Kubio\Core\LodashBasic; |
| 5 | |
| 6 | |
| 7 | function kubio_is_recommendation_newsletter_plugin_active() { |
| 8 | if ( ! class_exists( '\Kubio\PluginsManager' ) ) { |
| 9 | return false; |
| 10 | } |
| 11 | $manager = \Kubio\PluginsManager::getInstance(); |
| 12 | |
| 13 | return $manager->isPluginActive( 'iconvert-promoter' ); |
| 14 | } |
| 15 | |
| 16 | function kubio_get_recommendation_newsletters() { |
| 17 | if ( ! kubio_is_recommendation_newsletter_plugin_active() ) { |
| 18 | return array(); |
| 19 | } |
| 20 | |
| 21 | $args = array( |
| 22 | 'post_type' => 'cs-promo-popups', |
| 23 | 'posts_per_page' => - 1, |
| 24 | ); |
| 25 | |
| 26 | $query = new WP_Query( $args ); |
| 27 | |
| 28 | if ( ! $query->have_posts() ) { |
| 29 | return array(); |
| 30 | } |
| 31 | |
| 32 | $posts = $query->posts; |
| 33 | $ignored_popup_types = array( |
| 34 | 'inline-promotion-bar', |
| 35 | 'floating-bar', |
| 36 | ); |
| 37 | |
| 38 | $filtered_posts = array_filter( |
| 39 | $posts, |
| 40 | function ( $post ) use ( $ignored_popup_types ) { |
| 41 | $popup_type = get_post_meta( $post->ID, 'popup_type', true ); |
| 42 | |
| 43 | return ! in_array( $popup_type, $ignored_popup_types, true ); |
| 44 | } |
| 45 | ); |
| 46 | |
| 47 | $mapped = array(); |
| 48 | |
| 49 | foreach ( $filtered_posts as $post ) { |
| 50 | $mapped[] = array( |
| 51 | 'label' => $post->post_title, |
| 52 | 'value' => $post->ID, |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | return $mapped; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | |
| 61 | function kubio_recommendation_set_click_promo_popup_triggers( $promoId ) { |
| 62 | if ( empty( $promoId ) ) { |
| 63 | return; |
| 64 | } |
| 65 | $identifier = kubio_recommendation_popup_get_click_popup_selector( $promoId ); |
| 66 | |
| 67 | $metas = get_post_meta( $promoId, 'triggers', true ); |
| 68 | |
| 69 | Arr::set( $metas, 'on-click.0', 'advanced' ); |
| 70 | Arr::set( $metas, 'on-click.checkbox', true ); |
| 71 | Arr::set( $metas, 'on-click.1', $identifier ); |
| 72 | |
| 73 | //disable the page load popup when moving to on click |
| 74 | //These disables are temporary until it gets fixed in the promo the issue with other condition + click condition |
| 75 | Arr::set( $metas, 'page-load.checkbox', false ); |
| 76 | Arr::set( $metas, 'after-inactivity.checkbox', false ); |
| 77 | update_post_meta( $promoId, 'triggers', $metas ); |
| 78 | |
| 79 | $isActive = get_post_meta( $promoId, 'active', true ); |
| 80 | if ( $isActive !== true ) { |
| 81 | update_post_meta( $promoId, 'active', '1' ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | function kubio_recommendation_popup_get_click_popup_selector( $id ) { |
| 86 | return "[data-kubio-email-capture-popup-$id]"; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | function kubio_recommendations_create_promo_popup( $popup_data ) { |
| 91 | |
| 92 | if ( ! class_exists( '\CSPromo\Core\Admin\PopupService' ) || |
| 93 | ! method_exists( '\CSPromo\Core\Admin\PopupService', 'create' ) ) { |
| 94 | return null; |
| 95 | } |
| 96 | |
| 97 | if ( empty( $popup_data ) ) { |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | $promo_type = LodashBasic::get( $popup_data, 'type' ); |
| 102 | if ( empty( $promo_type ) ) { |
| 103 | return null; |
| 104 | } |
| 105 | |
| 106 | $popup_settings = array( |
| 107 | 'promoType' => 'simple-popup', |
| 108 | 'position' => 'center#center', |
| 109 | 'effectsSides' => |
| 110 | array( |
| 111 | 'in' => 'In', |
| 112 | 'out' => 'Out', |
| 113 | ), |
| 114 | 'animationIn' => 'effectSliding#slideInDown', |
| 115 | 'animationOut' => 'effectSliding#slideOutDown', |
| 116 | ); |
| 117 | |
| 118 | $popup_data['name'] = __( 'Email capture popup 1', 'kubio' ); |
| 119 | |
| 120 | $popup_by_click_id = \CSPromo\Core\Admin\PopupService::create( $popup_data, $popup_settings ); |
| 121 | |
| 122 | add_post_meta( |
| 123 | $popup_by_click_id, |
| 124 | 'kubio_recommendation_popup', |
| 125 | true, |
| 126 | true |
| 127 | ); |
| 128 | |
| 129 | return $popup_by_click_id; |
| 130 | } |
| 131 |