1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Offers FooVideo users a discount on FooGallery PRO |
4
|
|
|
*/ |
5
|
|
|
if ( ! class_exists( 'FooGallery_FooVideo_Compatibility' ) ) { |
6
|
|
|
|
7
|
|
|
class FooGallery_FooVideo_Compatibility { |
|
|
|
|
8
|
|
|
|
9
|
|
|
const option_discount_key = 'foogallery_video_discount'; |
10
|
|
|
|
11
|
|
|
function __construct() { |
|
|
|
|
12
|
|
|
//check if the old FooVideo is still activated |
13
|
|
|
if ( is_admin() && $this->show_discount_message() ) { |
14
|
|
|
add_action( 'admin_notices', array( $this, 'display_discount_notice') ); |
15
|
|
|
add_action( 'admin_menu', array( $this, 'add_discount_menu' ) ); |
16
|
|
|
|
17
|
|
|
// Ajax calls |
18
|
|
|
add_action( 'wp_ajax_foogallery_video_discount_offer', array( $this, 'ajax_foogallery_video_discount_offer' ) ); |
19
|
|
|
add_action( 'wp_ajax_foogallery_video_discount_offer_support', array( $this, 'ajax_foogallery_video_discount_offer_support' ) ); |
20
|
|
|
add_action( 'wp_ajax_foogallery_video_discount_offer_hide', array( $this, 'ajax_foogallery_video_discount_offer_hide' ) ); |
21
|
|
|
|
22
|
|
|
add_action( 'wp_ajax_foogallery_video_discount_dismiss', array( $this, 'admin_notice_dismiss' ) ); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Determines if the discount message should be shown |
28
|
|
|
* |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
|
|
function show_discount_message() { |
|
|
|
|
32
|
|
|
//first try to get the saved option |
33
|
|
|
$show_message = get_option( FooGallery_FooVideo_Compatibility::option_discount_key, 0 ); |
34
|
|
|
|
35
|
|
|
if ( '3' === $show_message ) { |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
//we must show the message - get out early |
40
|
|
|
if ( 0 !== $show_message ) { |
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ( class_exists('Foo_Video') ) { |
45
|
|
|
//the legacy plugin is installed, so set the option for future use |
46
|
|
|
$show_message = true; |
47
|
|
|
|
48
|
|
|
update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '1' ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
//we have no option saved and no legacy plugin, so no discount available |
52
|
|
|
if ( 0 === $show_message ) { |
53
|
|
|
$show_message = false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $show_message; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Display a message if the FooVideo extension is also installed |
61
|
|
|
*/ |
62
|
|
|
function display_discount_notice() { |
|
|
|
|
63
|
|
|
$show_message = get_option( FooGallery_FooVideo_Compatibility::option_discount_key, 0 ); |
64
|
|
|
if ( '1' === $show_message ) { |
65
|
|
|
|
66
|
|
|
$notice_title = apply_filters( 'foogallery_foovideo_discount_offer_notice_title', __( 'FooGallery PRO Discount Available!', 'foogallery' ) ); |
67
|
|
|
$notice_message = apply_filters( 'foogallery_foovideo_discount_offer_notice_message', __( 'We noticed that you own a license for the older FooVideo extension but not for FooGallery PRO, which has all the awesome features of FooVideo, plus more! And because you already own FooVideo, you are eligible for a discount when upgrading to FooGallery PRO.', 'foogallery' ) ); |
68
|
|
|
|
69
|
|
|
$url = admin_url( add_query_arg( array( 'page' => 'foogallery-video-offer' ), foogallery_admin_menu_parent_slug() ) ); |
70
|
|
|
?> |
71
|
|
|
<script type="text/javascript"> |
72
|
|
|
(function ($) { |
73
|
|
|
$(document).ready(function () { |
74
|
|
|
$('.foogallery-foovideo-discount-notice.is-dismissible') |
75
|
|
|
.on('click', '.notice-dismiss', function (e) { |
76
|
|
|
e.preventDefault(); |
77
|
|
|
$.post(ajaxurl, { |
78
|
|
|
action : 'foogallery_video_discount_dismiss', |
79
|
|
|
url : '<?php echo admin_url( 'admin-ajax.php' ); ?>', |
80
|
|
|
_wpnonce: '<?php echo wp_create_nonce( 'foogallery_video_discount_dismiss' ); ?>' |
81
|
|
|
}); |
82
|
|
|
}); |
83
|
|
|
}); |
84
|
|
|
})(jQuery); |
85
|
|
|
</script> |
86
|
|
|
<div class="foogallery-foovideo-discount-notice notice notice-info is-dismissible"> |
87
|
|
|
<p> |
88
|
|
|
<strong><?php echo $notice_title; ?></strong><br /> |
89
|
|
|
<?php echo $notice_message; ?><br /> |
90
|
|
|
<br /> |
91
|
|
|
<a class="button button-primary button-large" href="<?php echo $url; ?>"><?php _e( 'Redeem Now!', 'foogallery' ); ?></a> |
92
|
|
|
</p> |
93
|
|
|
</div> |
94
|
|
|
<?php |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Dismiss the admin notice |
100
|
|
|
*/ |
101
|
|
|
function admin_notice_dismiss() { |
|
|
|
|
102
|
|
|
if ( check_admin_referer( 'foogallery_video_discount_dismiss' ) ) { |
103
|
|
|
update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '2' ); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Outputs the video discount offer view |
109
|
|
|
*/ |
110
|
|
|
function render_video_offer_view() { |
|
|
|
|
111
|
|
|
require_once 'view-foovideo-offer.php'; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Add a new menu item for running the migration |
116
|
|
|
*/ |
117
|
|
|
function add_discount_menu() { |
|
|
|
|
118
|
|
|
$menu = apply_filters( 'foogallery_foovideo_discount_offer_menu', __( 'Discount Offer', 'foogallery' ) ); |
119
|
|
|
|
120
|
|
|
foogallery_add_submenu_page( $menu, 'manage_options', 'foogallery-video-offer', array( $this, 'render_video_offer_view', ) ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
function ajax_foogallery_video_discount_offer() { |
|
|
|
|
124
|
|
|
if ( check_admin_referer( 'foogallery_video_discount_offer' ) ) { |
125
|
|
|
$license_key = get_site_option( 'foo-video_licensekey' ); |
126
|
|
|
|
127
|
|
|
if ( empty( $license_key ) ) { |
128
|
|
|
echo '<h3>' . __( 'No FooVideo License Found!', 'foogallery' ) . '</h3>'; |
129
|
|
|
$settings_link = '<a target="_blank" href="' . foogallery_admin_settings_url() . '#extensions">' . __('FooGallery Settings page', 'foogallery') . '</a>'; |
130
|
|
|
echo '<h4>' . sprintf( __( 'There is no FooVideo license key set for this site. Please set it via the %s under the extensions tab and try again.', 'foogallery' ), $settings_link ) . '</h4>'; |
131
|
|
|
} else { |
132
|
|
|
$license_url = "http://fooplugins.com/api/{$license_key}/licensekey/"; |
133
|
|
|
|
134
|
|
|
//fetch the license info from FooPlugins.com |
135
|
|
|
$response = wp_remote_get( $license_url, array( 'sslverify' => false ) ); |
136
|
|
|
|
137
|
|
|
if( ! is_wp_error( $response ) ) { |
138
|
|
|
|
139
|
|
|
if ( $response['response']['code'] == 200 ) { |
140
|
|
|
$license_details = @json_decode( $response['body'], true ); |
141
|
|
|
|
142
|
|
|
if ( isset( $license_details ) ) { |
143
|
|
|
$coupon = $license_details['coupon']; |
144
|
|
|
|
145
|
|
|
if ( $coupon['valid'] ) { |
146
|
|
|
echo '<h3>' . __( 'Your discount code is : ', 'foogallery' ) . $coupon['code'] . '</h3>'; |
147
|
|
|
echo '<h4>' . __( 'The value of the discount is : ', 'foogallery' ) . $coupon['value'] . '</h4>'; |
148
|
|
|
|
149
|
|
|
$license_option = __( 'Single Site', 'foogallery' ); |
150
|
|
|
if ( 'FooVideo Extension (Multi)' === $license_details['license'] ) { |
151
|
|
|
$license_option = __( '5 Site', 'foogallery' ); |
152
|
|
|
} else if ( 'FooVideo Extension (Business)' === $license_details['license'] ) { |
153
|
|
|
$license_option = __( '25 Site', 'foogallery' ); |
154
|
|
|
} |
155
|
|
|
$license_option = '<strong>' . $license_option . '</strong>'; |
156
|
|
|
$pricing_page_url = foogallery_admin_pricing_url(); |
157
|
|
|
$pricing_page_text = apply_filters( 'foogallery_foovideo_pricing_menu_text', __( 'FooGallery -> Upgrade', 'foogallery' ) ); |
158
|
|
|
$pricing_page_link = '<a target="_blank" href="' . $pricing_page_url . '">' . $pricing_page_text . '</a>'; |
159
|
|
|
|
160
|
|
|
if ( !class_exists( 'FooGallery_Pro_Video' ) ) { |
161
|
|
|
echo sprintf( __( 'Your discount entitles you to a FooGallery PRO - %s license for no additional cost!', 'foogallery' ), $license_option ); |
162
|
|
|
echo '<br />' . sprintf( __( 'Copy the discount code above and use it when purchasing FooGallery PRO from %s (make sure to select %s plan!).', 'foogallery' ), $pricing_page_link, $license_option ); |
163
|
|
|
} else { |
164
|
|
|
echo sprintf( __( 'Your discount entitles you to a free FooGallery PRO - %s license renewal or extension!', 'foogallery' ), $license_option ); |
165
|
|
|
echo '<br />' . sprintf( __( 'Copy the discount code above and use it when extending your FooGallery PRO license from %s (make sure to select the %s plan!).', 'foogallery' ), $pricing_page_link, $license_option ); |
166
|
|
|
} |
167
|
|
|
$doc_link = '<a href="https://fooplugins.link/foovideo-upgrade" target="_blank">' . __( 'read our documentation', 'foogallery' ) . '</a>'; |
168
|
|
|
echo '<br />' . sprintf( __( 'For a more detailed guide on the process, %s.', 'foogallery' ), $doc_link ); |
169
|
|
|
|
170
|
|
|
//redeemed the code - no need to show the admin notice anymore |
171
|
|
|
update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '2' ); |
172
|
|
|
} else { |
173
|
|
|
echo '<h3>' . __( 'Invalid License!', 'foogallery' ) . '</h3>'; |
174
|
|
|
echo '<h4>' .$coupon['code'] . '</h4>'; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
} else { |
180
|
|
|
echo '<h4>'. __('Sorry! There was an error retrieving your discount code from our servers. Please log a support ticket and we will help.', 'foogallery') . '</h4>'; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
die(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
function ajax_foogallery_video_discount_offer_support() { |
|
|
|
|
188
|
|
|
if ( check_admin_referer( 'foogallery_video_discount_offer_support' ) ) { |
189
|
|
|
//send the support email! |
190
|
|
|
$message = $_POST['message']; |
191
|
|
|
if ( wp_mail( '[email protected]', 'FooGallery/FooVideo Discount Offer Query', $message ) ) { |
192
|
|
|
echo __('Support email logged successfully!', 'foogallery' ); |
193
|
|
|
} else { |
194
|
|
|
echo __('We could not log the ticket. Please email [email protected] directly.', 'foogallery' ); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
die(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
function ajax_foogallery_video_discount_offer_hide() { |
|
|
|
|
201
|
|
|
if ( check_admin_referer( 'foogallery_video_discount_offer_hide' ) ) { |
202
|
|
|
update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '3' ); |
203
|
|
|
} |
204
|
|
|
die(); |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.