PluginProbe
GetResponse Forms by Optin Cat / 1.4.2
GetResponse Forms by Optin Cat v1.4.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.4.2, at includes/eoi-init.php

192 lines 5.0 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 if ( ! $this->is_new_css_notification_dismissed() ) {
112 $this->show_new_css_notification();
113 }
114
115 $flash_notification_id = get_user_meta( $current_user_id, $this->keys['flash_notification_id'] );
116
117 if ( ! empty( $flash_notification_id ) ) {
118 delete_user_meta( $current_user_id, $this->keys['flash_notification_id'] );
119
120 if ( $flash_notification_id == $this->flash_notification_ids['new_css_activated'] ) {
121 $this->show_new_css_activated_notification();
122 }
123 }
124 }
125
126 private function set_flash_notification_id( $flash_notification_id ) {
127 update_user_meta(
128 $GLOBALS['current_user']->ID,
129 $this->keys['flash_notification_id'],
130 $flash_notification_id
131 );
132 }
133
134 public function process_actions() {
135 if ( isset( $_REQUEST[ $this->keys['new_css']['activate_action'] ] ) ) {
136 $this->process_new_css_activation( (boolean) $_REQUEST[ $this->keys['new_css']['activate_action'] ] );
137 }
138 }
139
140 private function show_new_css_notification() {
141 ?>
142
143 <div class="updated">
144 <p>
145 This version of Optin Cat comes with all new CSS for improved theme compatibility
146 and mobile friendliness.
147 <a href="https://fatcatapps.com/optin-cat-1-3#new-css">Click here to learn more</a>.
148 </p>
149
150 <p>
151 Activate new CSS?
152 <a href="<?php echo add_query_arg( $this->keys['new_css']['activate_action'], 1 ) ?>">Yes</a> |
153 <a href="<?php echo add_query_arg( $this->keys['new_css']['activate_action'], 0 ) ?>">No</a>
154 </p>
155 </div>
156
157 <?php
158 }
159
160 private function process_new_css_activation( $activate ) {
161 $this->set_new_css_notification_dismissed( true );
162
163 if ( $activate ) {
164 powerup_new_css_set_active( true );
165 $this->set_flash_notification_id( $this->flash_notification_ids['new_css_activated'] );
166 }
167
168 wp_redirect( remove_query_arg( $this->keys['new_css']['activate_action'] ) );
169 exit;
170 }
171
172 private function show_new_css_activated_notification() {
173 ?>
174
175 <div class="updated">
176 <p>
177 New CSS enabled. Please double check your optin forms for possible CSS display issues.
178 </p>
179 </div>
180
181 <?php
182 }
183
184 public function is_new_css_notification_dismissed() {
185 return get_user_meta( $GLOBALS['current_user']->ID, $this->keys['new_css']['notification_dismissed'] );
186 }
187
188 public function set_new_css_notification_dismissed( $dismissed ) {
189 return update_user_meta( $GLOBALS['current_user']->ID, $this->keys['new_css']['notification_dismissed'], $dismissed );
190 }
191 }
192