Skip to content

Commit 1d9791f

Browse files
feat: add license management functionality and UI updates
1 parent 97db6a7 commit 1d9791f

File tree

7 files changed

+115
-55
lines changed

7 files changed

+115
-55
lines changed

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,13 @@ public function enqueue_styles_admin() {
278278
}
279279

280280
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
281-
if ( 'feedzy_page_feedzy-support' === $screen->base && ( ( isset( $_GET['tab'] ) && 'improve' === $_GET['tab'] ) || ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) ) {
281+
if ( 'feedzy_page_feedzy-support' === $screen->base &&
282+
(
283+
( isset( $_GET['tab'] ) && 'improve' === $_GET['tab'] )
284+
|| ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type )
285+
|| ( isset( $_GET['tab'] ) && 'license' === $_GET['tab'] )
286+
)
287+
) {
282288

283289
$asset_file = include FEEDZY_ABSPATH . '/build/feedback/index.asset.php';
284290
wp_enqueue_script( $this->plugin_name . '_feedback', FEEDZY_ABSURL . 'build/feedback/index.js', array_merge( $asset_file['dependencies'], array( 'wp-editor', 'wp-api', 'lodash' ) ), $asset_file['version'], true );
@@ -293,6 +299,20 @@ public function enqueue_styles_admin() {
293299
)
294300
);
295301

302+
wp_enqueue_script( $this->plugin_name . '_license', FEEDZY_ABSURL . 'js/feedzy-license.js', array( 'jquery' ), $this->version, true );
303+
304+
wp_localize_script(
305+
$this->plugin_name . '_license',
306+
'feedzyLicense',
307+
array(
308+
'l10n' => array(
309+
'licenseKey' => __( 'License Key', 'feedzy-rss-feeds' ),
310+
'checkBtn' => __( 'Check License', 'feedzy-rss-feeds' ),
311+
'errorMsg' => __( 'An error occurred while checking the license. Please try again.', 'feedzy-rss-feeds' ),
312+
),
313+
)
314+
);
315+
296316
wp_set_script_translations( $this->plugin_name . '_feedback', 'feedzy-rss-feeds' );
297317
}
298318

@@ -966,7 +986,7 @@ public function feedzy_menu_pages() {
966986
)
967987
);
968988

969-
if ( ! feedzy_is_pro() && get_option( 'feedzy_fresh_install', false ) ) {
989+
if ( ! feedzy_is_pro() && get_option( 'feedzy_fresh_install', false ) ) {
970990
$hook = add_submenu_page(
971991
'feedzy-admin-menu',
972992
__( 'Setup Wizard', 'feedzy-rss-feeds' ),
@@ -989,7 +1009,7 @@ public function rss_to_social_menu() {
9891009
return;
9901010
}
9911011

992-
if ( defined ( 'REVIVE_NETWORK_VERSION' ) && ! feedzy_is_pro() ) {
1012+
if ( defined( 'REVIVE_NETWORK_VERSION' ) && ! feedzy_is_pro() ) {
9931013
return;
9941014
}
9951015

includes/feedzy-rss-feeds.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private function define_admin_hooks() {
176176
self::$instance->loader->add_action( 'feedzy_post_http_teardown', self::$instance->admin, 'post_http_teardown', 10, 1 );
177177
self::$instance->loader->add_action( 'admin_init', self::$instance->admin, 'admin_init', 10, 1 );
178178
self::$instance->loader->add_action( 'manage_feedzy_categories_posts_custom_column', self::$instance->admin, 'manage_feedzy_category_columns', 10, 2 );
179-
self::$instance->loader->add_action( 'admin_menu', self::$instance->admin, 'feedzy_menu_pages', 8);
179+
self::$instance->loader->add_action( 'admin_menu', self::$instance->admin, 'feedzy_menu_pages', 8 );
180180
self::$instance->loader->add_action( 'admin_menu', self::$instance->admin, 'rss_to_social_menu', 20 );
181181
self::$instance->loader->add_action( 'wp_ajax_get_tinymce_form', self::$instance->admin, 'get_tinymce_form' );
182182
self::$instance->loader->add_action( 'wp_enqueue_scripts', self::$instance->admin, 'enqueue_styles' );

includes/layouts/feedzy-license.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="fz-form-wrap">
2+
<?php do_action( 'feedzy_dashboard_license_content' ); ?>
3+
</div>

includes/layouts/feedzy-support.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ class="<?php echo 'docs' === $active_tab ? 'active' : ''; ?>"><?php esc_html_e(
2727
class="<?php echo 'feedzy-pro' === $active_tab ? 'active' : ''; ?>"><?php esc_html_e( 'Free vs Pro', 'feedzy-rss-feeds' ); ?></a>
2828
</li>
2929
<?php endif; ?>
30+
<?php if ( defined( 'FEEDZY_PRO_VERSION' ) && has_action( 'feedzy_dashboard_license_content' ) ) : ?>
31+
<li>
32+
<a href="<?php echo esc_url( admin_url( 'admin.php?page=feedzy-support&tab=license' ) ); ?>"
33+
class="<?php echo 'license' === $active_tab ? 'active' : ''; ?>"><?php esc_html_e( 'License', 'feedzy-rss-feeds' ); ?></a>
34+
</li>
35+
<?php endif; ?>
3036
<li>
3137
<a href="<?php echo esc_url( admin_url( 'admin.php?page=feedzy-support&tab=improve' ) ); ?>"
3238
class="<?php echo 'improve' === $active_tab ? 'active' : ''; ?>"><?php esc_html_e( 'Help us improve!', 'feedzy-rss-feeds' ); ?></a>
@@ -68,6 +74,9 @@ class="<?php echo 'improve' === $active_tab ? 'active' : ''; ?>"><?php esc_html_
6874
case 'improve':
6975
load_template( FEEDZY_ABSPATH . '/includes/layouts/feedzy-improve.php' );
7076
break;
77+
case 'license':
78+
load_template( FEEDZY_ABSPATH . '/includes/layouts/feedzy-license.php' );
79+
break;
7180
default:
7281
$template = apply_filters( 'feedzy_support_tab_content', '', $active_tab );
7382
if ( ! empty( $template ) ) {
@@ -112,4 +121,4 @@ class="<?php echo 'improve' === $active_tab ? 'active' : ''; ?>"><?php esc_html_
112121
</div>
113122
<?php endif; ?>
114123
</div>
115-
</div>
124+
</div>

includes/layouts/setup-wizard.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
*/
77

88
$dashboard_url = add_query_arg(
9-
array(
10-
'page' => 'feedzy-support',
11-
'action' => 'feedzy_dismiss_wizard',
12-
'status' => 0,
13-
),
14-
admin_url( 'admin.php' )
9+
array(
10+
'page' => 'feedzy-support',
11+
'action' => 'feedzy_dismiss_wizard',
12+
'status' => 0,
13+
),
14+
admin_url( 'admin.php' )
1515
);
1616
// phpcs:ignore WordPress.Security.NonceVerification
1717
$integrate_with = ! empty( $_GET['integrate-with'] ) ? sanitize_text_field( wp_unslash( $_GET['integrate-with'] ) ) : '';

js/feedzy-license.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
(function ($) {
2+
/**
3+
* Toggles check button state based on license key input and syncs value across inputs
4+
* @param {window.jQuery} $input - License key input element
5+
*/
6+
const handleLicenseKeyInput = ($input) => {
7+
const licenseKey = $input.val();
8+
const $checkButton = $('#check_ti_license');
9+
10+
if (licenseKey !== '') {
11+
$checkButton.removeAttr('disabled');
12+
} else {
13+
$checkButton.attr('disabled', true);
14+
}
15+
16+
$('.fz-license-section input[name="license_key"]').val(licenseKey);
17+
};
18+
19+
/**
20+
* Handles license validation response - shows errors or reloads page on success
21+
* @param {Object} response - API response with success flag and message
22+
* @param {window.jQuery} $button - Check license button element
23+
*/
24+
const handleLicenseResponse = (response, $button) => {
25+
if (!response.success) {
26+
const $errorMessage = $(
27+
'<p class="feedzy-api-error">' + response.message + '</p>'
28+
);
29+
$errorMessage.insertAfter(
30+
$('.fz-license-section').find('.help-text')
31+
);
32+
$button.removeAttr('disabled').removeClass('fz-checking');
33+
return;
34+
}
35+
window.location.reload();
36+
};
37+
38+
/**
39+
* Validates license via AJAX, disables button and clears previous errors
40+
* @param {Event} e - Click event from check license button
41+
*/
42+
const checkLicense = (e) => {
43+
e.preventDefault();
44+
const $button = $(e.currentTarget);
45+
46+
$button.attr('disabled', true).addClass('fz-checking');
47+
$button
48+
.parents('.fz-license-section')
49+
.find('.feedzy-api-error')
50+
.remove();
51+
52+
const licenseData = $button
53+
.parent('.fz-input-group-btn')
54+
.find('input')
55+
.serialize();
56+
57+
$.post(
58+
window.ajaxurl,
59+
licenseData,
60+
(response) => handleLicenseResponse(response, $button),
61+
'json'
62+
);
63+
};
64+
65+
$(document).ready(() => {
66+
$('.fz-license-section #license_key').on('input', function () {
67+
handleLicenseKeyInput($(this));
68+
});
69+
70+
$('.fz-license-section #check_ti_license').on('click', checkLicense);
71+
});
72+
})(window.jQuery);

js/feedzy-setting.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -98,50 +98,6 @@ jQuery(function ($) {
9898
}
9999
});
100100

101-
102-
// License key.
103-
jQuery('.fz-license-section #license_key').on('input', function () {
104-
const licenseKey = jQuery(this).val();
105-
if (licenseKey !== '') {
106-
jQuery('#check_ti_license').removeAttr('disabled');
107-
} else {
108-
jQuery('#check_ti_license').attr('disabled', true);
109-
}
110-
jQuery('.fz-license-section input[name="license_key"]').val(licenseKey);
111-
});
112-
113-
jQuery('.fz-license-section #check_ti_license').on('click', function (e) {
114-
e.preventDefault();
115-
const _this = jQuery(this);
116-
_this.attr('disabled', true).addClass('fz-checking');
117-
118-
_this.parents('.fz-license-section').find('.feedzy-api-error').remove();
119-
120-
const LicenseData = _this
121-
.parent('.fz-input-group-btn')
122-
.find('input')
123-
.serialize();
124-
125-
jQuery.post(
126-
ajaxurl,
127-
LicenseData,
128-
function (response) {
129-
if (!response.success) {
130-
jQuery(
131-
'<p class="feedzy-api-error">' +
132-
response.message +
133-
'</p>'
134-
).insertAfter(
135-
jQuery('.fz-license-section').find('.help-text')
136-
);
137-
_this.removeAttr('disabled').removeClass('fz-checking');
138-
} else {
139-
window.location.reload();
140-
}
141-
},
142-
'json'
143-
);
144-
});
145101
snackbarNotice();
146102

147103
const initializeAutoCatActions = () => {

0 commit comments

Comments
 (0)