PluginProbe
GetResponse Forms by Optin Cat / 1.5.2
GetResponse Forms by Optin Cat v1.5.2
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / includes / eoi-init.php

eoi-init.php in GetResponse Forms by Optin Cat 1.5.2, at includes/eoi-init.php

193 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
4
5 class EasyOptInsInit {
6 private $keys = array(
7 'plugin_version' => 'fca_eoi_plugin_version',
8 'flash_notification_id' => 'fca_eoi_init_flash_notification_id',
9 'new_css' => array(
10 'notification_dismissed' => 'fca_eoi_is_notification_activate_new_css_dismissed',
11 'activate_action' => 'fca_eoi_action_activate_new_css'
12 )
13 );
14
15 private $flash_notification_ids = array(
16 'new_css_activated' => 1
17 );
18
19 private static $instance;
20
21 public static function get_instance() {
22 if ( ! self::$instance ) {
23 self::$instance = new self;
24 }
25
26 return self::$instance;
27 }
28
29 private function require_new_css() {
30 $powerup_path = dirname( __FILE__ ) . '/../powerups/4_new_css/powerup.php';
31
32 if ( file_exists( $powerup_path ) ) {
33 require_once $powerup_path;
34 return true;
35 }
36
37 return false;
38 }
39
40 public function on_install() {
41 if ( $this->require_new_css() ) {
42 powerup_new_css_set_active( true );
43 $this->set_new_css_notification_dismissed( true );
44 }
45 }
46
47 public function on_uninstall() {
48 delete_option( $this->keys['plugin_version'] );
49 }
50
51 private function on_upgrade( $old_version, $new_version ) {
52 if ( $this->require_new_css() ) {
53 if ( $new_version == '1.3.2' && powerup_new_css_is_active() ) {
54 require_once dirname( __FILE__ ) . '/eoi-layout.php';
55
56 powerup_new_css_set_active( false );
57 powerup_new_css_set_active( true );
58 }
59 }
60 }
61
62 public function on_activate() {
63 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
64 $plugin_data = get_plugin_data( FCA_EOI_PLUGIN_FILE );
65
66 $new_version = $plugin_data['Version'];
67 $old_version = get_option( $this->keys['plugin_version'] );
68 if ( empty( $old_version ) && $this->has_forms() ) {
69 $old_version = '1.2';
70 }
71
72 if ( empty( $old_version ) ) {
73 $this->on_install();
74 } elseif ( version_compare( $old_version, $new_version, '<' ) ) {
75 $this->on_upgrade( $old_version, $new_version );
76 }
77 }
78
79 public function setup() {
80 add_action( 'admin_notices', array( $this, 'show_notifications' ) );
81 add_action( 'admin_init', array( $this, 'admin_init' ) );
82 }
83
84 public function admin_init() {
85 $this->save_plugin_version();
86 $this->process_actions();
87 }
88
89 private function has_forms() {
90 global $wpdb;
91
92 $query = "
93 SELECT COUNT(*)
94 FROM $wpdb->posts
95 WHERE post_type = 'easy-opt-ins' AND ( post_status = 'publish' OR post_status = 'trash' )
96 LIMIT 1
97 ";
98
99 return (int) $wpdb->get_var( $query, 0, 0 ) > 0;
100 }
101
102 public function save_plugin_version() {
103 $plugin_data = get_plugin_data( FCA_EOI_PLUGIN_FILE );
104
105 update_option( $this->keys['plugin_version'], $plugin_data['Version'] );
106 }
107
108 public function show_notifications() {
109 $current_user_id = $GLOBALS['current_user']->ID;
110
111 /* RN NOTE: DISABLE NEW CSS NOTIFICATIONS, EVERYONE IS GOING TO NEW CSS @SINCE 1.5.0 */
112 // if ( ! $this->is_new_css_notification_dismissed() ) {
113 // $this->show_new_css_notification();
114 // }
115
116 $flash_notification_id = get_user_meta( $current_user_id, $this->keys['flash_notification_id'] );
117
118 if ( ! empty( $flash_notification_id ) ) {
119 delete_user_meta( $current_user_id, $this->keys['flash_notification_id'] );
120
121 if ( $flash_notification_id == $this->flash_notification_ids['new_css_activated'] ) {
122 $this->show_new_css_activated_notification();
123 }
124 }
125 }
126
127 private function set_flash_notification_id( $flash_notification_id ) {
128 update_user_meta(
129 $GLOBALS['current_user']->ID,
130 $this->keys['flash_notification_id'],
131 $flash_notification_id
132 );
133 }
134
135 public function process_actions() {
136 if ( isset( $_REQUEST[ $this->keys['new_css']['activate_action'] ] ) ) {
137 $this->process_new_css_activation( (boolean) $_REQUEST[ $this->keys['new_css']['activate_action'] ] );
138 }
139 }
140
141 private function show_new_css_notification() {
142 ?>
143
144 <div class="updated">
145 <p>
146 This version of Optin Cat comes with all new CSS for improved theme compatibility
147 and mobile friendliness.
148 <a href="https://fatcatapps.com/optin-cat-1-3#new-css">Click here to learn more</a>.
149 </p>
150
151 <p>
152 Activate new CSS?
153 <a href="<?php echo add_query_arg( $this->keys['new_css']['activate_action'], 1 ) ?>">Yes</a> |
154 <a href="<?php echo add_query_arg( $this->keys['new_css']['activate_action'], 0 ) ?>">No</a>
155 </p>
156 </div>
157
158 <?php
159 }
160
161 private function process_new_css_activation( $activate ) {
162 $this->set_new_css_notification_dismissed( true );
163
164 if ( $activate ) {
165 powerup_new_css_set_active( true );
166 $this->set_flash_notification_id( $this->flash_notification_ids['new_css_activated'] );
167 }
168
169 wp_redirect( remove_query_arg( $this->keys['new_css']['activate_action'] ) );
170 exit;
171 }
172
173 private function show_new_css_activated_notification() {
174 ?>
175
176 <div class="updated">
177 <p>
178 New CSS enabled. Please double check your optin forms for possible CSS display issues.
179 </p>
180 </div>
181
182 <?php
183 }
184
185 public function is_new_css_notification_dismissed() {
186 return get_user_meta( $GLOBALS['current_user']->ID, $this->keys['new_css']['notification_dismissed'] );
187 }
188
189 public function set_new_css_notification_dismissed( $dismissed ) {
190 return update_user_meta( $GLOBALS['current_user']->ID, $this->keys['new_css']['notification_dismissed'], $dismissed );
191 }
192 }
193