class-memberpress.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) or exit; |
| 4 | |
| 5 | /** |
| 6 | * Class MC4WP_MemberPress_Integration |
| 7 | * |
| 8 | * @ignore |
| 9 | */ |
| 10 | class MC4WP_MemberPress_Integration extends MC4WP_Integration { |
| 11 | |
| 12 | /** |
| 13 | * @var string |
| 14 | */ |
| 15 | public $name = "MemberPress"; |
| 16 | |
| 17 | /** |
| 18 | * @var string |
| 19 | */ |
| 20 | public $description = "Subscribes people from MemberPress register forms."; |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * Add hooks |
| 25 | */ |
| 26 | public function add_hooks() { |
| 27 | |
| 28 | if( ! $this->options['implicit'] ) { |
| 29 | add_action( 'mepr_checkout_before_submit', array( $this, 'output_checkbox' ) ); |
| 30 | } |
| 31 | |
| 32 | add_action( 'mepr_signup', array( $this, 'subscribe_from_memberpress' ), 5 ); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * Subscribe from MemberPress sign-up forms. |
| 39 | * |
| 40 | * @param MeprTransaction $txn |
| 41 | * @return bool |
| 42 | */ |
| 43 | public function subscribe_from_memberpress( $txn ) { |
| 44 | |
| 45 | // Is this integration triggered? (checkbox checked or implicit) |
| 46 | if( ! $this->triggered() ) { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | $user = get_userdata( $txn->user_id ); |
| 51 | |
| 52 | $data = array( |
| 53 | 'EMAIL' => $user->user_email, |
| 54 | 'FNAME' => $user->first_name, |
| 55 | 'LNAME' => $user->last_name |
| 56 | ); |
| 57 | |
| 58 | // subscribe using email and name |
| 59 | return $this->subscribe( $data, $txn->id ); |
| 60 | |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @return bool |
| 65 | */ |
| 66 | public function is_installed() { |
| 67 | return defined( 'MEPR_VERSION' ); |
| 68 | } |
| 69 | |
| 70 | } |