From 159bfd365819d8f569ca95400868a66d6660120b Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Wed, 16 Aug 2023 21:07:23 +0100 Subject: [PATCH 1/2] Adds warning if private properties are accessed outside its class. --- class-wc-facebookcommerce.php | 17 +++++++++++++++++ facebook-commerce-messenger-chat.php | 17 +++++++++++++++++ facebook-commerce.php | 18 ++++++++++++++++++ includes/Admin.php | 18 ++++++++++++++++++ .../Enhanced_Catalog_Attribute_Fields.php | 18 ++++++++++++++++++ includes/ProductSync/ProductValidator.php | 18 ++++++++++++++++++ includes/fbbackground.php | 18 ++++++++++++++++++ includes/fbproduct.php | 18 ++++++++++++++++++ 8 files changed, 142 insertions(+) diff --git a/class-wc-facebookcommerce.php b/class-wc-facebookcommerce.php index 02ec386c3..8506798d7 100644 --- a/class-wc-facebookcommerce.php +++ b/class-wc-facebookcommerce.php @@ -134,6 +134,23 @@ public function __construct() { $this->init_admin(); } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( in_array( $key, array( 'configuration_detection', 'fb_categories' ), true ) ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } /** * Initializes the plugin. diff --git a/facebook-commerce-messenger-chat.php b/facebook-commerce-messenger-chat.php index 89e0aba97..4f5eadc7f 100755 --- a/facebook-commerce-messenger-chat.php +++ b/facebook-commerce-messenger-chat.php @@ -46,6 +46,23 @@ public function __construct( $settings ) { add_action( 'wp_footer', array( $this, 'inject_messenger_chat_plugin' ) ); } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( in_array( $key, array( 'page_id', 'jssdk_version' ), true ) ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } /** * Outputs the Facebook Messenger chat script. diff --git a/facebook-commerce.php b/facebook-commerce.php index 22cd5f789..c14a76713 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -385,6 +385,24 @@ public function __construct( WC_Facebookcommerce $facebook_for_woocommerce ) { add_action( 'fb_wc_product_set_delete', [ $this, 'delete_product_set_item' ], 99 ); } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( in_array( $key, array( 'events_tracker', 'messenger_chat', 'background_processor' ), true ) ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } + /** * Initialises Facebook Pixel and its settings. * diff --git a/includes/Admin.php b/includes/Admin.php index 5afc38dd5..5a280d1d8 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -110,6 +110,24 @@ public function __construct() { add_filter( 'gettext', array( $this, 'change_custom_taxonomy_tip' ), 20, 2 ); } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( 'product_sets' === $key ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } + /** * Change custom taxonomy tip text * diff --git a/includes/Admin/Enhanced_Catalog_Attribute_Fields.php b/includes/Admin/Enhanced_Catalog_Attribute_Fields.php index 6bfff865f..126fdc328 100644 --- a/includes/Admin/Enhanced_Catalog_Attribute_Fields.php +++ b/includes/Admin/Enhanced_Catalog_Attribute_Fields.php @@ -54,6 +54,24 @@ public function __construct( $page_type, \WP_Term $term = null, \WC_Product $pro $this->category_handler = facebook_for_woocommerce()->get_facebook_category_handler(); } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( in_array( $key, array( 'page_type', 'term', 'product', 'category_handler' ), true ) ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } + public static function render_hidden_input_can_show_attributes() { ?> integration = $integration; } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( 'facebook_product' === $key ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } + /** * Validate whether the product should be synced to Facebook. * diff --git a/includes/fbbackground.php b/includes/fbbackground.php index e04ab37f5..20dc295d8 100644 --- a/includes/fbbackground.php +++ b/includes/fbbackground.php @@ -27,6 +27,24 @@ public function __construct( $commerce ) { $this->commerce = $commerce; // Full WC_Facebookcommerce_Integration obj } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( 'commerce' === $key ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } + /** * @var string */ diff --git a/includes/fbproduct.php b/includes/fbproduct.php index 7c016fed9..291243bc5 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -120,6 +120,24 @@ public function __construct( $wpid, $parent_product = null ) { } } + /** + * __get method for backward compatibility. + * + * @param string $key property name + * @return mixed + * @since x.x.x + */ + public function __get( $key ) { + // Add warning for private properties. + if ( in_array( $key, array( 'fb_description', 'gallery_urls', 'fb_use_parent_image', 'main_description', 'sync_short_description' ), true ) ) { + /* translators: %s property name. */ + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + return $this->$key; + } + + return null; + } + public function exists() { return ( $this->woo_product !== null && $this->woo_product !== false ); } From cd911a8ac92c716106bd5886a92c550caa797f92 Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Fri, 18 Aug 2023 10:24:17 +0100 Subject: [PATCH 2/2] Corrects property access to protected in notice. --- includes/Admin.php | 2 +- includes/ProductSync/ProductValidator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Admin.php b/includes/Admin.php index 5a280d1d8..5078fc06a 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -121,7 +121,7 @@ public function __get( $key ) { // Add warning for private properties. if ( 'product_sets' === $key ) { /* translators: %s property name. */ - _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is protected and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); return $this->$key; } diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index e09743816..428811020 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -118,7 +118,7 @@ public function __get( $key ) { // Add warning for private properties. if ( 'facebook_product' === $key ) { /* translators: %s property name. */ - _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); + _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is protected and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), 'x.x.x' ); return $this->$key; }