premium-versions-upgrade-handler.php
8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
* @package Freemius
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
* @since 2.0.2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* @var Freemius $fs
*/
$fs = freemius( $VARS['id'] );
$slug = $fs->get_slug();
$plugin_data = $fs->get_plugin_data();
$plugin_name = $plugin_data['Name'];
$plugin_basename = $fs->get_plugin_basename();
$license = $fs->_get_license();
if ( ! is_object( $license ) ) {
$purchase_url = $fs->pricing_url();
} else {
$subscription = $fs->_get_subscription( $license->id );
$purchase_url = $fs->checkout_url(
is_object( $subscription ) ?
( 1 == $subscription->billing_cycle ? WP_FS__PERIOD_MONTHLY : WP_FS__PERIOD_ANNUALLY ) :
WP_FS__PERIOD_LIFETIME,
false,
array( 'licenses' => $license->quota )
);
}
$message = sprintf(
fs_text_inline( 'There is a new version of %s available.', 'new-version-available-message', $slug ) .
fs_text_inline( ' %s to access version %s security & feature updates, and support.', 'x-for-updates-and-support', $slug ),
'<span id="plugin_name"></span>',
sprintf(
'<a id="pricing_url" href="">%s</a>',
is_object( $license ) ?
fs_text_inline( 'Renew your license now', 'renew-license-now', $slug ) :
fs_text_inline( 'Buy a license now', 'buy-license-now', $slug )
),
'<span id="new_version"></span>'
);
$modal_content_html = "<p>{$message}</p>";
$header_title = fs_text_inline( 'New Version Available', 'new-version-available', $slug );
$renew_license_button_text = is_object( $license ) ?
fs_text_inline( 'Renew license', 'renew-license', $slug ) :
fs_text_inline( 'Buy license', 'buy-license', $slug );
fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
?>
<script type="text/javascript">
(function( $ ) {
$( document ).ready(function() {
if ( 0 === $( '.license-expired' ).length ) {
return;
}
var modalContentHtml = <?php echo json_encode( $modal_content_html ) ?>,
modalHtml =
'<div class="fs-modal fs-modal-upgrade-premium-version">'
+ ' <div class="fs-modal-dialog">'
+ ' <div class="fs-modal-header">'
+ ' <h4><?php echo esc_js( $header_title ) ?></h4>'
+ ' <a href="!#" class="fs-close"><i class="dashicons dashicons-no" title="<?php echo esc_js( fs_text_x_inline( 'Dismiss', 'close a window', 'dismiss', $slug ) ) ?>"></i></a>'
+ ' </div>'
+ ' <div class="fs-modal-body">'
+ ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
+ ' </div>'
+ ' <div class="fs-modal-footer">'
+ ' <a class="button button-primary button-renew-license" tabindex="3" href="<?php echo $purchase_url ?>"><?php echo esc_js( $renew_license_button_text ) ?></a>'
+ ' <button class="button button-secondary button-close" tabindex="4"><?php fs_esc_js_echo_inline( 'Cancel', 'cancel', $slug ) ?></button>'
+ ' </div>'
+ ' </div>'
+ '</div>',
$modal = $( modalHtml ),
isPluginsPage = <?php echo Freemius::is_plugins_page() ? 'true' : 'false' ?>;
$modal.appendTo( $( 'body' ) );
function registerEventHandlers() {
$( 'body' ).on( 'click', '.license-expired', function( evt ) {
var $this = $( this );
if ( ! $this.is( ':checked' ) ||
(
isPluginsPage &&
'update-selected' !== $( '#bulk-action-selector-top' ).val() &&
'update-selected' !== $( '#bulk-action-selector-bottom' ).val()
)
) {
return true;
}
evt.preventDefault();
evt.stopImmediatePropagation();
showModal( $this );
});
// If the user has clicked outside the window, close the modal.
$modal.on( 'click', '.fs-close, .button-secondary', function() {
closeModal();
return false;
});
if ( isPluginsPage ) {
$( 'body' ).on( 'change', 'select[id*="bulk-action-selector"]', function() {
if ( 'update-selected' === $( this ).val() ) {
setTimeout(function() {
$( '.license-expired' ).prop( 'checked', false );
$( '[id*="select-all"]' ).prop( 'checked', false );
}, 0);
}
});
}
$( 'body' ).on( 'click', '[id*="select-all"]', function( evt ) {
var $this = $( this );
if ( ! $this.is( ':checked' ) ) {
return true;
}
if ( isPluginsPage ) {
if ( 'update-selected' !== $( '#bulk-action-selector-top' ).val() &&
'update-selected' !== $( '#bulk-action-selector-bottom' ).val() ) {
return true;
}
}
var $table = $this.closest( 'table' ),
controlChecked = $this.prop( 'checked' ),
toggle = ( event.shiftKey || $this.data( 'wp-toggle' ) ),
$modules = $table.children( 'tbody' ).filter( ':visible' ).children().children( '.check-column' ).find( ':checkbox' ),
$modulesWithNonActiveLicense = $modules.filter( '.license-expired' );
if ( 0 === $modulesWithNonActiveLicense.length ) {
/**
* It's possible that the context HTML table element doesn't have checkboxes with
* ".license-expired" class if for example only the themes table has such checkboxes and the user
* clicks on a "Select All" checkbox on the plugins table which has no such checkboxes.
*
* @author Leo Fajardo (@leorw)
*/
return true;
} else if ( 1 === $modulesWithNonActiveLicense.length ) {
showModal( $modulesWithNonActiveLicense );
}
/**
* Prevent the default WordPress handler from checking all checkboxes.
*
* @author Leo Fajardo (@leorw)
*/
evt.stopImmediatePropagation();
$modules.filter( ':not(.license-expired)' )
.prop( 'checked', function() {
if ( $( this ).is( ':hidden,:disabled' ) ) {
return false;
}
if ( toggle ) {
return ! $( this ).prop( 'checked' );
} else if ( controlChecked ) {
return true;
}
return false;
});
return false;
});
}
registerEventHandlers();
function showModal( $module ) {
$modal.find( '#plugin_name' ).text( $module.data( 'plugin-name' ) );
$modal.find( '#pricing_url' ).attr( 'href', $module.data( 'pricing-url' ) );
$modal.find( '#new_version' ).text( $module.data( 'new-version' ) );
// Display the dialog box.
$modal.addClass( 'active' );
$( 'body' ).addClass( 'has-fs-modal' );
}
function closeModal() {
$modal.removeClass( 'active' );
$( 'body' ).removeClass( 'has-fs-modal' );
}
});
})( jQuery );
</script>