Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/uni-woo-custom-product-options/class-uni-cpo.php
+++ b/uni-woo-custom-product-options/class-uni-cpo.php
@@ -6,62 +6,52 @@
/**
* Uni_Cpo Class
*/
-final class Uni_Cpo {
+final class Uni_Cpo
+{
/**
* Uni_Cpo version.
*
* @var string
*/
- public $version = '4.9.69';
-
+ public $version = '4.9.11' ;
/**
* The single instance of the class.
*
* @var Uni_Cpo
*/
- protected static $_instance = null;
-
+ protected static $_instance = null ;
/**
* Option factory instance.
*
* @var Uni_Cpo_Option_Factory
*/
- public $option_factory = null;
-
+ public $option_factory = null ;
/**
* Module factory instance.
*
* @var Uni_Cpo_Module_Factory
*/
- public $module_factory = null;
-
+ public $module_factory = null ;
/**
* Plugin's settings
*
* @var Uni_Cpo_Option_Factory
*/
- public $settings_scheme = [];
-
+ public $settings_scheme = array() ;
/**
* Is pro
*
* @var Uni_Cpo_Option_Factory
*/
- protected $is_pro = false;
-
- protected $debug_mode = false;
-
+ protected $is_pro = false ;
+ protected $debug_mode = false ;
/**
*
*/
- protected $var_slug;
-
- protected $nov_slug;
-
- protected $builder_id;
-
- private static $plugin_updates = array();
-
+ protected $var_slug ;
+ protected $nov_slug ;
+ protected $builder_id ;
+ private static $plugin_updates = array() ;
/**
* Throw error on object clone
*
@@ -71,39 +61,43 @@
* @return void
* @since 1.0.0
*/
- public function __clone() {
+ public function __clone()
+ {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'uni-cpo' ), '1.0.0' );
}
-
+
/**
* Disable unserializing of the class
*
* @return void
* @since 1.0.0
*/
- public function __wakeup() {
+ public function __wakeup()
+ {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'uni-cpo' ), '1.0.0' );
}
-
+
/**
* Main Uni_Cpo Instance
*/
- public static function instance() {
+ public static function instance()
+ {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
-
+
/**
* Uni_Cpo Constructor.
*/
- public function __construct() {
+ public function __construct()
+ {
$this->define_constants();
$this->is_pro = unicpo_fs()->is__premium_only();
$this->includes();
$this->init_hooks();
- add_action( 'activated_plugin', array($this, 'activation') );
+ add_action( 'activated_plugin', array( $this, 'activation' ) );
$this->var_slug = 'uni_cpo_';
$this->nov_slug = 'uni_nov_cpo_';
$this->builder_id = 'uni_cpo_options';
@@ -111,18 +105,20 @@
$this->debug_mode = true;
}
}
-
+
/**
* Init hooks
*/
- private function init_hooks() {
- add_action( 'init', array($this, 'init'), 0 );
+ private function init_hooks()
+ {
+ add_action( 'init', array( $this, 'init' ), 0 );
}
-
+
/**
* Define Uni_Cpo Constants.
*/
- private function define_constants() {
+ private function define_constants()
+ {
$upload_dir = wp_upload_dir();
$plugin_settings = $this->get_settings();
$this->define( 'UNI_CPO_PLUGIN_FILE', __FILE__ );
@@ -133,19 +129,20 @@
$this->define( 'UNI_CPO_CSS_URI', trailingslashit( $upload_dir['baseurl'] ) . 'cpo-css' );
$this->define( 'UNI_CPO_TEMP_DIR', wp_normalize_path( trailingslashit( $upload_dir['basedir'] ) . 'cpo_temp' ) );
}
-
+
/**
* Define constant if not already set.
*
* @param string $name
* @param string|bool $value
*/
- private function define( $name, $value ) {
+ private function define( $name, $value )
+ {
if ( !defined( $name ) ) {
define( $name, $value );
}
}
-
+
/**
* What type of request is this?
*
@@ -153,7 +150,8 @@
*
* @return bool
*/
- private function is_request( $type ) {
+ private function is_request( $type )
+ {
switch ( $type ) {
case 'admin':
return is_admin();
@@ -165,15 +163,12 @@
return (!is_admin() || defined( 'DOING_AJAX' )) && !defined( 'DOING_CRON' );
}
}
-
+
/**
* Includes
*/
- public function includes() {
- if ( $this->is_pro() ) {
- // Initialize composer autoloader
- $this->init_autoloader();
- }
+ public function includes()
+ {
//
include_once UNI_CPO_ABSPATH . 'includes/abstracts/abstract-uni-cpo-data.php';
include_once UNI_CPO_ABSPATH . 'includes/abstracts/abstract-uni-cpo-option.php';
@@ -198,7 +193,8 @@
//
include_once UNI_CPO_ABSPATH . 'includes/uni-cpo-option-functions.php';
// TODO differentiate inclusion of files when edit mode on or off
- if ( $this->is_request( 'frontend' ) || $this->is_request( 'admin' ) || $this->is_request( 'cron' ) ) {
+
+ if ( $this->is_request( 'frontend' ) || $this->is_request( 'admin' ) ) {
// row / column / modules
include_once UNI_CPO_ABSPATH . 'includes/modules/class-uni-cpo-module-row.php';
include_once UNI_CPO_ABSPATH . 'includes/modules/class-uni-cpo-module-column.php';
@@ -210,10 +206,10 @@
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-text-input.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-radio.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-select.php';
+
if ( $this->is_pro() ) {
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-checkbox.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-file-upload.php';
- include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-multi-file-upload.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-datepicker.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-range-slider.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-dynamic-notice.php';
@@ -222,21 +218,12 @@
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-google-map.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-distance-by-postcode.php';
include_once UNI_CPO_ABSPATH . 'includes/options/class-uni-cpo-option-font-preview.php';
- $option_classes_pro = apply_filters( 'uni_cpo_option_classes_pro', [] );
- if ( !empty( $option_classes_pro ) ) {
- foreach ( $option_classes_pro as $option_class ) {
- include_once $option_class;
- }
- }
- }
- $option_classes = apply_filters( 'uni_cpo_option_classes', [] );
- if ( !empty( $option_classes ) ) {
- foreach ( $option_classes as $option_class ) {
- include_once $option_class;
- }
}
+
}
- if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) {
+
+
+ if ( $this->is_request( 'frontend' ) ) {
// settings
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-width-type.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-width.php';
@@ -279,12 +266,6 @@
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-class-name.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-offset-px.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-gap-px.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-display.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-flex-direction.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-justify-content.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-align-items.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-gap.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-flex-wrap.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-float.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-content.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-align.php';
@@ -297,7 +278,6 @@
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-sync.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-slug.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-is-required.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-is-searchable.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-is-datepicker-disabled.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-is-timepicker.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-timepicker-type.php';
@@ -327,7 +307,6 @@
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-geom-radio.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-upload-mode.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-max-filesize.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-max-files.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-mime-types.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-mode-checkbox.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-geom-checkbox.php';
@@ -349,6 +328,7 @@
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-is-sc.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-sc-default.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-sc-scheme.php';
+
if ( $this->is_pro() ) {
// radio
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-encoded-image.php';
@@ -363,8 +343,6 @@
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-date-conjunction.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-disabled-dates.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-date-rules.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-first-day-of-week.php';
- include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-date-format.php';
// range slider
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-range-type.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-range-grid.php';
@@ -381,22 +359,12 @@
// map
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-map-center.php';
include_once UNI_CPO_ABSPATH . 'includes/settings/class-uni-cpo-setting-cpo-map-zoom.php';
- $settings_classes_pro = apply_filters( 'uni_cpo_settings_classes_pro', [] );
- if ( !empty( $settings_classes_pro ) ) {
- foreach ( $settings_classes_pro as $settings_class ) {
- include_once $settings_class;
- }
- }
- }
- $settings_classes = apply_filters( 'uni_cpo_settings_classes', [] );
- if ( !empty( $settings_classes ) ) {
- foreach ( $settings_classes as $settings_class ) {
- include_once $settings_class;
- }
}
+
// common js templates
include_once UNI_CPO_ABSPATH . 'includes/class-uni-cpo-templates.php';
}
+
if ( $this->is_request( 'admin' ) || $this->is_request( 'ajax' ) ) {
}
if ( $this->is_request( 'ajax' ) ) {
@@ -411,11 +379,12 @@
include_once UNI_CPO_ABSPATH . 'includes/class-uni-cpo-product.php';
include_once UNI_CPO_ABSPATH . 'includes/uni-cpo-core-functions.php';
}
-
+
/**
* Init
*/
- public function init() {
+ public function init()
+ {
// Before init action.
do_action( 'before_uni_cpo_init' );
$this->check_version();
@@ -425,91 +394,55 @@
//
$this->option_factory = new Uni_Cpo_Option_Factory();
$this->module_factory = new Uni_Cpo_Module_Factory();
- $this->settings_scheme = new Uni_Cpo_Plugin_Settings(__FILE__);
- add_action( 'admin_enqueue_scripts', array($this, 'admin_scripts'), 10 );
- // Dropbox OAuth actions
- add_action( 'admin_post_uni_cpo_dropbox_auth', array($this, 'handle_dropbox_auth') );
- add_action( 'admin_post_uni_cpo_dropbox_callback', array($this, 'handle_dropbox_callback') );
- add_action( 'admin_post_uni_cpo_dropbox_revoke', array($this, 'handle_dropbox_revoke') );
- // Google Drive OAuth actions
- add_action( 'admin_post_uni_cpo_gdrive_authorize', array($this, 'handle_gdrive_authorize') );
- add_action( 'admin_post_uni_cpo_gdrive_revoke', array($this, 'handle_gdrive_revoke') );
- // Google Drive OAuth callback (handled in admin page)
- add_action( 'admin_init', array($this, 'handle_gdrive_callback') );
+ $this->settings_scheme = new Uni_Cpo_Plugin_Settings( __FILE__ );
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 10 );
// Init action.
do_action( 'uni_cpo_init' );
- if ( isset( $_GET['order_again'] ) ) {
- add_filter(
- 'woocommerce_add_to_cart_validation',
- 'uni_cpo_woocommerce_add_to_cart_validation',
- 10,
- 6
- );
- }
- add_shortcode( 'unicpo_form', array($this, 'product_form_shortcode') );
- add_action(
- 'woocommerce_product_options_sku',
- array($this, 'info_about_dynamic_discount'),
- 10,
- 11
- );
- }
-
- /**
- * @return void
- */
- public function info_about_dynamic_discount() {
- if ( !function_exists( 'UniCpoCustomSku' ) ) {
- echo '<p>' . sprintf( __( 'Uni CPO users can use <strong>dynamic SKU</strong> functionality after installing %s add-on.', 'uni-cpo' ), '<a href="https://moomoo-agency.gitbook.io/uni-cpo-4-documentation/uni-cpo-add-ons/dynamic-sku-for-woocommerce" target="_blank">' . __( '"Custom SKU"', 'uni-cpo' ) . '</a>' ) . '</p>';
- }
- }
-
- /**
- * @return void
- */
- public function product_form_shortcode() {
- do_action( 'woocommerce_before_add_to_cart_button' );
}
-
+
/**
* Get the builder container CSS ID
*/
- public function get_builder_id() {
+ public function get_builder_id()
+ {
return $this->builder_id;
}
-
+
/**
* get_var_slug
*/
- public function get_var_slug() {
+ public function get_var_slug()
+ {
return $this->var_slug;
}
-
+
/**
* get_nov_slug
*/
- public function get_nov_slug() {
+ public function get_nov_slug()
+ {
return $this->nov_slug;
}
-
+
/**
* is_debug
*/
- public function is_debug() {
+ public function is_debug()
+ {
return $this->debug_mode;
}
-
+
/**
* Scripts and styles used in back end
* @since 1.0.0
*/
- function admin_scripts() {
+ function admin_scripts()
+ {
$screen = get_current_screen();
$screen_id = ( $screen ? $screen->id : '' );
- $post_type = ( $screen ? $screen->post_type : '' );
$localizations = Uni_Cpo_Frontend_Scripts::get_localizations();
- $order_meta_boxes = wc_get_order_types( 'order-meta-boxes' );
- if ( in_array( $screen_id, array('product', 'edit-product') ) ) {
+
+ if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) {
wp_enqueue_style(
'uni-cpo-styles-product',
$this->plugin_url() . '/assets/css/admin-product.css',
@@ -517,14 +450,7 @@
UNI_CPO_VERSION,
'all'
);
- wp_register_script(
- 'uni-cpo-scripts-product',
- $this->plugin_url() . '/assets/js/admin-product.js',
- array(),
- UNI_CPO_VERSION
- );
- wp_enqueue_script( 'uni-cpo-scripts-product' );
- } elseif ( in_array( str_replace( 'edit-', '', $screen_id ), $order_meta_boxes ) || in_array( str_replace( 'edit-', '', $post_type ), $order_meta_boxes ) ) {
+ } elseif ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
wp_register_script(
'moment',
$this->plugin_url() . '/includes/vendors/moment/moment.min.js',
@@ -535,30 +461,29 @@
'flatpickr',
$this->plugin_url() . '/includes/vendors/flatpickr/flatpickr.js',
array(),
- '4.6.13'
+ '4.3.2'
);
wp_register_script(
'parsleyjs',
$this->plugin_url() . '/includes/vendors/parsleyjs/parsley.min.js',
- array('jquery'),
+ array( 'jquery' ),
'2.8.0'
);
wp_register_script(
'parsley-localization',
$this->plugin_url() . '/includes/vendors/parsleyjs/i18n/en.js',
- array('parsleyjs'),
+ array( 'parsleyjs' ),
'2.8.0'
);
- $order_script_deps = array(
+ wp_register_script(
+ 'uni-cpo-scripts-order',
+ $this->plugin_url() . '/assets/js/admin-order.js',
+ array(
'wc-admin-order-meta-boxes',
'moment',
'flatpickr',
'parsleyjs'
- );
- wp_register_script(
- 'uni-cpo-scripts-order',
- $this->plugin_url() . '/assets/js/admin-order.js',
- $order_script_deps,
+ ),
UNI_CPO_VERSION
);
wp_enqueue_script( 'uni-cpo-scripts-order' );
@@ -591,7 +516,7 @@
UNI_CPO_VERSION,
'all'
);
- } elseif ( in_array( $screen_id, array('woocommerce_page_uni-cpo-import-export', 'woocommerce_page_uni-cpo-settings', 'woocommerce_page_uni-cpo-bulk-edit') ) ) {
+ } elseif ( in_array( $screen_id, array( 'woocommerce_page_uni-cpo-import-export', 'woocommerce_page_uni-cpo-settings' ) ) ) {
wp_enqueue_style(
'uni-cpo-styles-settings',
$this->plugin_url() . '/assets/css/admin-settings.css',
@@ -602,11 +527,11 @@
wp_register_script(
'uni-cpo-scripts-settings',
$this->plugin_url() . '/assets/js/admin-settings.js',
- array('jquery'),
+ array( 'jquery' ),
UNI_CPO_VERSION
);
wp_enqueue_script( 'uni-cpo-scripts-settings' );
- } elseif ( in_array( $screen_id, array('woocommerce_page_uni-cpo-manager') ) ) {
+ } elseif ( in_array( $screen_id, array( 'woocommerce_page_uni-cpo-manager' ) ) ) {
wp_register_script(
'uni-cpo-manager',
$this->plugin_url() . '/assets/js/unicpo-managers.js',
@@ -621,64 +546,70 @@
'currency' => get_woocommerce_currency_symbol(),
);
wp_localize_script( 'uni-cpo-manager', 'unicpoManager', $manager );
- } elseif ( in_array( $screen_id, array('woocommerce_page_uni-cpo-settings') ) ) {
+ } elseif ( in_array( $screen_id, array( 'woocommerce_page_uni-cpo-settings' ) ) ) {
wp_enqueue_style( 'farbtastic' );
wp_enqueue_script( 'farbtastic' );
wp_enqueue_media();
wp_register_script(
'uni-cpo-admin-utils',
$this->plugin_url() . '/assets/js/admin-utils.js',
- array('farbtastic', 'jquery'),
+ array( 'farbtastic', 'jquery' ),
UNI_CPO_VERSION
);
wp_enqueue_script( 'uni-cpo-admin-utils' );
}
+
}
-
+
/**
* load_plugin_textdomain()
*/
- public function load_plugin_textdomain() {
+ public function load_plugin_textdomain()
+ {
$locale = apply_filters( 'plugin_locale', get_locale(), 'uni-cpo' );
load_textdomain( 'uni-cpo', WP_LANG_DIR . '/uni-woo-custom-product-options/uni-cpo-' . $locale . '.mo' );
load_plugin_textdomain( 'uni-cpo', false, plugin_basename( dirname( __FILE__ ) ) . "/languages" );
}
-
+
/**
* check_version()
*/
- public function check_version() {
+ public function check_version()
+ {
$current_version = get_option( 'uni_cpo_version', null );
if ( is_null( $current_version ) ) {
update_option( 'uni_cpo_version', $this->version );
}
- if ( !defined( 'IFRAME_REQUEST' ) && !empty( $plugin_updates ) && version_compare( $current_version, max( array_keys( self::$plugin_updates ) ), '<' ) ) {
+
+ if ( !defined( 'IFRAME_REQUEST' ) && !empty($plugin_updates) && version_compare( $current_version, max( array_keys( self::$plugin_updates ) ), '<' ) ) {
$this->update_plugin();
do_action( 'uni_cpo_updated' );
}
+
}
-
+
/**
* is_pro()
*/
- public function is_pro() {
+ public function is_pro()
+ {
return $this->is_pro;
}
-
+
/**
* default_settings()
*/
- function default_settings() {
+ function default_settings()
+ {
return array(
'ajax_add_to_cart' => '',
'product_price_container' => '.summary.entry-summary .price > .amount bdi, .summary.entry-summary .price ins .amount bdi',
- 'product_image_container' => 'div.woocommerce-product-gallery__wrapper',
+ 'product_image_container' => 'figure.woocommerce-product-gallery__wrapper',
'product_image_size' => 'woocommerce_single',
'product_thumbnails_container' => 'ol.flex-control-thumbs',
'gmap_api_key' => '',
'csv_delimiter' => ';',
'order_edit_role' => 'administrator',
- 'change_product_image_in_cart' => 'on',
'display_weight_in_cart' => '',
'display_dimensions_in_cart' => '',
'range_slider_style' => 'html5',
@@ -687,414 +618,59 @@
'file_storage' => 'local',
'custom_path_enable' => '',
'custom_path' => '',
- 'dropbox_app_key' => '',
- 'dropbox_app_secret' => '',
+ 'dropbox_token' => '',
'free_sample_enable' => '',
'free_samples_limit' => '',
);
}
-
+
/**
* get_settings()
*/
- function get_settings() {
+ function get_settings()
+ {
$settings = get_option( 'uni_cpo_settings_general', $this->default_settings() );
- // Ensure $settings is an array to prevent array_merge() errors
- if ( !is_array( $settings ) ) {
- $settings = $this->default_settings();
- }
return array_merge( $this->default_settings(), $settings );
}
-
+
/**
* update_plugin()
*/
- private function update_plugin() {
+ private function update_plugin()
+ {
// Silence
}
-
+
/**
* plugin_url()
*/
- public function plugin_url() {
+ public function plugin_url()
+ {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
-
+
/**
* plugin_path()
*/
- public function plugin_path() {
+ public function plugin_path()
+ {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
-
+
/**
* Get Ajax URL.
* @return string
*/
- public function ajax_url() {
+ public function ajax_url()
+ {
return admin_url( 'admin-ajax.php', 'relative' );
}
-
+
/**
* cpo_activation()
*/
- public function activation( $plugin ) {
- }
-
- /**
- * Initialize composer autoloader for dependencies
- */
- private function init_autoloader() {
- static $autoloader_loaded = false;
- if ( !$autoloader_loaded ) {
- $autoloader_path = UNI_CPO_ABSPATH . 'vendor/autoload.php';
- if ( file_exists( $autoloader_path ) ) {
- require_once $autoloader_path;
- $autoloader_loaded = true;
- if ( function_exists( 'uni_cpo_log_cloud_operation' ) ) {
- uni_cpo_log_cloud_operation( "Composer autoloader loaded successfully from: {$autoloader_path}", 'info' );
- }
- } else {
- if ( function_exists( 'uni_cpo_log_cloud_operation' ) ) {
- uni_cpo_log_cloud_operation( "Composer autoloader not found at: {$autoloader_path}. Please run composer install.", 'error' );
- }
- error_log( "Uni CPO: Composer autoloader not found at: {$autoloader_path}" );
- }
- }
- }
-
- /**
- * Load composer dependencies (backward compatibility method)
- */
- private function load_dropbox_sdk() {
- $this->init_autoloader();
- }
-
- /**
- * Handle Dropbox authorization redirect
- */
- public function handle_dropbox_auth() {
- if ( $this->is_pro() ) {
- // Check if user can manage options
- if ( !current_user_can( 'manage_options' ) ) {
- wp_die( __( 'Unauthorized', 'uni-cpo' ) );
- }
- $settings = $this->get_settings();
- $app_key = ( isset( $settings['dropbox_app_key'] ) ? $settings['dropbox_app_key'] : '' );
- $app_secret = ( isset( $settings['dropbox_app_secret'] ) ? $settings['dropbox_app_secret'] : '' );
- if ( empty( $app_key ) || empty( $app_secret ) ) {
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&error=missing_credentials' ) );
- exit;
- }
- try {
- // Include the new Dropbox SDK and all required dependencies
- $this->load_dropbox_sdk();
- // Include our custom WordPress-compatible persistent data store
- require_once UNI_CPO_ABSPATH . 'includes/cloud-storage/class-uni-cpo-wordpress-persistent-data-store.php';
- // Create Dropbox app instance with custom persistent data store
- $app = new KunnuDropboxDropboxApp($app_key, $app_secret);
- $persistentDataStore = new Uni_Cpo_WordPress_Persistent_Data_Store();
- $config = [
- 'persistent_data_store' => $persistentDataStore,
- ];
- $dropbox = new KunnuDropboxDropbox($app, $config);
- $authHelper = $dropbox->getAuthHelper();
- // Get authorization URL (CSRF token will be auto-generated and stored by the SDK)
- $redirectUri = admin_url( 'admin-post.php?action=uni_cpo_dropbox_callback' );
- $authUrl = $authHelper->getAuthUrl(
- $redirectUri,
- [],
- null,
- 'offline'
- );
- // Redirect to Dropbox authorization
- wp_redirect( $authUrl );
- exit;
- } catch ( Exception $e ) {
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&error=' . urlencode( $e->getMessage() ) ) );
- exit;
- }
- }
- }
-
- /**
- * Handle Dropbox OAuth callback
- */
- public function handle_dropbox_callback() {
- if ( $this->is_pro() ) {
- // Check if user can manage options
- if ( !current_user_can( 'manage_options' ) ) {
- wp_die( __( 'Unauthorized', 'uni-cpo' ) );
- }
- $code = ( isset( $_GET['code'] ) ? $_GET['code'] : '' );
- $state = ( isset( $_GET['state'] ) ? $_GET['state'] : '' );
- if ( empty( $code ) ) {
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&error=no_code' ) );
- exit;
- }
- $settings = $this->get_settings();
- $app_key = ( isset( $settings['dropbox_app_key'] ) ? $settings['dropbox_app_key'] : '' );
- $app_secret = ( isset( $settings['dropbox_app_secret'] ) ? $settings['dropbox_app_secret'] : '' );
- try {
- // Include the new Dropbox SDK and all required dependencies
- $this->load_dropbox_sdk();
- // Include our custom WordPress-compatible persistent data store
- require_once UNI_CPO_ABSPATH . 'includes/cloud-storage/class-uni-cpo-wordpress-persistent-data-store.php';
- // Create Dropbox app instance with the same persistent data store
- $app = new KunnuDropboxDropboxApp($app_key, $app_secret);
- $persistentDataStore = new Uni_Cpo_WordPress_Persistent_Data_Store();
- $config = [
- 'persistent_data_store' => $persistentDataStore,
- ];
- $dropbox = new KunnuDropboxDropbox($app, $config);
- $authHelper = $dropbox->getAuthHelper();
- // Get access token (CSRF token validation will happen automatically)
- $redirectUri = admin_url( 'admin-post.php?action=uni_cpo_dropbox_callback' );
- $accessToken = $authHelper->getAccessToken( $code, $state, $redirectUri );
- // Store tokens
- update_option( 'uni_cpo_dropbox_access_token', $accessToken->getToken() );
- update_option( 'uni_cpo_dropbox_refresh_token', $accessToken->getRefreshToken() );
- update_option( 'uni_cpo_dropbox_expires_at', time() + $accessToken->getExpiryTime() );
- update_option( 'uni_cpo_dropbox_account_id', $accessToken->getAccountId() );
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&success=authorized' ) );
- exit;
- } catch ( Exception $e ) {
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&error=' . urlencode( $e->getMessage() ) ) );
- exit;
- }
- }
- }
-
- /**
- * Handle Dropbox authorization revocation
- */
- public function handle_dropbox_revoke() {
- // Check if user can manage options
- if ( !current_user_can( 'manage_options' ) ) {
- wp_die( __( 'Unauthorized', 'uni-cpo' ) );
- }
- try {
- $settings = $this->get_settings();
- $app_key = ( isset( $settings['dropbox_app_key'] ) ? $settings['dropbox_app_key'] : '' );
- $app_secret = ( isset( $settings['dropbox_app_secret'] ) ? $settings['dropbox_app_secret'] : '' );
- $access_token = get_option( 'uni_cpo_dropbox_access_token', '' );
- if ( !empty( $app_key ) && !empty( $app_secret ) && !empty( $access_token ) ) {
- // Load Dropbox SDK via composer autoloader
- $this->load_dropbox_sdk();
- // Create Dropbox app instance
- $app = new KunnuDropboxDropboxApp($app_key, $app_secret, $access_token);
- $dropbox = new KunnuDropboxDropbox($app);
- $authHelper = $dropbox->getAuthHelper();
- // Revoke access token
- $authHelper->revokeAccessToken();
- }
- } catch ( Exception $e ) {
- // Log the error but don't fail the revocation
- error_log( 'Dropbox revocation error: ' . $e->getMessage() );
- }
- // Clear stored tokens regardless of API call success
- delete_option( 'uni_cpo_dropbox_access_token' );
- delete_option( 'uni_cpo_dropbox_refresh_token' );
- delete_option( 'uni_cpo_dropbox_expires_at' );
- delete_option( 'uni_cpo_dropbox_account_id' );
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&success=revoked' ) );
- exit;
- }
-
- /**
- * Handle Google Drive authorization
- */
- public function handle_gdrive_authorize() {
- if ( $this->is_pro() ) {
- uni_cpo_log_cloud_operation( "=== GOOGLE DRIVE AUTHORIZATION STARTED ===", 'info' );
- // Check if user can manage options
- if ( !current_user_can( 'manage_options' ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Authorization denied - user lacks manage_options capability", 'error' );
- wp_die( __( 'Unauthorized', 'uni-cpo' ) );
- }
- // Check if we have the necessary credentials
- $settings = $this->get_settings();
- $client_id = ( isset( $settings['gdrive_client_id'] ) ? $settings['gdrive_client_id'] : '' );
- $client_secret = ( isset( $settings['gdrive_client_secret'] ) ? $settings['gdrive_client_secret'] : '' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Client ID configured: " . (( !empty( $client_id ) ? 'YES' : 'NO' )), 'info' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Client Secret configured: " . (( !empty( $client_secret ) ? 'YES' : 'NO' )), 'info' );
- if ( empty( $client_id ) || empty( $client_secret ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Missing credentials - redirecting with error", 'error' );
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&error=gdrive_missing_credentials' ) );
- exit;
- }
- try {
- // Initialize autoloader
- $this->init_autoloader();
- // Check if GoogleAuthOAuth2 class is available
- if ( !class_exists( 'Google\Auth\OAuth2' ) ) {
- throw new Exception('Google Auth library is not installed. Please run composer install.');
- }
- $redirect_uri = admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&gdrive_callback=1' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Redirect URI: " . $redirect_uri, 'info' );
- // Generate and store state for CSRF protection
- $state = wp_generate_password( 32, false );
- set_transient( 'uni_cpo_gdrive_oauth_state', $state, 300 );
- // 5 minutes
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Generated state token: " . $state, 'info' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: State token stored in transient (expires in 300 seconds)", 'info' );
- // Build authorization URL manually
- $auth_params = [
- 'client_id' => $client_id,
- 'redirect_uri' => $redirect_uri,
- 'response_type' => 'code',
- 'scope' => 'https://www.googleapis.com/auth/drive.file',
- 'access_type' => 'offline',
- 'prompt' => 'consent',
- 'state' => $state,
- ];
- $authUrl = 'https://accounts.google.com/o/oauth2/v2/auth?' . http_build_query( $auth_params );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Redirecting to Google authorization URL", 'info' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Auth URL: " . $authUrl, 'info' );
- wp_redirect( $authUrl );
- exit;
- } catch ( Exception $e ) {
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&error=' . urlencode( $e->getMessage() ) ) );
- exit;
- }
- }
- }
-
- /**
- * Handle Google Drive OAuth callback
- */
- public function handle_gdrive_callback() {
- if ( $this->is_pro() ) {
- // Only process on settings page with callback parameter
- if ( !is_admin() || !isset( $_GET['page'] ) || $_GET['page'] !== 'uni-cpo-settings' || !isset( $_GET['gdrive_callback'] ) ) {
- return;
- }
- uni_cpo_log_cloud_operation( "=== GOOGLE DRIVE CALLBACK RECEIVED ===", 'info' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Request URI: " . $_SERVER['REQUEST_URI'], 'info' );
- // Log all GET parameters (sanitized)
- $get_params = array_map( 'sanitize_text_field', $_GET );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: GET parameters: " . json_encode( $get_params ), 'info' );
- // Check if user can manage options
- if ( !current_user_can( 'manage_options' ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Authorization denied - user lacks manage_options capability", 'error' );
- wp_die( __( 'Unauthorized', 'uni-cpo' ) );
- }
- // Check for authorization code
- if ( !isset( $_GET['code'] ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: No authorization code received", 'error' );
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&error=gdrive_no_code' ) );
- exit;
- }
- $code = sanitize_text_field( $_GET['code'] );
- $state = ( isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : '' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Authorization code received (length: " . strlen( $code ) . ")", 'info' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: State from Google: " . $state, 'info' );
- // Verify CSRF state
- $stored_state = get_transient( 'uni_cpo_gdrive_oauth_state' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Stored state from transient: " . (( $stored_state ? $stored_state : 'NULL/EMPTY' )), 'info' );
- delete_transient( 'uni_cpo_gdrive_oauth_state' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Transient deleted", 'info' );
- // Detailed state comparison
- if ( empty( $stored_state ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: State validation FAILED - stored state is empty (token expired or not found)", 'error' );
- } elseif ( $stored_state !== $state ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: State validation FAILED - states don't match", 'error' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Expected: " . $stored_state, 'error' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Received: " . $state, 'error' );
- } else {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: State validation SUCCESS", 'info' );
- }
- if ( empty( $stored_state ) || $stored_state !== $state ) {
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&error=gdrive_invalid_state' ) );
- exit;
- }
- try {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Starting token exchange", 'info' );
- $settings = $this->get_settings();
- $client_id = $settings['gdrive_client_id'];
- $client_secret = $settings['gdrive_client_secret'];
- // Initialize autoloader
- $this->init_autoloader();
- // Check if GoogleAuthOAuth2 class is available
- if ( !class_exists( 'Google\Auth\OAuth2' ) ) {
- throw new Exception('Google Auth library is not installed. Please run composer install.');
- }
- $redirect_uri = admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&gdrive_callback=1' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Using redirect URI: " . $redirect_uri, 'info' );
- // Initialize OAuth2 client
- $oauth2 = new GoogleAuthOAuth2([
- 'clientId' => $client_id,
- 'clientSecret' => $client_secret,
- 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
- 'tokenCredentialUri' => 'https://oauth2.googleapis.com/token',
- 'redirectUri' => $redirect_uri,
- 'scope' => 'https://www.googleapis.com/auth/drive.file',
- ]);
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Exchanging authorization code for access token", 'info' );
- // Set authorization code
- $oauth2->setCode( $code );
- // Exchange code for access token
- $token = $oauth2->fetchAuthToken();
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Token response received: " . json_encode( array_keys( $token ) ), 'info' );
- if ( isset( $token['error'] ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Token exchange error: " . (( isset( $token['error_description'] ) ? $token['error_description'] : $token['error'] )), 'error' );
- throw new Exception('Token exchange failed: ' . (( isset( $token['error_description'] ) ? $token['error_description'] : $token['error'] )));
- }
- // Add created timestamp
- $token['created'] = time();
- // Store tokens
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Storing access token", 'info' );
- update_option( 'uni_cpo_gdrive_access_token', json_encode( $token ) );
- if ( isset( $token['refresh_token'] ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: Storing refresh token", 'info' );
- update_option( 'uni_cpo_gdrive_refresh_token', $token['refresh_token'] );
- } else {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE CALLBACK: No refresh token in response", 'warning' );
- }
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: OAuth authorization successful", 'info' );
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&success=gdrive_authorized' ) );
- exit;
- } catch ( Exception $e ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: OAuth authorization failed: " . $e->getMessage(), 'error' );
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&error=' . urlencode( $e->getMessage() ) ) );
- exit;
- }
- }
- }
-
- /**
- * Handle Google Drive authorization revocation
- */
- public function handle_gdrive_revoke() {
- // Check if user can manage options
- if ( !current_user_can( 'manage_options' ) ) {
- wp_die( __( 'Unauthorized', 'uni-cpo' ) );
- }
- try {
- $access_token = get_option( 'uni_cpo_gdrive_access_token', '' );
- if ( !empty( $access_token ) ) {
- $token_data = json_decode( $access_token, true );
- if ( isset( $token_data['access_token'] ) ) {
- // Revoke token with Google using direct HTTP request
- $revoke_url = 'https://oauth2.googleapis.com/revoke?token=' . urlencode( $token_data['access_token'] );
- $response = wp_remote_post( $revoke_url );
- if ( !is_wp_error( $response ) ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: OAuth token revoked with Google", 'info' );
- } else {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Token revocation request failed: " . $response->get_error_message(), 'warning' );
- }
- }
- }
- } catch ( Exception $e ) {
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: Token revocation failed: " . $e->getMessage(), 'warning' );
- }
- // Clear stored tokens regardless of revocation success
- delete_option( 'uni_cpo_gdrive_access_token' );
- delete_option( 'uni_cpo_gdrive_refresh_token' );
- delete_option( 'uni_cpo_gdrive_upload_folder_id' );
- uni_cpo_log_cloud_operation( "GOOGLE DRIVE: OAuth tokens cleared locally", 'info' );
- wp_redirect( admin_url( 'admin.php?page=uni-cpo-settings&tab=file_uploads&success=gdrive_revoked' ) );
- exit;
+ public function activation( $plugin )
+ {
}
-}
+}
No newline at end of file
--- a/uni-woo-custom-product-options/includes/abstracts/abstract-uni-cpo-module.php
+++ b/uni-woo-custom-product-options/includes/abstracts/abstract-uni-cpo-module.php
@@ -51,7 +51,6 @@
),
'letter_spacing' => '',
'line_height' => '',
- 'cpo_conditional' => array(),
);
/**
@@ -106,10 +105,6 @@
return $this->get_prop( 'name', $context );
}
- public function get_cpo_conditional( $context = 'view' ) {
- return $this->get_prop( 'cpo_conditional', $context );
- }
-
// TODO add more getters
@@ -132,10 +127,6 @@
$this->set_prop( 'slug', $slug );
}
- public function set_cpo_conditional( $value ) {
- $this->set_prop( 'cpo_conditional', $value );
- }
-
// TODO add more setters
/*
@@ -172,114 +163,4 @@
public static function get_css( $data ){}
- public static function conditional_rules( $data ) {
- $id = $data['id'];
- $selectors = $data['settings']['advanced']['selectors'];
- $css_id = 'uni_row_' . $id;
-
- if ( ! empty( $selectors['id_name'] ) ) {
- $css_id = $selectors['id_name'];
- }
-
- if (!empty($data['settings']['cpo_conditional'])) {
- $rules_data = $data['settings']['cpo_conditional']['main'];
- $is_enabled = ('yes' === $rules_data['cpo_is_fc']) ? true : false;
- } else {
- $is_enabled = false;
- }
-
- if ( ! $is_enabled ) {
- return;
- }
-
- $is_hidden = ( 'hide' === $rules_data['cpo_fc_default'] ) ? true : false;
- $scheme = stripslashes_deep( stripslashes_deep( $rules_data['cpo_fc_scheme'] ) );
- $scheme = json_decode( $scheme, true );
-
- if ( is_array( $scheme ) && ! empty( $scheme ) ) {
- $condition = uni_cpo_option_js_condition_prepare( $scheme );
-
- $slide_down = '$' . esc_attr( $css_id ) . '.slideDown(300).addClass("cpo-visible-field");' . "n";
- $slide_up = '$' . esc_attr( $css_id ) . '.slideUp(300).removeClass("cpo-visible-field");' . "n";
- $add_class = '$' . esc_attr( $css_id ) . '_fields.each(function( index ) {' . "n";
- $add_class .= '$(this).addClass( extraClass );' . "n";
- $add_class .= '});' . "n";
- $remove_class = '$' . esc_attr( $css_id ) . '_fields.each(function( index ) {' . "n";
- $remove_class .= '$(this).removeClass( extraClass );' . "n";
- $remove_class .= '});' . "n";
-
- $final_statement = 'if ' . $condition . ' {' . "n";
- if ( $is_hidden ) {
- $final_statement .= $slide_down;
- $final_statement .= $remove_class;
- } else {
- $final_statement .= $slide_up;
- $final_statement .= $add_class;
- }
- $final_statement .= '} else {' . "n";
- if ( $is_hidden ) {
- $final_statement .= $slide_up;
- $final_statement .= $add_class;
- } else {
- $final_statement .= $slide_down;
- $final_statement .= $remove_class;
- }
- $final_statement .= '}' . "n";
-
- ?>
- <script>
- jQuery(document).ready(function($) {
- 'use strict';
-
- $(document.body).on('uni_cpo_options_data_ajax_success', function() {
- <?php echo esc_attr( $css_id ) ?>_fields_conditional_func(unicpo.formatted_vars);
- });
- $(document.body).on('uni_cpo_options_data_for_conditional', function(e, fields) {
- var variables = $.extend({}, unicpo.formatted_vars, fields);
- <?php echo esc_attr( $css_id ) ?>_fields_conditional_func(variables);
- });
-
- function <?php echo esc_attr( $css_id ) ?>_fields_conditional_func(formData) {
- try {
- var $<?php echo esc_attr( $css_id ) ?> = $('#<?php echo esc_attr( $css_id ) ?>');
- var $<?php echo esc_attr( $css_id ) ?>_fields = $<?php echo esc_attr( $css_id ) ?>.find('input, select, textarea');
- var extraClass = 'uni-cpo-excluded-field';
-
- <?php
- if ( $is_hidden ) {
- $is_hidden_html = 'if ( ! $' . esc_attr( $css_id ) . '.hasClass("cpo-visible-field") ) {' . "n";
- $is_hidden_html .= '$' . $css_id . '.hide();' . "n";
- $is_hidden_html .= $add_class;
- $is_hidden_html .= '}' . "n";
- echo $is_hidden_html;
- }
- ?>
-
- <?php echo $final_statement; ?>
- } catch (e) {
- console.error(e);
- }
- }
- });
- </script>
- <?php
- }
- }
-
- public static function get_custom_attribute_html( $attributes = array() ) {
- $custom_attributes = array();
-
- if ( ! empty( $attributes ) && is_array( $attributes ) ) {
- // Apply filter to allow modification/merging of attributes before processing
- $attributes = apply_filters( 'uni_cpo_custom_attributes', $attributes );
-
- // Build attributes array using keys to ensure uniqueness
- // Later attributes with same key will overwrite earlier ones
- foreach ( $attributes as $attribute => $attribute_value ) {
- $custom_attributes[ $attribute ] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
- }
- }
-
- return implode( ' ', $custom_attributes );
- }
}
--- a/uni-woo-custom-product-options/includes/abstracts/abstract-uni-cpo-option.php
+++ b/uni-woo-custom-product-options/includes/abstracts/abstract-uni-cpo-option.php
@@ -4,35 +4,34 @@
exit;
// Exit if accessed directly
}
+
/*
* Uni_Cpo_Option Abstract class
*
*/
-class Uni_Cpo_Option extends Uni_Cpo_Data {
+class Uni_Cpo_Option extends Uni_Cpo_Data
+{
/**
* This is the name of this object type.
* @var string
*/
- protected $object_type = 'option';
-
+ protected $object_type = 'option' ;
/**
* Post type.
* @var string
*/
- protected $post_type = 'uni_cpo_option';
-
+ protected $post_type = 'uni_cpo_option' ;
/**
* Cache group.
* @var string
*/
- protected $cache_group = 'options';
-
+ protected $cache_group = 'options' ;
/**
* Stores option data.
*
* @var array
*/
- protected $data = array(
+ protected $data = array(
'name' => '',
'status' => false,
'slug' => '',
@@ -43,8 +42,7 @@
'cpo_general' => array(),
'cpo_conditional' => array(),
'cpo_validation' => array(),
- );
-
+ ) ;
/**
* Get the option if ID is passed, otherwise the option is new and empty.
* This class should NOT be instantiated, but the uni_cpo_get_option() function
@@ -52,50 +50,56 @@
*
* @param int|Uni_Cpo_Option|object $option Option to init.
*/
- public function __construct( $option = 0 ) {
+ public function __construct( $option = 0 )
+ {
parent::__construct( $option );
+
if ( is_numeric( $option ) && $option > 0 ) {
$this->set_id( $option );
} elseif ( $option instanceof self ) {
$this->set_id( absint( $option->get_id() ) );
- } elseif ( !empty( $option->ID ) ) {
+ } elseif ( !empty($option->ID) ) {
$this->set_id( absint( $option->ID ) );
} else {
$this->set_object_read( true );
}
+
$this->data_store = Uni_Cpo_Data_Store::load( 'option' );
if ( $this->get_id() > 0 ) {
$this->data_store->read( $this );
}
}
-
+
/**
* Get internal type. Should return string and *should be overridden* by child classes.
*
* @return string
*/
- public static function get_type() {
+ public static function get_type()
+ {
return '';
}
-
+
/**
* Returns an array of special vars associated with the option
*
* @return array
*/
- public static function get_special_vars() {
+ public static function get_special_vars()
+ {
return array();
}
-
+
/**
* Returns an array of data used in js query builder
*
* @return array
*/
- public static function get_filter_data() {
+ public static function get_filter_data()
+ {
return array();
}
-
+
/*
|--------------------------------------------------------------------------
| Getters
@@ -110,10 +114,11 @@
*
* @return string
*/
- public function get_name( $context = 'view' ) {
+ public function get_name( $context = 'view' )
+ {
return $this->get_prop( 'name', $context );
}
-
+
/**
* Get option status.
*
@@ -121,10 +126,11 @@
*
* @return string
*/
- public function get_status( $context = 'view' ) {
+ public function get_status( $context = 'view' )
+ {
return $this->get_prop( 'status', $context );
}
-
+
/**
* Get option slug.
*
@@ -132,38 +138,46 @@
*
* @return string
*/
- public function get_slug( $context = 'view' ) {
+ public function get_slug( $context = 'view' )
+ {
return $this->get_prop( 'slug', $context );
}
-
- public function get_general( $context = 'view' ) {
+
+ public function get_general( $context = 'view' )
+ {
return $this->get_prop( 'general', $context );
}
-
- public function get_style( $context = 'view' ) {
+
+ public function get_style( $context = 'view' )
+ {
return $this->get_prop( 'style', $context );
}
-
- public function get_advanced( $context = 'view' ) {
+
+ public function get_advanced( $context = 'view' )
+ {
return $this->get_prop( 'advanced', $context );
}
-
- public function get_cpo_general( $context = 'view' ) {
+
+ public function get_cpo_general( $context = 'view' )
+ {
return $this->get_prop( 'cpo_general', $context );
}
-
- public function get_cpo_conditional( $context = 'view' ) {
+
+ public function get_cpo_conditional( $context = 'view' )
+ {
return $this->get_prop( 'cpo_conditional', $context );
}
-
- public function get_cpo_validation( $context = 'view' ) {
+
+ public function get_cpo_validation( $context = 'view' )
+ {
return $this->get_prop( 'cpo_validation', $context );
}
-
- public function get_slug_ending() {
+
+ public function get_slug_ending()
+ {
return preg_replace( '/' . UniCpo()->get_var_slug() . '/', '', $this->get_slug() );
}
-
+
/*
|--------------------------------------------------------------------------
| Setters
@@ -180,52 +194,61 @@
*
* @param string $name Product name.
*/
- public function set_name( $name ) {
+ public function set_name( $name )
+ {
$this->set_prop( 'name', $name );
}
-
+
/**
* Set option status.
*
* @param string $status Product status.
*/
- public function set_status( $status ) {
+ public function set_status( $status )
+ {
$this->set_prop( 'status', $status );
}
-
+
/**
* Set option slug.
*
* @param string $slug Option slug.
*/
- public function set_slug( $slug ) {
+ public function set_slug( $slug )
+ {
$this->set_prop( 'slug', $slug );
}
-
- public function set_general( $value ) {
+
+ public function set_general( $value )
+ {
$this->set_prop( 'general', $value );
}
-
- public function set_style( $value ) {
+
+ public function set_style( $value )
+ {
$this->set_prop( 'style', $value );
}
-
- public function set_advanced( $value ) {
+
+ public function set_advanced( $value )
+ {
$this->set_prop( 'advanced', $value );
}
-
- public function set_cpo_general( $value ) {
+
+ public function set_cpo_general( $value )
+ {
$this->set_prop( 'cpo_general', $value );
}
-
- public function set_cpo_conditional( $value ) {
+
+ public function set_cpo_conditional( $value )
+ {
$this->set_prop( 'cpo_conditional', $value );
}
-
- public function set_cpo_validation( $value ) {
+
+ public function set_cpo_validation( $value )
+ {
$this->set_prop( 'cpo_validation', $value );
}
-
+
/*
|--------------------------------------------------------------------------
| Other Methods
@@ -235,53 +258,67 @@
* Save data (either create or update depending on if we are working on an existing option).
*
*/
- public function save() {
+ public function save()
+ {
+
if ( $this->data_store ) {
// Trigger action before saving to the DB. Use a pointer to adjust object props before save.
do_action( 'uni_cpo_before_' . $this->object_type . '_object_save', $this, $this->data_store );
+
if ( $this->get_id() ) {
$this->data_store->update( $this );
} else {
$this->data_store->create( $this );
}
+
return $this->get_id();