Skip to content

Commit

Permalink
Merge pull request #357 from Codeinwp/feat/pro/426
Browse files Browse the repository at this point in the history
Restrict custom style uses for free users
  • Loading branch information
selul authored Sep 23, 2024
2 parents 22cacd8 + 0e45460 commit 7849396
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 33 deletions.
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

0 comments on commit 7849396

Please sign in to comment.