Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict custom style uses for free users #357

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions classes/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function __construct() {
10
);

add_action( 'admin_init', array( $this, 'set_legacy_user' ) );
add_action( 'admin_init', array( $this, 'ppom_create_db_tables' ) );
}

Expand Down Expand Up @@ -493,6 +494,22 @@ 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' );
}


/**
* Create database tables.
*/
Expand Down
11 changes: 9 additions & 2 deletions classes/fields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,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(
Expand All @@ -105,7 +109,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(
Expand Down
4 changes: 2 additions & 2 deletions classes/frontend-scripts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions css/ppom-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,10 @@ a[data-modal-id="ppom-nm-plugins-modal"] {
padding: 15px 30px 0 0;
}

.ppom-admin-tabs-css .ppom-admin-tab-content .notice-info {
margin: 10px 0;
padding: 10px 5px;
}
/* CSS for popup.js */
.ppom-popup-overlay {
position: fixed;
Expand Down Expand Up @@ -1291,4 +1295,7 @@ a[data-modal-id="ppom-nm-plugins-modal"] {
text-align: left;
padding-bottom: 10px;
padding-top: 20px;

.ppom-admin-tabs-css .ppom-admin-tab-content .notice-info p {
margin: 0;
}
58 changes: 29 additions & 29 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,22 +305,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);

Expand Down Expand Up @@ -460,22 +461,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);

Expand Down
12 changes: 12 additions & 0 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2404,3 +2404,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', '' );
}
9 changes: 9 additions & 0 deletions templates/admin/ppom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ class="dashicons dashicons-editor-help"></i></span>
<input type="radio" name="css-tabs" id="ppom-style-tab">
<label for="ppom-style-tab" class="ppom-tab-label">Style</label>
<div class="ppom-admin-tab-content">
<?php if ( ppom_is_legacy_user() ) : ?>
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="notice notice-info">
<p><?php echo sprintf( __( 'Custom CSS and JS customization is not available on your current plan. <a href="%s" target="_blank">Upgrade to the Pro</a> plan to unlock the ability to fully customize your fields\' appearance and functionality.', 'woocommerce-product-addon' ), esc_url( tsdk_utmify( PPOM_UPGRADE_URL, 'customstyle' ) ) ); ?></p>
</div>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="form-group">
Expand Down
Loading