Last active
November 27, 2017 21:15
-
-
Save igorbenic/d1bcdd13a9cda6d1dd78a0f91026a2c8 to your computer and use it in GitHub Desktop.
OOP for Better Conversions in WordPress Plugins | https://www.ibenic.com/oop-conversions-wordpress-plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Get all integrations. If there are any integrations, the array will be: | |
| * array( | |
| * 'integration_slug' => 'My_Integration_Class' | |
| * ) | |
| */ | |
| $integrations = apply_filters( 'my_plugin_integrations', array() ); | |
| if( $integrations ) { | |
| foreach ( $integrations as $slug => $class ) { | |
| $integration_object = new $class(); ?> | |
| <div class="plugin-card plugin-card-<?php echo $slug; ?>"> | |
| <div class="plugin-card-top"> | |
| <div class="name column-name"> | |
| <h3> | |
| <?php echo $integration_object->title; ?> | |
| <img src="<?php echo $integration_object->image; ?>" class="plugin-icon" alt=""> | |
| </h3> | |
| </div> | |
| <div class="desc column-description"> | |
| <p><?php echo $integration_object->desc; ?></p> | |
| </div> | |
| </div> | |
| <div class="plugin-card-bottom"> | |
| <?php $integration_object->buttons(); ?> | |
| </div> | |
| </div> | |
| <?php | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'my_plugin_integrations', 'integrate_mailchimp' ); | |
| /** | |
| * Registering mailchimp | |
| * @return array | |
| */ | |
| function integrate_mailchimp( $integrations ) { | |
| $integrations['ga_mailchimp'] = 'GA_MailChimp'; | |
| return $integrations; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if( ! class_exists( 'GA_MailChimp' ) ) { | |
| class GA_MailChimp extends GA_Integration { | |
| // ... | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class GA_MailChimp extends GA_Integration { | |
| /** | |
| * Integration Image | |
| * @var string | |
| */ | |
| public $image = ''; | |
| /** | |
| * Integration Title | |
| * @var string | |
| */ | |
| public $title = ''; | |
| /** | |
| * Integration Description | |
| * @var string | |
| */ | |
| public $desc = ''; | |
| /** | |
| * Setting initial params | |
| */ | |
| public function __construct() { | |
| $this->title = __( 'MailChimp', 'givasap' ); | |
| $this->settings_id = 'ga_mailchimp'; | |
| $this->image = 'https://static.mailchimp.com/web/brand-assets/mc_freddie_color_web.png'; | |
| $this->desc = __( 'Sends users to your list and grow your email list', 'giveasap' ); | |
| // Premium Features | |
| parent::__construct(); | |
| add_filter( 'giveasap_send_registered_email', array( $this, 'send_default_email' ) ); | |
| // ... All your premium features below | |
| } | |
| // All other premium methods are inside here. No method buttons() needed. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class GA_MailChimp extends GA_Integration { | |
| /** | |
| * Integration Image | |
| * @var string | |
| */ | |
| public $image = ''; | |
| /** | |
| * Integration Title | |
| * @var string | |
| */ | |
| public $title = ''; | |
| /** | |
| * Integration Description | |
| * @var string | |
| */ | |
| public $desc = ''; | |
| /** | |
| * Setting initial params | |
| */ | |
| public function __construct() { | |
| $this->title = __( 'MailChimp', 'givasap' ); | |
| $this->settings_id = 'ga_mailchimp'; | |
| $this->image = 'https://static.mailchimp.com/web/brand-assets/mc_freddie_color_web.png'; | |
| $this->desc = __( 'Sends users to your list and grow your email list', 'giveasap' ); | |
| } | |
| public function buttons( $integrations ) { | |
| echo '<a href="' . giv_fs()->get_upgrade_url() . '" class="button button-primary">' . __( 'Upgrade to PRO', 'giveasap' ) . '</a>'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment