AdditionalOptions.class.php
2 months ago
CampaignInfo.class.php
2 months ago
Campaigns.class.php
2 months ago
ClickTracking.class.php
2 months ago
ContactForm7.class.php
2 months ago
Debugging.class.php
4 weeks ago
EDD.class.php
4 weeks ago
General.class.php
4 weeks ago
Integrations.class.php
2 months ago
LifterLMS.class.php
2 months ago
Marketpress.class.php
4 weeks ago
MemberPress.class.php
2 months ago
Membership2.class.php
2 months ago
PMPro.class.php
2 months ago
PPBuyNowButton.class.php
2 months ago
RestrictContentPro.class.php
2 months ago
S2Member.class.php
2 months ago
Signup.class.php
2 months ago
SimplePayPro.class.php
2 months ago
StripePayments.class.php
4 weeks ago
SureCart.class.php
2 months ago
WPEasyCart.class.php
2 months ago
WPPayForms.class.php
2 months ago
WishListMember.class.php
2 months ago
WooComm.class.php
4 weeks ago
PMPro.class.php
124 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | |
| 4 | class postaffiliatepro_Form_Settings_PMPro extends postaffiliatepro_Form_Base { |
| 5 | const PMPRO_COMMISSION_ENABLED = 'pmpro-commission-enabled'; |
| 6 | const PMPRO_CONFIG_PAGE = 'pmpro-config-page'; |
| 7 | const PMPRO_PRODUCT_ID = 'pmpro-prodid'; |
| 8 | |
| 9 | public $visitorId = ''; |
| 10 | |
| 11 | public function __construct() { |
| 12 | parent::__construct(self::PMPRO_CONFIG_PAGE, 'options.php'); |
| 13 | } |
| 14 | |
| 15 | public function initSettings() { |
| 16 | register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::PMPRO_COMMISSION_ENABLED); |
| 17 | register_setting(self::PMPRO_CONFIG_PAGE, self::PMPRO_PRODUCT_ID); |
| 18 | } |
| 19 | |
| 20 | protected function initForm() { |
| 21 | $this->addSelect(self::PMPRO_PRODUCT_ID, array( |
| 22 | 'id' => 'membership ID', |
| 23 | 'name' => 'membership name' |
| 24 | )); |
| 25 | $this->addSubmit(); |
| 26 | } |
| 27 | protected function getTemplateFile() { |
| 28 | return WP_PLUGIN_DIR . '/postaffiliatepro/Template/PMProConfig.xtpl'; |
| 29 | } |
| 30 | |
| 31 | public function addPrimaryConfigMenu() { |
| 32 | if (get_option(self::PMPRO_COMMISSION_ENABLED) === 'true') { |
| 33 | add_submenu_page('integrations-config-page-handle', 'Paid Membership Pro', 'Paid Membership Pro', 'manage_options', 'pmprointegration-settings-page', array( |
| 34 | $this, |
| 35 | 'printConfigPage' |
| 36 | )); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | public function printConfigPage() { |
| 41 | $this->render(); |
| 42 | } |
| 43 | |
| 44 | public function pmproSaveAffIdToOrder($order) { |
| 45 | if ($this->visitorId != '') { |
| 46 | $order->affiliate_id = $this->visitorId; |
| 47 | $order->saveOrder(); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | public function pmproTrackOrder($userId, $order) { |
| 52 | if (get_option(self::PMPRO_COMMISSION_ENABLED) !== 'true') { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | $visitorId = ''; |
| 57 | if (isset($_COOKIE['PAPVisitorId']) && !empty($_COOKIE['PAPVisitorId'])) { |
| 58 | $visitorId = sanitize_text_field(wp_unslash($_COOKIE['PAPVisitorId'])); |
| 59 | } |
| 60 | |
| 61 | if (isset($order->total)) { |
| 62 | $query = 'AccountID='.postaffiliatepro::getAccountName().'&TotalCost=' . $order->total . '&OrderID=' . $order->code; |
| 63 | $productId = $order->membership_id; |
| 64 | if (get_option(self::PMPRO_PRODUCT_ID) == 'name') { |
| 65 | $level = pmpro_getLevel($order->membership_id); |
| 66 | $productId = sanitize_title($level->name, 'pmpro-level-' . $order->membership_id); |
| 67 | } |
| 68 | $query .= '&ProductID='.$productId.'&visitorId='.$visitorId.'&data1='.$userId; |
| 69 | self::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query); |
| 70 | |
| 71 | // save affiliate ID into order |
| 72 | $order->affiliate_id = $visitorId; |
| 73 | $order->saveOrder(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | public function pmproTrackAddedOrder($order) { |
| 78 | if (get_option(self::PMPRO_COMMISSION_ENABLED) !== 'true') { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | $order->getLastMemberOrder($order->user_id); |
| 83 | if (!empty($order->affiliate_id)) { |
| 84 | $visitorId = $order->affiliate_id; |
| 85 | |
| 86 | $query = 'AccountID='.postaffiliatepro::getAccountName().'&TotalCost=' . $order->subtotal . '&OrderID=' . $order->code; |
| 87 | $productId = $order->membership_id; |
| 88 | if (get_option(self::PMPRO_PRODUCT_ID) == 'name') { |
| 89 | $level = pmpro_getLevel($order->membership_id); |
| 90 | $productId = sanitize_title($level->name, 'pmpro-level-' . $order->membership_id); |
| 91 | } |
| 92 | $query .= '&ProductID='.$productId.'&visitorId='.$visitorId.'&data1='.$order->user_id; |
| 93 | self::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query); |
| 94 | |
| 95 | // save affiliate ID into order |
| 96 | $order->affiliate_id = $visitorId; |
| 97 | $order->saveOrder(); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | $papSubmenuPriority = 32; |
| 103 | $papIntegrationPMPro = new postaffiliatepro_Form_Settings_PMPro(); |
| 104 | add_action('admin_init', array( |
| 105 | $papIntegrationPMPro, |
| 106 | 'initSettings' |
| 107 | ), 99); |
| 108 | add_action('admin_menu', array( |
| 109 | $papIntegrationPMPro, |
| 110 | 'addPrimaryConfigMenu' |
| 111 | ), $papSubmenuPriority); |
| 112 | add_action('pmpro_added_order', array( |
| 113 | $papIntegrationPMPro, |
| 114 | 'pmproSaveAffIdToOrder' |
| 115 | ), 99); |
| 116 | add_action('pmpro_after_checkout', array( |
| 117 | $papIntegrationPMPro, |
| 118 | 'pmproTrackOrder' |
| 119 | ), 99, 2); |
| 120 | add_action('pmpro_add_order', array( |
| 121 | $papIntegrationPMPro, |
| 122 | 'pmproTrackAddedOrder' |
| 123 | ), 99); |
| 124 |