diff --git a/includes/admin/feedzy-rss-feeds-admin.php b/includes/admin/feedzy-rss-feeds-admin.php index 337d7dd6..cd9e9e5f 100644 --- a/includes/admin/feedzy-rss-feeds-admin.php +++ b/includes/admin/feedzy-rss-feeds-admin.php @@ -128,6 +128,34 @@ public function enqueue_styles() { } wp_register_style( $this->plugin_name, FEEDZY_ABSURL . 'css/feedzy-rss-feeds.css', array(), $this->version, 'all' ); } + + /** + * Helper function to enqueue the license script with localization + * + * @access public + * @return void + */ + private function enqueue_license_script() { + wp_enqueue_script( + $this->plugin_name . '_license', + FEEDZY_ABSURL . 'js/feedzy-license.js', + array( 'jquery' ), + $this->version, + true + ); + + wp_localize_script( + $this->plugin_name . '_license', + 'feedzyLicense', + array( + 'l10n' => array( + 'licenseKey' => __( 'License Key', 'feedzy-rss-feeds' ), + 'checkBtn' => __( 'Check License', 'feedzy-rss-feeds' ), + 'errorMsg' => __( 'An error occurred while checking the license. Please try again.', 'feedzy-rss-feeds' ), + ), + ) + ); + } /** * Register the stylesheets for the admin area. @@ -206,6 +234,8 @@ public function enqueue_styles_admin() { ), ) ); + + $this->enqueue_license_script(); } $upsell_screens = array( 'feedzy-rss_page_feedzy-settings', 'feedzy-rss_page_feedzy-admin-menu-pro-upsell' ); @@ -278,8 +308,15 @@ public function enqueue_styles_admin() { } // phpcs:ignore WordPress.Security.NonceVerification.Recommended - if ( 'feedzy_page_feedzy-support' === $screen->base && ( ( isset( $_GET['tab'] ) && 'improve' === $_GET['tab'] ) || ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) ) { - + $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : ''; + + if ( 'feedzy_page_feedzy-support' === $screen->base && + ( + ( 'improve' === $tab ) + || ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) + || ( 'license' === $tab ) + ) + ) { $asset_file = include FEEDZY_ABSPATH . '/build/feedback/index.asset.php'; 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 ); wp_enqueue_style( 'wp-block-editor' ); @@ -293,6 +330,8 @@ public function enqueue_styles_admin() { ) ); + $this->enqueue_license_script(); + wp_set_script_translations( $this->plugin_name . '_feedback', 'feedzy-rss-feeds' ); } @@ -923,6 +962,7 @@ public function feedzy_filter_plugin_row_meta( $links, $file ) { * * @since 3.0.12 * @access public + * @return void */ public function feedzy_menu_pages() { $capability = feedzy_current_user_can(); @@ -932,6 +972,17 @@ public function feedzy_menu_pages() { $svg_base64_icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iNzdweCIgaGVpZ2h0PSI3N3B4IiB2aWV3Qm94PSIwIDAgNzcgNzciIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8IS0tIEdlbmVyYXRvcjogU2tldGNoIDUyLjYgKDY3NDkxKSAtIGh0dHA6Ly93d3cuYm9oZW1pYW5jb2RpbmcuY29tL3NrZXRjaCAtLT4KICAgIDx0aXRsZT5Db21iaW5lZC1TaGFwZTwvdGl0bGU+CiAgICA8ZGVzYz5DcmVhdGVkIHdpdGggU2tldGNoLjwvZGVzYz4KICAgIDxnIGlkPSJQcm9kdWN0LVBhZ2UiIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxnIGlkPSJXb3JkUHJlc3MtcGx1Z2lucyIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE5Ni4wMDAwMDAsIC05NTcuMDAwMDAwKSIgZmlsbD0iIzQyNjhDRiI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DI0Ni42NDk1NDYsMTAwMS4yOTU0MSBDMjQ3LjE3MDA0NywxMDAxLjc1MjI1IDI0Ny45NTg0MiwxMDAxLjcxOTI1IDI0OC40NDgwNzUsMTAwMS4yMjk1OSBMMjUxLjI0NTQ2NSw5OTguNDMyMjA1IEMyNTEuNzc3OTUyLDk5Ny44OTk4MzQgMjUxLjc1OTU2MSw5OTcuMDI3MTM2IDI1MS4xOTkxOTYsOTk2LjUyNDI2OSBaIE0yNTkuNTE3NDgxLDk4OC4wNjI4MTggQzI0NS43NTQ2NjIsOTc1LjI1MzkxIDIyNC4zMTI1MzEsOTc1LjE5MTM3NCAyMTAuNDgyNDY0LDk4OC4wNjI4NzMgQzIwOS45NTA5Niw5ODguNTU3NTU3IDIwOS45NDA4NDUsOTg5LjM5NjY4OSAyMTAuNDU0MjIyLDk4OS45MTAwNjYgTDIxMy4xODU0ODksOTkyLjY0MTMzMyBDMjEzLjY3NTU2OSw5OTMuMTMxNDEzIDIxNC40NjI4MjQsOTkzLjE0MTkyNCAyMTQuOTcyNjIyLDk5Mi42NzIzNTUgQzIyNi4yODEwMjksOTgyLjI1NDc4NiAyNDMuNzIwODA0LDk4Mi4yNTY0MTUgMjU5LjUxNzQ4MSw5ODguMDYyODE4IFoiIGlkPSJDb21iaW5lZC1TaGFwZSI+PC9wYXRoPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+'; add_menu_page( __( 'Feedzy', 'feedzy-rss-feeds' ), __( 'Feedzy', 'feedzy-rss-feeds' ), apply_filters( 'feedzy_admin_menu_capability', 'publish_posts' ), 'feedzy-admin-menu', '', $svg_base64_icon, 98.7666 ); + add_submenu_page( + 'feedzy-admin-menu', + __( 'Dashboard', 'feedzy-rss-feeds' ), + __( 'Dashboard', 'feedzy-rss-feeds' ), + 'manage_options', + 'feedzy-support', + array( + $this, + 'render_support', + ) + ); add_submenu_page( 'feedzy-admin-menu', __( 'Settings', 'feedzy-rss-feeds' ), @@ -954,17 +1005,6 @@ public function feedzy_menu_pages() { 'feedzy_integration_page', ) ); - add_submenu_page( - 'feedzy-admin-menu', - __( 'Support', 'feedzy-rss-feeds' ), - __( 'Support', 'feedzy-rss-feeds' ) . '', - 'manage_options', - 'feedzy-support', - array( - $this, - 'render_support', - ) - ); if ( ! feedzy_is_pro() && get_option( 'feedzy_fresh_install', false ) ) { $hook = add_submenu_page( @@ -981,37 +1021,55 @@ public function feedzy_menu_pages() { add_action( "load-$hook", array( $this, 'feedzy_load_setup_wizard_page' ) ); add_action( 'adminmenu', array( $this, 'feedzy_hide_wizard_menu' ) ); } - if ( ! defined( 'REVIVE_NETWORK_VERSION' ) ) { - $rss_to_social = __( 'RSS to Social', 'feedzy-rss-feeds' ) . ''; - add_action( - 'admin_footer', - function () { - ?> - - '; + add_action( + 'admin_footer', + function () { + ?> + + 1, - 'redirect_to' => add_query_arg( 'post_type', 'feedzy_imports', admin_url( 'edit.php' ) ), + 'redirect_to' => add_query_arg( + array( + 'page' => 'feedzy-support', + ), + admin_url( 'admin.php' ) + ), 'message' => __( 'Redirecting to Feedzy dashboard', 'feedzy-rss-feeds' ), ); @@ -1834,30 +1910,48 @@ private function setup_wizard_subscribe_process() { } else { $response = array( 'status' => 1, - 'redirect_to' => add_query_arg( 'post_type', 'feedzy_imports', admin_url( 'edit.php' ) ), + 'redirect_to' => add_query_arg( + array( + 'page' => 'feedzy-support', + ), + admin_url( 'admin.php' ) + ), 'message' => __( 'Redirecting to Feedzy dashboard', 'feedzy-rss-feeds' ), ); } } elseif ( 'page_builder' === $integrate_with ) { - $post_edit_link = get_edit_post_link( $page_id, 'db' ); - // Get elementor edit page link. - if ( defined( 'ELEMENTOR_PATH' ) && class_exists( 'Elementor\Widget_Base' ) ) { - $segment = 3; - $post_edit_link = add_query_arg( - array( - 'post' => $page_id, - 'action' => 'elementor', + if ( empty( $page_id ) ) { + $response = array( + 'status' => 1, + 'redirect_to' => add_query_arg( + array( + 'page' => 'feedzy-support', + ), + admin_url( 'admin.php' ) ), - admin_url( 'post.php' ) + 'message' => __( 'Redirecting to Feedzy dashboard', 'feedzy-rss-feeds' ), ); } else { - $segment = 4; + $post_edit_link = get_edit_post_link( $page_id, 'db' ); + // Get elementor edit page link. + if ( defined( 'ELEMENTOR_PATH' ) && class_exists( 'Elementor\Widget_Base' ) ) { + $segment = 3; + $post_edit_link = add_query_arg( + array( + 'post' => $page_id, + 'action' => 'elementor', + ), + admin_url( 'post.php' ) + ); + } else { + $segment = 4; + } + $response = array( + 'status' => 1, + 'redirect_to' => $post_edit_link, + 'message' => __( 'Redirecting to draft page', 'feedzy-rss-feeds' ), + ); } - $response = array( - 'status' => 1, - 'redirect_to' => $post_edit_link, - 'message' => __( 'Redirecting to draft page', 'feedzy-rss-feeds' ), - ); } if ( $with_subscribe && is_email( $email ) ) { update_option( 'feedzy_rss_feeds_logger_flag', 'yes' ); diff --git a/includes/feedzy-rss-feeds.php b/includes/feedzy-rss-feeds.php index 47fa150e..18f29201 100644 --- a/includes/feedzy-rss-feeds.php +++ b/includes/feedzy-rss-feeds.php @@ -176,7 +176,8 @@ private function define_admin_hooks() { self::$instance->loader->add_action( 'feedzy_post_http_teardown', self::$instance->admin, 'post_http_teardown', 10, 1 ); self::$instance->loader->add_action( 'admin_init', self::$instance->admin, 'admin_init', 10, 1 ); self::$instance->loader->add_action( 'manage_feedzy_categories_posts_custom_column', self::$instance->admin, 'manage_feedzy_category_columns', 10, 2 ); - self::$instance->loader->add_action( 'admin_menu', self::$instance->admin, 'feedzy_menu_pages' ); + self::$instance->loader->add_action( 'admin_menu', self::$instance->admin, 'feedzy_menu_pages', 8 ); + self::$instance->loader->add_action( 'admin_menu', self::$instance->admin, 'rss_to_social_menu', 20 ); self::$instance->loader->add_action( 'wp_ajax_get_tinymce_form', self::$instance->admin, 'get_tinymce_form' ); self::$instance->loader->add_action( 'wp_enqueue_scripts', self::$instance->admin, 'enqueue_styles' ); self::$instance->loader->add_action( 'admin_enqueue_scripts', self::$instance->admin, 'enqueue_styles_admin', 99 ); diff --git a/includes/layouts/feedzy-license.php b/includes/layouts/feedzy-license.php new file mode 100644 index 00000000..58b12522 --- /dev/null +++ b/includes/layouts/feedzy-license.php @@ -0,0 +1,3 @@ +
' + response.message + '
' + ); + $errorMessage.insertAfter( + $('.fz-license-section').find('.help-text') + ); + $button.removeAttr('disabled').removeClass('fz-checking'); + return; + } + window.location.reload(); + }; + + /** + * Validates license via AJAX, disables button and clears previous errors + * @param {Event} e - Click event from check license button + */ + const checkLicense = (e) => { + e.preventDefault(); + const $button = $(e.currentTarget); + + $button.attr('disabled', true).addClass('fz-checking'); + $button + .parents('.fz-license-section') + .find('.feedzy-api-error') + .remove(); + + const licenseData = $button + .parent('.fz-input-group-btn') + .find('input') + .serialize(); + + $.post( + window.ajaxurl, + licenseData, + (response) => handleLicenseResponse(response, $button), + 'json' + ); + }; + + $(document).ready(() => { + $('.fz-license-section #license_key').on('input', function () { + handleLicenseKeyInput($(this)); + }); + + $('.fz-license-section #check_ti_license').on('click', checkLicense); + }); +})(window.jQuery); diff --git a/js/feedzy-setting.js b/js/feedzy-setting.js index 375c581c..51fe0741 100644 --- a/js/feedzy-setting.js +++ b/js/feedzy-setting.js @@ -98,50 +98,6 @@ jQuery(function ($) { } }); - - // License key. - jQuery('.fz-license-section #license_key').on('input', function () { - const licenseKey = jQuery(this).val(); - if (licenseKey !== '') { - jQuery('#check_ti_license').removeAttr('disabled'); - } else { - jQuery('#check_ti_license').attr('disabled', true); - } - jQuery('.fz-license-section input[name="license_key"]').val(licenseKey); - }); - - jQuery('.fz-license-section #check_ti_license').on('click', function (e) { - e.preventDefault(); - const _this = jQuery(this); - _this.attr('disabled', true).addClass('fz-checking'); - - _this.parents('.fz-license-section').find('.feedzy-api-error').remove(); - - const LicenseData = _this - .parent('.fz-input-group-btn') - .find('input') - .serialize(); - - jQuery.post( - ajaxurl, - LicenseData, - function (response) { - if (!response.success) { - jQuery( - '' + - response.message + - '
' - ).insertAfter( - jQuery('.fz-license-section').find('.help-text') - ); - _this.removeAttr('disabled').removeClass('fz-checking'); - } else { - window.location.reload(); - } - }, - 'json' - ); - }); snackbarNotice(); const initializeAutoCatActions = () => { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 079a2745..48144c95 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -630,11 +630,6 @@ parameters: count: 1 path: includes/admin/feedzy-rss-feeds-admin.php - - - message: "#^Method Feedzy_Rss_Feeds_Admin\\:\\:feedzy_menu_pages\\(\\) has no return type specified\\.$#" - count: 1 - path: includes/admin/feedzy-rss-feeds-admin.php - - message: "#^Method Feedzy_Rss_Feeds_Admin\\:\\:feedzy_remove_elementor_feature\\(\\) has no return type specified\\.$#" count: 1