Jump to content

Replying to Adding An It_Exchange_Email_Notification_Shortcode_Functions Is Next To Impossible Because Of Private Property Access

Post Options

  or Cancel

Topic Summary


Posted 20 March 2014 - 02:23 PM

Thanks Elise!

Makes sense. I'd absolutely love to see it happen.



Elise Alley

Posted 20 March 2014 - 02:14 PM

Hi Tim,

I've spoken with the developers and they agree that those should be public.  They are going to change it in core for the next release.

As for GitHub - this is something we've discussed doing.  However, it's something that is still a ways down the road, and I can't guarantee that it will happen even then.  Like I said, we've discussed it, but I just don't want to make any promises!  :)

Let us know if you have any other questions.




Posted 20 March 2014 - 12:58 PM

Hi Guys,

The class IT_Exchange_Email_Notifications handles the sending of receipts. Using the it_exchange_email_notification_shortcode_functions filter we can add our own custom short code. However, in the ithemes_exchange_email_notification_shortcode method, the parameter that is passed to the function earlier defined with that filter is the $this object. Normally this wouldn't be a problem, however, in order to get any meaningful use out of our custom short code function, we need to access the customer id. Unfortunately, those properties are defined as private:

private $transaction_id;
private $customer_id;
private $user;

This isn't a problem for the default iThemes Exchange short codes because they are all contained with in the IT_Exchange_Email_Notifications class, so they get access. But because our function is outside of the IT_Exchange_Email_Notifications class we can't access them.

As such we have to do an ugly "hack" using reflection as follows:

* @param $args IT_Exchange_Email_Notifications
* @return string
public static function email_shortcode_print_billing_address( $args ) {
$IT_Exchange_Email_Notifications_Reflection = new ReflectionClass( get_class( $args ) ); // we have to use reflection because the damn $customer_id property is private
$secret = $IT_Exchange_Email_Notifications_Reflection->getProperty( 'customer_id' );
$secret->setAccessible( true );
$user_id = $secret->getValue( $args );

$content = it_exchange_get_formatted_billing_address( it_exchange_get_customer_billing_address( $user_id ) );

return $content;

I'd propose that either those properties are marked as public, or that they are passed in as additional parameters.

Additionally, are there any plans to move iThemes Exchange to a more open source model such as WooCommerce or EDD? As in, hosting the code on GitHub and allowing developers to submit pull requests, and add issues? It seems that one of the many things that makes all of these other platforms so successful is the ability for developers to contribute back to the project. I know personally, during the current development of a site using iThemes Exchange I have come across many small bugs etc... And while I have of course filed tickets here, it is understandable that it would take a while for you fabulous folks to get to them, because they might be lower down on the priority list, etc... That is totally understandable, and makes sense. I only wish that there was someway that I, and many other developers could contribute back to the project, and make iThemes Exchange even cooler. It seems like "open sourcing" ( I know it is a GPL plugin, hence the quotes ) would be a tremendous benefit to the community, and the future development as a plugin as well. And I'm sure you guys have thought about this already, and I'd imagine one of the drawbacks being that you'd have to make that someones job — but it seems that even though it would consume company hours, it'd be really great in the long run.

Sorry for my rambling, but it is just something that has been on my mind...


Review the complete topic (launches new window)