From 43f2aded0519573408b1607a09c7117792cf7ba4 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Mon, 9 Sep 2024 16:35:04 +0530 Subject: [PATCH] Restrict custom style uses for free users --- classes/admin.class.php | 17 +++++++++ classes/fields.class.php | 11 ++++-- classes/frontend-scripts.class.php | 4 +-- css/ppom-admin.css | 8 +++++ inc/admin.php | 58 +++++++++++++++--------------- inc/functions.php | 12 +++++++ templates/admin/ppom-fields.php | 9 +++++ 7 files changed, 86 insertions(+), 33 deletions(-) diff --git a/classes/admin.class.php b/classes/admin.class.php index bae49c7a..dd4e3ba7 100644 --- a/classes/admin.class.php +++ b/classes/admin.class.php @@ -86,6 +86,8 @@ function __construct() { 10 ); + add_action( 'admin_init', array( $this, 'set_legacy_user' ) ); + } @@ -412,5 +414,20 @@ public function load_admin_menu() { PPOM_Survey::get_instance()->init(); } + /** + * Set legacy user flag. + */ + public function set_legacy_user() { + if ( ! empty( get_option( 'ppom_legacy_user', '' ) ) ) { + return; + } + + global $wpdb; + $ppom_meta_table = $wpdb->prefix . PPOM_TABLE_META; + // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared + $res = $wpdb->get_results( "SELECT * FROM `$ppom_meta_table` WHERE `productmeta_js` != '' OR `productmeta_style` != ''" ); + update_option( 'ppom_legacy_user', ! empty( $res ) ? 'yes' : 'no' ); + } + } diff --git a/classes/fields.class.php b/classes/fields.class.php index 78788222..5c1211e5 100644 --- a/classes/fields.class.php +++ b/classes/fields.class.php @@ -89,10 +89,14 @@ function load_script( $hook ) { // CSS Code Editor Files wp_enqueue_style( 'ppom-codemirror-theme', PPOM_URL . '/css/codemirror-theme.css' ); $css_code_editor = wp_enqueue_code_editor( array( 'type' => 'text/css' ) ); + $legacy_user = ppom_is_legacy_user(); // ppom_pa($css_code_editor); exit; if ( false !== $css_code_editor ) { $css_code_editor['codemirror']['autoRefresh'] = true; - $css_code_editor['codemirror']['theme'] = 'darcula'; + if ( $legacy_user ) { + $css_code_editor['codemirror']['readOnly'] = 'nocursor'; + } + $css_code_editor['codemirror']['theme'] = 'darcula'; wp_add_inline_script( 'code-editor', sprintf( @@ -106,7 +110,10 @@ function load_script( $hook ) { $js_code_editor = wp_enqueue_code_editor( array( 'type' => 'text/javascript' ) ); if ( false !== $js_code_editor ) { $js_code_editor['codemirror']['autoRefresh'] = true; - $js_code_editor['codemirror']['theme'] = 'darcula'; + if ( $legacy_user ) { + $js_code_editor['codemirror']['readOnly'] = 'nocursor'; + } + $js_code_editor['codemirror']['theme'] = 'darcula'; wp_add_inline_script( 'code-editor', sprintf( diff --git a/classes/frontend-scripts.class.php b/classes/frontend-scripts.class.php index 287f30d3..7882e1b3 100644 --- a/classes/frontend-scripts.class.php +++ b/classes/frontend-scripts.class.php @@ -404,10 +404,10 @@ public static function load_scripts_by_product_id( $product_id, $ppom_id = null, break; case 'bulkquantity': - $fields_meta['options'] = stripslashes( $fields_meta['options'] ); + $fields_meta['options'] = isset( $fields_meta['options'] ) ? stripslashes( $fields_meta['options'] ) : ''; // To make bulkquantity option WOOCS ready - $bulkquantities_options = json_decode( $fields_meta['options'], true ); + $bulkquantities_options = ! empty( $fields_meta['options'] ) ? json_decode( $fields_meta['options'], true ) : array(); $bulkquantities_new_options = array(); foreach ( $bulkquantities_options as $bq_opt ) { $bq_array = array(); diff --git a/css/ppom-admin.css b/css/ppom-admin.css index ecef0789..cf6d291b 100644 --- a/css/ppom-admin.css +++ b/css/ppom-admin.css @@ -1163,4 +1163,12 @@ a[data-modal-id="ppom-nm-plugins-modal"] { #ppom-admin-changelog-header-top { padding: 15px 30px 0 0; +} + +.ppom-admin-tabs-css .ppom-admin-tab-content .notice-info { + margin: 10px 0; + padding: 10px 5px; +} +.ppom-admin-tabs-css .ppom-admin-tab-content .notice-info p { + margin: 0; } \ No newline at end of file diff --git a/inc/admin.php b/inc/admin.php index 6cc430b5..ff4b51ee 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -243,22 +243,23 @@ function ppom_admin_save_form_meta() { wp_send_json( $resp ); } - $dt = apply_filters( - 'ppom_settings_meta_data_new', - array( - 'productmeta_name' => $productmeta_name, - 'dynamic_price_display' => $dynamic_price_hide, - 'send_file_attachment' => $send_file_attachment, - 'show_cart_thumb' => $show_cart_thumb, - 'aviary_api_key' => trim( $aviary_api_key ), - 'productmeta_style' => $productmeta_style, - 'productmeta_js' => $productmeta_js, - 'productmeta_categories' => $productmeta_categories, - 'the_meta' => $product_meta, - 'productmeta_created' => current_time( 'mysql' ), - ) + $ppom_settings_meta_data = array( + 'productmeta_name' => $productmeta_name, + 'dynamic_price_display' => $dynamic_price_hide, + 'send_file_attachment' => $send_file_attachment, + 'show_cart_thumb' => $show_cart_thumb, + 'aviary_api_key' => trim( $aviary_api_key ), + 'productmeta_categories' => $productmeta_categories, + 'the_meta' => $product_meta, + 'productmeta_created' => current_time( 'mysql' ), ); + if ( ! ppom_is_legacy_user() ) { + $ppom_settings_meta_data['productmeta_style'] = $productmeta_style; + $ppom_settings_meta_data['productmeta_js'] = $productmeta_js; + } + + $dt = apply_filters( 'ppom_settings_meta_data_new', $ppom_settings_meta_data ); // wp_send_json($dt); @@ -398,22 +399,21 @@ function( $pm ) { wp_send_json( $resp ); } - - $dt = $dt = apply_filters( - 'ppom_settings_meta_data_update', - array( - 'productmeta_name' => $productmeta_name, - 'dynamic_price_display' => $dynamic_price_hide, - 'send_file_attachment' => $send_file_attachment, - 'show_cart_thumb' => $show_cart_thumb, - 'aviary_api_key' => trim( $aviary_api_key ), - 'productmeta_style' => $productmeta_style, - 'productmeta_js' => $productmeta_js, - 'productmeta_categories' => $productmeta_categories, - 'the_meta' => $product_meta, - ), - $productmeta_id + $ppom_settings_meta_data = array( + 'productmeta_name' => $productmeta_name, + 'dynamic_price_display' => $dynamic_price_hide, + 'send_file_attachment' => $send_file_attachment, + 'show_cart_thumb' => $show_cart_thumb, + 'aviary_api_key' => trim( $aviary_api_key ), + 'productmeta_categories' => $productmeta_categories, + 'the_meta' => $product_meta, ); + if ( ! ppom_is_legacy_user() ) { + $ppom_settings_meta_data['productmeta_style'] = $productmeta_style; + $ppom_settings_meta_data['productmeta_js'] = $productmeta_js; + } + + $dt = apply_filters( 'ppom_settings_meta_data_update', $ppom_settings_meta_data, $productmeta_id ); // wp_send_json($dt); diff --git a/inc/functions.php b/inc/functions.php index 6751eab0..aa7663f1 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2389,3 +2389,15 @@ function ppom_check_pro_compatibility($feature_slug) { return isset( PPOM_PRO_COMPATIBILITY_FEATURES[ $feature_slug ] ) && PPOM_PRO_COMPATIBILITY_FEATURES[ $feature_slug ]; } + +/** + * Check is legacy user. + * + * @return bool + */ +function ppom_is_legacy_user() { + if ( ppom_pro_is_installed() && ( function_exists( '\PPOM_Pro\get_license_status' ) && 'valid' === \PPOM_Pro\get_license_status( false ) ) ) { + return false; + } + return 'no' === get_option( 'ppom_legacy_user', '' ); +} diff --git a/templates/admin/ppom-fields.php b/templates/admin/ppom-fields.php index 6f43b89d..136703f5 100644 --- a/templates/admin/ppom-fields.php +++ b/templates/admin/ppom-fields.php @@ -189,6 +189,15 @@ class="dashicons dashicons-editor-help">
+ +
+
+
+

Upgrade to the Pro plan to unlock the ability to fully customize your fields\' appearance and functionality.', 'woocommerce-product-addon' ), esc_url( tsdk_utmify( PPOM_UPGRADE_URL, 'customstyle' ) ) ); ?>

+
+
+
+