Skip to content

Commit

Permalink
release: fixes
Browse files Browse the repository at this point in the history
### Bug Fixes
- [PHP 8.2] Fixed deprecation notices
- Fixed the choose file issue
- Fixed REST API compatibility issue with PHP8
- Fixed edit cart issue
- Fixed repeater fields issue
- Fixed user permission issue
- Fixed texter popup height/width issue
- Added shortcode rendering support in the field description
- Fixed cart subtotal issue checkbox fixed fee option
- Fixed date looses issue
- Fixed typo for Square name in Image Cropper
- Updated dependencies
- Enhanced security
  • Loading branch information
vytisbulkevicius authored Feb 28, 2024
2 parents a54e329 + e374365 commit a2f46ad
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 125 deletions.
11 changes: 10 additions & 1 deletion classes/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class NM_PersonalizedProduct_Admin extends NM_PersonalizedProduct {

var $menu_pages, $plugin_scripts_admin, $plugin_settings;

/**
* Plugin meta data.
*
* @var string $plugin_meta
*/
public $plugin_meta = array();

function __construct() {

// setting plugin meta saved in config.php
Expand Down Expand Up @@ -48,12 +55,14 @@ function __construct() {
)
);

add_action( 'init', array( 'NM_PersonalizedProduct', 'set_ppom_menu_permission' ) );

// Getting products list
add_action( 'wp_ajax_ppom_get_products', array( $this, 'get_products' ) );
add_action( 'wp_ajax_ppom_attach_ppoms', array( $this, 'ppom_attach_ppoms' ) );

// Adding setting tab in WooCommerce
if ( ! ppom_settings_migrated() ) {
if ( ! ppom_settings_migrated() && current_user_can( 'manage_options' ) ) {
add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
// Display settings
add_action( 'woocommerce_settings_tabs_ppom_settings', array( $this, 'settings_tab' ) );
Expand Down
33 changes: 19 additions & 14 deletions classes/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @version 1.0
*/

/*
**========== Block direct access ===========
/*
**========== Block direct access ===========
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down Expand Up @@ -37,7 +37,7 @@ class PPOM_Form {
*
* @var object
*/
// public static $product;
public $product;

/**
* Return templates args
Expand All @@ -48,7 +48,6 @@ class PPOM_Form {

function __construct( $product, $args ) {


$this->product = $product;

$this->product_id = ppom_get_product_id( $this->product );
Expand Down Expand Up @@ -81,11 +80,11 @@ function wrapper_inner_classes() {
}

/**
* PPOM fields rendering callback
* PPOM fields rendering callback.
*
* @return fields html
* @param int $meta_id Meta ID.
*/
function ppom_fields_render() {
function ppom_fields_render( $meta_id = 0 ) {

$posted_values = '';

Expand All @@ -97,8 +96,13 @@ function ppom_fields_render() {
// posted value being
// used ppom-pro
$posted_values = apply_filters( 'ppom_default_values', $posted_values, $_POST, $this->product_id, self::$args );

foreach ( self::$ppom->fields as $meta ) {
$fields = array_filter(
self::$ppom->fields,
function( $field ) use ( $meta_id ) {
return (int) $meta_id === (int) $field['ppom_id'];
}
);
foreach ( $fields as $meta ) {

$type = isset( $meta['type'] ) ? $meta['type'] : '';
$title = isset( $meta['title'] ) ? ppom_wpml_translate( $meta['title'], 'PPOM' ) : '';
Expand Down Expand Up @@ -175,7 +179,6 @@ function ppom_fields_render() {
continue;
}


$field_wrapper_div = '<div data-data_name=' . esc_attr( $data_name ) . ' ' . $ppom_cond_data . ' class="' . esc_attr( $field_wrapper_class ) . '">';
$field_html .= apply_filters( 'ppom_field_wrapper_div', $field_wrapper_div, $meta, $this->product );

Expand Down Expand Up @@ -360,12 +363,14 @@ function get_field_default_value( $posted_values, $data_name, $meta ) {
default:
$default_value = $posted_values[ $data_name ];
break;
}
}
} elseif ( isset( $_GET[ $data_name ] ) ) {
// When Cart Edit addon used
$default_value = sanitize_text_field( $_GET[ $data_name ] );
// When Cart Edit addon used.
$edit_data = isset( $_GET[ $data_name ] ) ? $_GET[ $data_name ] : '';
$default_value = is_array( $edit_data ) ? map_deep( $edit_data, 'sanitize_text_field' ) : sanitize_text_field( $_GET[ $data_name ] );
} elseif ( isset( $_POST['ppom']['fields'][ $data_name ] ) && apply_filters( 'ppom_retain_after_add_to_cart', true ) ) {
$default_value = sanitize_text_field( $_POST['ppom']['fields'][ $data_name ] );
$edit_data = isset( $_POST['ppom']['fields'][ $data_name ] ) ? $_POST['ppom']['fields'][ $data_name ] : '';
$default_value = is_array( $edit_data ) ? map_deep( $edit_data, 'sanitize_text_field' ) : sanitize_text_field( $_GET[ $data_name ] );
} else {
// Default values in settings
switch ( $type ) {
Expand Down
4 changes: 2 additions & 2 deletions classes/input-meta.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ function desc() {

// old Filter
$desc = apply_filters( 'ppom_description_content', $desc, self::$input_meta );

return apply_filters( 'ppom_input_meta_desc', $desc, self::$input_meta );
$desc = apply_filters( 'ppom_input_meta_desc', $desc, self::$input_meta );
return apply_filters( 'the_content', $desc );
}


Expand Down
7 changes: 7 additions & 0 deletions classes/input.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class PPOM_Inputs {
*/
private static $ins = null;

/**
* Icon.
*
* @var string $icon
*/
public $icon = '';


/**
* __construct function.
Expand Down
2 changes: 1 addition & 1 deletion classes/inputs/input.cropper.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function get_settings() {
'title' => __( 'Viewport type', 'woocommerce-product-addon' ),
'desc' => __( 'Select Squar or circle, see help', 'woocommerce-product-addon' ),
'options' => array(
'square' => 'Squar',
'square' => 'Square',
'circle' => 'Circle',
),
'col_classes' => array( 'col-md-3', 'col-sm-12' ),
Expand Down
3 changes: 2 additions & 1 deletion classes/legacy-meta.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function desc() {
$desc = ppom_wpml_translate( $desc, 'PPOM' );

// old Filter
return apply_filters( 'ppom_description_content', $desc, self::$input_meta );
$desc = apply_filters( 'ppom_description_content', $desc, self::$input_meta );
return apply_filters( 'the_content', $desc );
}


Expand Down
23 changes: 14 additions & 9 deletions classes/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function __construct() {
}


// add_filter( 'woocommerce_cart_item_subtotal', 'ppom_woocommerce_item_subtotal', 10, 3);
add_filter( 'woocommerce_cart_item_subtotal', 'ppom_woocommerce_item_subtotal', 10, 3);
add_filter( 'woocommerce_checkout_cart_item_quantity', 'ppom_woocommerce_control_checkout_quantity', 10, 3 );
add_filter( 'woocommerce_order_item_quantity_html', 'ppom_woocommerce_control_oder_item_quantity', 10, 2 );
add_filter( 'woocommerce_email_order_item_quantity', 'ppom_woocommerce_control_email_item_quantity', 10, 2 );
Expand Down Expand Up @@ -680,15 +680,20 @@ public static function deactivate_plugin() {
* Set PPOM Menu Access via Settings
* */
public static function set_ppom_menu_permission() {

$ppom_roles = ppom_get_option( 'ppom_permission_mfields', array() );
foreach ( $ppom_roles as $r ) {

// if( $r == 'administrator' ) continue;

$wp_role = get_role( $r );
if ( $wp_role ) {
$wp_role->add_cap( 'ppom_options_page' );
$roles = wp_roles();
foreach ( $roles->roles as $key => $r ) {
$wp_role = get_role( $key );
if ( in_array( $key, $ppom_roles, true ) ) {
if ( $wp_role ) {
if ( ! $wp_role->has_cap( 'ppom_options_page' ) ) {
$wp_role->add_cap( 'ppom_options_page' );
}
}
} else {
if ( $wp_role->has_cap( 'ppom_options_page' ) ) {
$wp_role->remove_cap( 'ppom_options_page' );
}
}
}
}
Expand Down
112 changes: 104 additions & 8 deletions classes/ppom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,90 @@ class PPOM_Meta {
private static $ins = null;
public static $product_id;

/**
* Plugin category data.
*
* @var array $category_meta
*/
public $category_meta = array();

/**
* Plugin category array.
*
* @var array $ppom_with_cat
*/
public $ppom_with_cat = array();

/**
* Plugin settings.
*
* @var array $ppom_settings
*/
public $ppom_settings = array();

/**
* Fields.
*
* @var bool $is_exists
*/
public $is_exists = false;

/**
* Meta ID.
*
* @var int $single_meta_id
*/
public $single_meta_id = 0;

/**
* Check has multiple meta.
*
* @var bool $has_multiple_meta
*/
public $has_multiple_meta = false;

/**
* Check ajax validation enabled or not.
*
* @var bool $ajax_validation_enabled
*/
public $ajax_validation_enabled = false;

/**
* Inline CSS.
*
* @var string $inline_css
*/
public $inline_css = '';

/**
* Inline JS.
*
* @var string $inline_js
*/
public $inline_js = '';

/**
* Price display.
*
* @var string $price_display
*/
public $price_display = '';

/**
* Meta title.
*
* @var string $meta_title
*/
public $meta_title = '';

/**
* Fields.
*
* @var string $fields
*/
public $fields = array();

// QM-5
var $meta_id;

Expand Down Expand Up @@ -105,14 +189,14 @@ function get_meta_id( $product_id ) {
$ppom_product_id = array_merge( $ppom_in_category, $ppom_product_id );
} else {
$ppom_product_id = array_merge( $ppom_product_id, $ppom_in_category );
}
}
} elseif ( ! $ppom_product_id ) { // If no meta groups attached to products

$ppom_product_id = $ppom_in_category;
}
break;

}
}
}

return apply_filters( 'ppom_product_meta_id', $ppom_product_id, $product_id );
Expand Down Expand Up @@ -170,8 +254,20 @@ function settings() {
}

global $wpdb;
$qry = 'SELECT * FROM ' . $wpdb->prefix . PPOM_TABLE_META . " WHERE productmeta_id = {$meta_id}";
$meta_settings = $wpdb->get_row( $qry );

if ( is_array( $meta_id ) ) {
$meta_id = implode( ',', $meta_id );
}

$qry = 'SELECT * FROM ' . $wpdb->prefix . PPOM_TABLE_META . " WHERE productmeta_id IN($meta_id)";
$meta_settings = $wpdb->get_results( $qry );
$filter_meta = array_filter(
$meta_settings,
function( $meta ) {
return 'on' === $meta->productmeta_validation ? $meta : false;
}
);
$meta_settings = ! empty( $filter_meta ) ? reset( $filter_meta ) : reset( $meta_settings );

$meta_settings = empty( $meta_settings ) ? null : $meta_settings;

Expand Down Expand Up @@ -216,7 +312,7 @@ function get_fields() {
(array) $meta_fields,
function ( $field ) {
return ! isset( $field['status'] ) || $field['status'] == 'on';
}
}
);

// ppom_pa($meta_fields);
Expand Down Expand Up @@ -246,14 +342,14 @@ function get_fields_by_id( $ppom_id ) {
$meta_fields,
function ( $field ) {
return ! isset( $field['status'] ) || $field['status'] == 'on';
}
}
);

$meta_fields = array_filter(
$meta_fields,
function ( $field ) {
return ! isset( $field['status'] ) || $field['status'] == 'on';
}
}
);

// if( empty($meta_fields) ) return null;
Expand Down Expand Up @@ -288,7 +384,7 @@ function ppom_has_category_meta( $product_id ) {
$meta_found[] = $meta_cats->productmeta_id;
}
}
}
}
}
}
}
Expand Down
Loading

0 comments on commit a2f46ad

Please sign in to comment.