/** * Replace comm_vars with corresponding values. * * @since 1.0.0 * * @param MS_Model_Relationship $subscription The membership relationship to send message to. * @param MS_Model_Member $member The member object to get info from. * @return array { * Returns array of ( $var_name => $var_replace ). * * @type string $var_name The variable name to replace. * @type string $var_replace The variable corresponding replace string. * } */ public function get_comm_vars($subscription, $member) { $currency = MS_Plugin::instance()->settings->currency . ' '; $invoice = null; $membership = null; if ($subscription && $subscription instanceof MS_Model_Relationship) { // First try to fetch the current invoice. $invoice = $subscription->get_current_invoice(false); $prev_invoice = $subscription->get_previous_invoice(); // If no current invoice exists then fetch the previous invoice. if (empty($invoice)) { $invoice = $prev_invoice; } $membership = $subscription->get_membership(); } $comm_vars = apply_filters('ms_model_communication_comm_vars', $this->comm_vars, $this->type, $member, $subscription); $wp_user = $member->get_user(); foreach ($comm_vars as $key => $description) { $var_value = ''; switch ($key) { case self::COMM_VAR_BLOG_NAME: $var_value = get_option('blogname'); break; case self::COMM_VAR_BLOG_URL: $var_value = get_option('home'); break; case self::COMM_VAR_USERNAME: $var_value = $member->username; break; case self::COMM_VAR_PASSWORD: /** * $member->password is ONLY available in the same request * when the new user account was created! After this we only * have the encrypted password in the DB, and the plain-text * version will never be available again in code... * * @since 1.0.1.1 */ if (self::COMM_TYPE_SIGNUP == $this->type) { $var_value = $member->password; } break; case self::COMM_VAR_USER_DISPLAY_NAME: $var_value = $wp_user->display_name; break; case self::COMM_VAR_USER_FIRST_NAME: $var_value = $member->first_name; break; case self::COMM_VAR_USER_LAST_NAME: $var_value = $member->last_name; break; case self::COMM_VAR_NET_NAME: $var_value = get_site_option('site_name'); break; case self::COMM_VAR_NET_URL: $var_value = get_site_option('siteurl'); break; case self::COMM_VAR_MS_ACCOUNT_PAGE_URL: $var_value = sprintf('<a href="%s">%s</a>', MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_ACCOUNT), __('account page', MS_TEXT_DOMAIN)); break; // Needs: $membership // Needs: $membership case self::COMM_VAR_MS_NAME: if ($membership && $membership->name) { $var_value = $membership->name; } break; // Needs: $invoice // Needs: $invoice case self::COMM_VAR_MS_INVOICE: if ($invoice) { if ($invoice->total > 0 || $invoice->uses_trial) { $attr = array('post_id' => $invoice->id, 'pay_button' => 0); $scode = MS_Factory::load('MS_Controller_Shortcode'); $var_value = $scode->membership_invoice($attr); } } break; // Needs: $subscription // Needs: $subscription case self::COMM_VAR_MS_REMAINING_DAYS: if ($subscription) { $days = $subscription->get_remaining_period(); $var_value = sprintf(__('%s day%s', MS_TEXT_DOMAIN), $days, abs($days) > 1 ? 's' : ''); } break; // Needs: $subscription // Needs: $subscription case self::COMM_VAR_MS_REMAINING_TRIAL_DAYS: if ($subscription) { $days = $subscription->get_remaining_trial_period(); $var_value = sprintf(__('%s day%s', MS_TEXT_DOMAIN), $days, abs($days) > 1 ? 's' : ''); } break; // Needs: $subscription // Needs: $subscription case self::COMM_VAR_MS_EXPIRY_DATE: if ($subscription) { $var_value = $subscription->expire_date; } break; } $comm_vars[$key] = apply_filters('ms_model_communication_send_message_comm_var-' . $key, $var_value, $this->type, $member, $subscription, $invoice); } return apply_filters('ms_model_communication_get_comm_vars', $comm_vars, $member); }
/** * Replace comm_vars with corresponding values. * * @since 1.0.0 * * @param MS_Model_Relationship $subscription The membership relationship to send message to. * @param WP_User $wp_user The wordpress user object to get info from. * @return array { * Returns array of ( $var_name => $var_replace ). * * @type string $var_name The variable name to replace. * @type string $var_replace The variable corresponding replace string. * } */ public function get_comm_vars($subscription, $wp_user) { $currency = MS_Plugin::instance()->settings->currency . ' '; $membership = $subscription->get_membership(); $invoice = null; // First try to fetch the current invoice. $invoice = $subscription->get_current_invoice(false); $prev_invoice = $subscription->get_previous_invoice(); // If no current invoice exists then fetch the previous invoice. if (empty($invoice)) { $invoice = $prev_invoice; } $comm_vars = apply_filters('ms_model_communication_comm_vars', $this->comm_vars); foreach ($comm_vars as $key => $description) { switch ($key) { case self::COMM_VAR_BLOG_NAME: $comm_vars[$key] = get_option('blogname'); break; case self::COMM_VAR_BLOG_URL: $comm_vars[$key] = get_option('home'); break; case self::COMM_VAR_USERNAME: $comm_vars[$key] = $wp_user->user_login; break; case self::COMM_VAR_USER_DISPLAY_NAME: $comm_vars[$key] = $wp_user->display_name; break; case self::COMM_VAR_USER_FIRST_NAME: $comm_vars[$key] = $wp_user->user_firstname; break; case self::COMM_VAR_USER_LAST_NAME: $comm_vars[$key] = $wp_user->user_lastname; break; case self::COMM_VAR_NET_NAME: $comm_vars[$key] = get_site_option('site_name'); break; case self::COMM_VAR_NET_URL: $comm_vars[$key] = get_site_option('siteurl'); break; case self::COMM_VAR_MS_NAME: if ($membership->name) { $comm_vars[$key] = $membership->name; } else { $comm_vars[$key] = ''; } break; case self::COMM_VAR_MS_INVOICE: if (isset($invoice) && ($invoice->total > 0 || $invoice->uses_trial)) { $attr = array('post_id' => $invoice->id, 'pay_button' => 0); $scode = MS_Factory::load('MS_Controller_Shortcode'); $comm_vars[$key] = $scode->membership_invoice($attr); } else { $comm_vars[$key] = ''; } break; case self::COMM_VAR_MS_ACCOUNT_PAGE_URL: $comm_vars[$key] = sprintf('<a href="%s">%s</a>', MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_ACCOUNT), __('account page', MS_TEXT_DOMAIN)); break; case self::COMM_VAR_MS_REMAINING_DAYS: $days = $subscription->get_remaining_period(); $comm_vars[$key] = sprintf(__('%s day%s', MS_TEXT_DOMAIN), $days, abs($days) > 1 ? 's' : ''); break; case self::COMM_VAR_MS_REMAINING_TRIAL_DAYS: $days = $subscription->get_remaining_trial_period(); $comm_vars[$key] = sprintf(__('%s day%s', MS_TEXT_DOMAIN), $days, abs($days) > 1 ? 's' : ''); break; case self::COMM_VAR_MS_EXPIRY_DATE: $comm_vars[$key] = $subscription->expire_date; break; } $comm_vars[$key] = apply_filters('ms_model_communication_send_message_comm_var_' . $key, $comm_vars[$key], $subscription); } return apply_filters('ms_model_communication_get_comm_vars', $comm_vars); }