Skip to content

Commit 7c53f00

Browse files
committed
chore: optimized feature lock notice rendering
1 parent 874cf97 commit 7c53f00

File tree

4 files changed

+73
-75
lines changed

4 files changed

+73
-75
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,7 @@ public function renderLibraryPage() {
10191019
}
10201020
// enqueue charts array
10211021
$ajaxurl = admin_url( 'admin-ajax.php' );
1022-
$license = get_option( 'visualizer_pro_license_data', 'free' );
1023-
$license_key = '';
1024-
$download_id = '';
1025-
if ( ! empty( $license ) && is_object( $license ) ) {
1026-
$license_key = $license->key;
1027-
$download_id = $license->download_id;
1028-
}
1022+
10291023
wp_localize_script(
10301024
'visualizer-library',
10311025
'visualizer',
@@ -1065,8 +1059,6 @@ public function renderLibraryPage() {
10651059
'conflict' => __( 'We have detected a potential conflict with another component that prevents Visualizer from functioning properly. Please disable any of the following components if they are activated on your instance: Modern Events Calendar plugin, Acronix plugin. In case the aforementioned components are not activated or you continue to see this error message, please disable all other plugins and enable them one by one to find out the component that is causing the conflict.', 'visualizer' ),
10661060
),
10671061
'is_pro_user' => Visualizer_Module::is_pro(),
1068-
'admin_license_url' => admin_url('options-general.php#visualizer_pro_license'),
1069-
'renew_license_url' => tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' .$download_id, 'visualizer_license_block' ),
10701062
)
10711063
);
10721064
// render library page

classes/Visualizer/Render/Library.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,48 @@ private function getDisplayForm() {
215215
* @access private
216216
*/
217217
private function _renderLibrary() {
218+
$license = get_option( 'visualizer_pro_license_data', 'free' );
219+
$license_key = '';
220+
$download_id = '';
221+
if ( ! empty( $license ) && is_object( $license ) ) {
222+
$license_key = $license->key;
223+
$download_id = $license->download_id;
224+
}
225+
$admin_license_url = admin_url('options-general.php#visualizer_pro_license');
226+
$renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' .$download_id, 'visualizer_license_block' );
218227
// Added by Ash/Upwork
219228
$filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
220229
// Added by Ash/Upwork
221230
echo $this->custom_css;
231+
if ( ! Visualizer_Module::is_pro() ) {
232+
echo '
233+
<div class="vizualizer-renew-notice-overlay" id="overlay-visualizer"></div>
234+
<div class="vizualizer-renew-notice-popup">
235+
<h1 class="vizualizer-renew-notice-heading">Alert!</h1>
236+
<p class="vizualizer-renew-notice-message">' . esc_html__( 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.', 'visualizer' ) . ' </p>
237+
<div class="vizualizer-renew-notice-buttons-container">
238+
<a href="' . esc_url($renew_license_url) . '" target="_blank">
239+
<button class="vizualizer-renew-notice-button vizualizer-renew-notice-renew-button">
240+
<span class="dashicons dashicons-cart"></span>' . esc_html__( 'Renew License', 'visualizer' ) . '
241+
</button>
242+
</a>
243+
<a href="' . esc_url($admin_license_url) . '">
244+
<button class="vizualizer-renew-notice-button vizualizer-renew-notice-activate-button">
245+
<span class="dashicons dashicons-unlock"></span> ' . esc_html__( 'Activate License', 'visualizer' ) . '
246+
</button>
247+
</a>
248+
</div>
249+
<i class="dashicons dashicons-no vizualizer-renew-notice-close-icon"></i>
250+
</div>
251+
<script>
252+
jQuery(document).ready(function($) {
253+
$(".vizualizer-renew-notice-close-icon").on("click", function() {
254+
$("#overlay-visualizer").css("display", "none");
255+
$(".vizualizer-renew-notice-popup").css("display", "none");
256+
});
257+
});
258+
</script>';
259+
}
222260
echo '<div id="visualizer-types" class="visualizer-clearfix">';
223261
echo '<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><symbol id="list-icon" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8C0 12.42 3.58 16 8 16C12.42 16 16 12.42 16 8C16 3.58 12.42 0 8 0ZM7.385 12.66H6.045L2.805 8.12L4.146 6.87L6.715 9.27L11.856 3.339L13.196 4.279L7.385 12.66Z"/></symbol></svg>';
224262
$this->getDisplayForm();
@@ -251,6 +289,26 @@ private function _renderLibrary() {
251289
$this->_renderSidebar();
252290
}
253291
echo '</div>';
292+
293+
// echo '
294+
//
295+
// <h1 class="vizualizer-renew-notice-heading">Alert!</h1>
296+
// <p class="vizualizer-renew-notice-message">
297+
// In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.
298+
// </p>
299+
// <div class="vizualizer-renew-notice-buttons-container">
300+
// <a href="${visualizer.renew_license_url}" target="_blank">
301+
// <button class="vizualizer-renew-notice-button vizualizer-renew-notice-renew-button">
302+
// <span class="dashicons dashicons-cart"></span> Renew License
303+
// </button>
304+
// </a>
305+
// <a href="${visualizer.admin_license_url}">
306+
// <button class="vizualizer-renew-notice-button vizualizer-renew-notice-activate-button">
307+
// <span class="dashicons dashicons-unlock"></span> Activate License
308+
// </button>
309+
// </a>
310+
// </div>
311+
// <i class="dashicons dashicons-no vizualizer-renew-notice-close-icon"></i> ';
254312
} else {
255313
echo '<div id="visualizer-library" class="visualizer-clearfix">';
256314
echo '<div class="items"><div class="visualizer-chart">';

css/library.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ div#visualizer-types ul, div#visualizer-types form p {
522522

523523

524524
.vizualizer-renew-notice-overlay {
525+
display: none;
525526
position: fixed;
526527
top: 0;
527528
left: 0;
@@ -532,7 +533,7 @@ div#visualizer-types ul, div#visualizer-types form p {
532533
}
533534

534535
.vizualizer-renew-notice-popup {
535-
display: block;
536+
display: none;
536537
position: fixed;
537538
top: 50%;
538539
left: 50%;

js/library.js

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,61 +33,13 @@
3333
});
3434
})(wp.media.view);
3535

36-
function createPopupProBlocker() {
37-
38-
var overlay = document.createElement('div');
39-
overlay.classList.add('vizualizer-renew-notice-overlay');
40-
overlay.id = 'overlay-visualizer';
41-
document.body.appendChild(overlay);
42-
43-
var popup = document.createElement('div');
44-
popup.classList.add('vizualizer-renew-notice-popup');
45-
46-
var heading = document.createElement('h1');
47-
heading.textContent = 'Alert!';
48-
heading.classList.add('vizualizer-renew-notice-heading');
49-
popup.appendChild(heading);
50-
51-
var message = document.createElement('p');
52-
message.textContent = 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.';
53-
message.classList.add('vizualizer-renew-notice-message');
54-
popup.appendChild(message);
55-
56-
var buttonsContainer = document.createElement('div');
57-
buttonsContainer.classList.add('vizualizer-renew-notice-buttons-container');
58-
59-
var link1 = document.createElement('a');
60-
link1.href = visualizer.renew_license_url;
61-
link1.target = '_blank';
62-
var button1 = document.createElement('button');
63-
button1.innerHTML = '<span class="dashicons dashicons-cart"></span> Renew License';
64-
button1.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-renew-button');
65-
link1.appendChild(button1);
66-
buttonsContainer.appendChild(link1);
67-
68-
var link2 = document.createElement('a');
69-
link2.href = visualizer.admin_license_url;
70-
var button2 = document.createElement('button');
71-
button2.innerHTML = '<span class="dashicons dashicons-unlock"></span> Activate License';
72-
button2.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-activate-button');
73-
link2.appendChild(button2);
74-
buttonsContainer.appendChild(link2);
75-
76-
popup.appendChild(buttonsContainer);
77-
78-
var closeIcon = document.createElement('i');
79-
80-
closeIcon.classList.add('dashicons', 'dashicons-no', 'vizualizer-renew-notice-close-icon');
81-
82-
closeIcon.addEventListener('click', function() {
83-
document.body.removeChild(overlay);
84-
document.body.removeChild(popup);
85-
});
86-
87-
popup.appendChild(closeIcon);
88-
89-
document.body.appendChild(popup);
90-
36+
function createPopupProBlocker( $ , e ) {
37+
if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) {
38+
$("#overlay-visualizer").css("display", "block");
39+
$(".vizualizer-renew-notice-popup").css("display", "block");
40+
return true;
41+
}
42+
return false;
9143
}
9244

9345
(function ($, vmv, vu) {
@@ -135,8 +87,7 @@ function createPopupProBlocker() {
13587

13688
$('.visualizer-chart-shortcode').click(function (e) {
13789

138-
if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) {
139-
createPopupProBlocker();
90+
if ( createPopupProBlocker( $, e ) ) {
14091
e.preventDefault();
14192
e.stopPropagation();
14293
return;
@@ -193,8 +144,7 @@ function createPopupProBlocker() {
193144

194145
$('.visualizer-chart-edit').click(function (event) {
195146

196-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
197-
createPopupProBlocker();
147+
if ( createPopupProBlocker( $, event ) ) {
198148
return;
199149
}
200150

@@ -213,16 +163,14 @@ function createPopupProBlocker() {
213163
return false;
214164
});
215165
$(".visualizer-chart-clone").on("click", function ( event ) {
216-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
217-
createPopupProBlocker();
166+
if ( createPopupProBlocker( $, event ) ) {
218167
event.preventDefault();
219168
}
220169
});
221170

222171
$(".visualizer-chart-export").on("click", function (event) {
223172

224-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
225-
createPopupProBlocker();
173+
if ( createPopupProBlocker( $, event ) ) {
226174
return;
227175
}
228176

@@ -247,8 +195,7 @@ function createPopupProBlocker() {
247195
});
248196

249197
$(".visualizer-chart-image").on("click", function (event) {
250-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
251-
createPopupProBlocker();
198+
if ( createPopupProBlocker( $, event ) ) {
252199
return;
253200
}
254201
$('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}});

0 commit comments

Comments
 (0)