/** * Fires only at user creation from admin * Create even to send notification email. * * @since 1.0.2.6 * * @var int $user_id */ public function save_user_create_event($user_id) { if (is_admin()) { $member = MS_Factory::load('MS_Model_Member', $user_id); MS_Model_Event::save_event(MS_Model_Event::TYPE_MS_REGISTERED, $member); } }
/** * Create view output. * * @since 1.0.0 * @return string */ public function to_html() { $list_table = MS_Factory::create('MS_Helper_ListTable_Event'); $list_table->prepare_items(); if (isset($_REQUEST['membership_id'])) { $membership = MS_Factory::load('MS_Model_Membership', $_REQUEST['membership_id']); $title = sprintf(__('%s News', 'membership2'), $membership->get_name_tag()); $url = esc_url_raw(add_query_arg(array('step' => MS_Controller_Membership::STEP_OVERVIEW), remove_query_arg(array('paged', 'order', 'post_mime_type', 'detached', 'orderby', 's')))); $back_link = array('id' => 'back', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'value' => __('» Back to Overview', 'membership2'), 'url' => $url, 'class' => 'wpmui-field-button button'); } else { $title = __('Membership News', 'membership2'); $back_link = ''; } ob_start(); ?> <div class="wrap ms-wrap ms-membership-news"> <?php MS_Helper_Html::settings_header(array('title' => $title)); MS_Helper_Html::html_element($back_link); $list_table->search_box(); $list_table->views(); ?> <form action="" method="post"> <?php $list_table->display(); ?> </form> </div> <?php $html = ob_get_clean(); echo '' . $html; }
public function to_html() { $this->check_simulation(); // Search for orphaned relationships and delete them. MS_Model_Member::clean_db(); $listview = MS_Factory::create('MS_Helper_ListTable_Member'); $listview->prepare_items(); ob_start(); ?> <div class="wrap ms-wrap ms-member-list"> <?php MS_Helper_Html::settings_header(array('title' => __('Members', MS_TEXT_DOMAIN), 'title_icon_class' => 'wpmui-fa wpmui-fa-users', 'desc' => __('Here you can manage the Memberships of existing Users.', MS_TEXT_DOMAIN))); // Display a filter to switch between individual memberships. $this->membership_filter(); $listview->views(); $listview->search_box(); ?> <form method="post"> <?php $listview->display(); ?> </form> </div> <?php $html = ob_get_clean(); return $html; }
/** * Create view output. * * @since 1.0.0 * * @return string */ public function to_html() { $code_list = MS_Factory::create('MS_Addon_Invitation_Helper_Listtable'); $code_list->prepare_items(); $title = __('Invitations', 'membership2'); $add_new_button = array('id' => 'add_new', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url(MS_Addon_Invitation::SLUG, array('action' => 'edit', 'invitation_id' => 0)), 'value' => __('Add New Code', 'membership2'), 'class' => 'button'); ob_start(); ?> <div class="wrap ms-wrap"> <?php MS_Helper_Html::settings_header(array('title' => $title, 'title_icon_class' => 'wpmui-fa wpmui-fa-ticket')); ?> <div> <?php MS_Helper_Html::html_element($add_new_button); ?> </div> <form action="" method="post"> <?php $code_list->display(); ?> </form> <p><em> <?php _e('By default all Memberships are protected and require an invitation code to register.<br>You can manually change this for individual memberships via a new setting in the "Payment Options" settings of each membership.', 'membership2'); ?> </em></p> </div> <?php $html = ob_get_clean(); return apply_filters('ms_addon_invitation_view_list_to_html', $html, $this); }
/** * Create view output. * * @since 1.0.0 * * @return string */ public function to_html() { $coupon_list = MS_Factory::create('MS_Addon_Coupon_Helper_Listtable'); $coupon_list->prepare_items(); $title = __('Coupons', MS_TEXT_DOMAIN); $add_new_button = array('id' => 'add_new', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => MS_Controller_Plugin::get_admin_url('coupons', array('action' => 'edit', 'coupon_id' => 0)), 'value' => __('Add New Coupon', MS_TEXT_DOMAIN), 'class' => 'button'); ob_start(); ?> <div class="wrap ms-wrap"> <?php MS_Helper_Html::settings_header(array('title' => $title, 'title_icon_class' => 'wpmui-fa wpmui-fa-credit-card')); ?> <div> <?php MS_Helper_Html::html_element($add_new_button); ?> </div> <form action="" method="post"> <?php $coupon_list->display(); ?> </form> </div> <?php $html = ob_get_clean(); return apply_filters('ms_addon_coupon_view_list_to_html', $html, $this); }
/** * Tells Membership2 Admin to display this form to manage this rule. * * @since 1.0.0 * * @param array $callback (Invalid callback) * @param array $data The data collection. * @return array Correct callback. */ public function handle_render_callback($callback, $data) { $view = MS_Factory::load('MS_Addon_BuddyPress_Rule_View'); $view->data = $data; $callback = array($view, 'to_html'); return $callback; }
/** * Returns the HTML code of the view. * * @since 1.0.0 * @api * * @return string */ public function to_html() { $model = MS_Factory::create('MS_Model_Import_Membership'); $model->prepare(); $view = MS_Factory::create('MS_View_Settings_Import'); $view->data = array('model' => $model, 'compact' => true); $msg = __('Tip: You can also import your data later by visiting the Admin page <b>Membership2 > Settings > Import Tool</b>.', 'membership2'); ob_start(); // Render tabbed interface. ?> <div class="ms-wrap wrap"> <h2> <?php _e('Import Your Membership Data To Membership2', 'membership2'); ?> </h2> <?php if (MS_Plugin::is_network_wide()) { $msg .= '<br><br>' . __('You have enabled Network Wide Protection. We will import Membership data from your main blog.', 'membership2'); } lib3()->ui->admin_message($msg, 'info'); ?> <div class="ms-settings-import"> <?php echo $view->to_html(); ?> </div> </div> <?php return ob_get_clean(); }
/** * Create view output. * * @since 1.0.0 * @return string */ public function to_html() { $this->check_simulation(); $membership = $this->data['membership']; $admin_message = MS_Helper_Membership::get_admin_message(array($membership->name), $membership); $title = MS_Helper_Membership::get_admin_title(); $membership_list = MS_Factory::create('MS_Helper_ListTable_Membership'); $membership_list->prepare_items(); $create_new_button = array('id' => 'create_new_ms_button', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'url' => $this->data['create_new_url'], 'value' => __('Create New Membership', MS_TEXT_DOMAIN), 'class' => 'button'); ob_start(); ?> <div class="wrap ms-wrap"> <?php MS_Helper_Html::settings_header(array('title' => $title, 'desc' => array(__('Here you can view and edit all the Memberships you have created.', MS_TEXT_DOMAIN), $admin_message))); ?> <form action="" method="post"> <div class="ms-list-table-wrapper ms-membership-list"> <?php MS_Helper_Html::html_element($create_new_button); $membership_list->display(); MS_Helper_Html::html_element($create_new_button); ?> </div> </form> </div> <?php $html = ob_get_clean(); echo $html; }
public function to_html() { $settings = $this->data['settings']; $fields = array('plugin_enabled' => array('id' => 'plugin_enabled', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => __('Content Protection', 'membership2'), 'desc' => __('This setting toggles the content protection on this site.', 'membership2'), 'value' => MS_Plugin::is_enabled(), 'data_ms' => array('action' => MS_Controller_Settings::AJAX_ACTION_TOGGLE_SETTINGS, 'setting' => 'plugin_enabled')), 'hide_admin_bar' => array('id' => 'hide_admin_bar', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => __('Hide admin toolbar', 'membership2'), 'desc' => __('Hide the admin toolbar for non administrator users.', 'membership2'), 'value' => $settings->hide_admin_bar, 'data_ms' => array('action' => MS_Controller_Settings::AJAX_ACTION_TOGGLE_SETTINGS, 'setting' => 'hide_admin_bar'))); $fields = apply_filters('ms_view_settings_prepare_general_fields', $fields); $setup = MS_Factory::create('MS_View_Settings_Page_Setup'); $action_url = esc_url_raw(remove_query_arg(array('msg'))); ob_start(); MS_Helper_Html::settings_tab_header(); ?> <form action="<?php echo esc_url($action_url); ?> " method="post" class="cf"> <div class="cf"> <div class="ms-half"> <?php MS_Helper_Html::html_element($fields['plugin_enabled']); ?> </div> <div class="ms-half"> <?php MS_Helper_Html::html_element($fields['hide_admin_bar']); ?> </div> </div> <?php MS_Helper_Html::html_separator(); MS_Helper_Html::html_element($setup->html_full_form()); ?> </form> <?php return ob_get_clean(); }
/** * Tells Membership2 Admin to display this form to manage this rule. * * @since 1.0.0 * * @param array $callback (Invalid callback) * @param array $data The data collection. * @return array Correct callback. */ public function handle_render_callback($callback, $data) { $view = MS_Factory::load('MS_Rule_MemberRoles_View'); $view->data = $data; $callback = array($view, 'to_html'); return $callback; }
/** * Delete from wp option table * * @since 1.0.0 */ public function delete() { do_action('ms_model_option_delete_before', $this); $option_key = $this->option_key(); MS_Factory::delete_option($option_key); wp_cache_delete($option_key, 'MS_Model_Option'); do_action('ms_model_option_delete_after', $this); }
/** * Checks if the current Add-on is enabled * * @since 1.0.0 * @return bool */ public static function is_active() { if (!self::wp_recaptcha_active() && MS_Model_Addon::is_enabled(self::ID)) { $model = MS_Factory::load('MS_Model_Addon'); $model->disable(self::ID); } return MS_Model_Addon::is_enabled(self::ID); }
/** * Initializes the Add-on. Always executed. * * @since 1.0.0 */ public function init() { // Always remove bbpress from MS_Rule_CptGroup_Model. $this->add_filter('ms_rule_cptgroup_model_get_excluded_content', 'exclude_bbpress_cpts'); if (self::is_active()) { $this->add_filter('ms_controller_protection_tabs', 'rule_tabs'); MS_Factory::load('MS_Addon_Bbpress_Rule'); } }
/** * Initialize the Add-On. * * @since 1.0.0 */ public function __construct() { parent::__construct(); self::$model = MS_Factory::load('MS_Model_Addon'); self::$settings = MS_Factory::load('MS_Model_Settings'); $this->add_filter('ms_model_addon_register', 'register'); $this->add_action('ms_model_addon_initialize', 'init_addon'); $this->add_ajax_action($this->ajax_action(), 'ajax_update_settings'); }
/** * Initialize the object. * * @since 1.0.0 * @internal */ public function after_load() { parent::after_load(); $this->_api = MS_Factory::load('MS_Gateway_Stripe_Api'); $this->id = self::ID; $this->name = __('Stripe Single Gateway', 'membership2'); $this->group = 'Stripe'; $this->manual_payment = true; // Recurring billed/paid manually $this->pro_rate = true; }
/** * Initialize the object. * * @since 1.0.0 * @internal */ public function after_load() { parent::after_load(); $this->_api = MS_Factory::load('MS_Gateway_Stripe_Api'); $this->id = self::ID; $this->name = __('Stripe Single Gateway', 'membership2'); $this->group = 'Stripe'; $this->manual_payment = true; // Recurring billed/paid manually $this->pro_rate = true; $this->add_filter('ms_model_pages_get_ms_page_url', 'ms_model_pages_get_ms_page_url_cb', 99, 4); }
/** * Tests the Stripe Subscription gateway * @test */ function stripeplan_subscription() { $gateway = MS_Model_Gateway::factory(MS_Gateway_Stripeplan::ID); $user_id = TData::id('user', 'editor'); $membership_id = TData::id('membership', 'recurring'); $subscription = TData::subscribe($user_id, $membership_id); $controller = MS_Factory::load('MS_Controller_Gateway'); $gateway->update_stripe_data(); $data = array('card' => array('number' => '4242424242424242', 'exp_month' => 12, 'exp_year' => date('Y') + 1, 'cvc' => '314')); $res = M2_Stripe_Token::create($data); $token = $res->id; $form_data = array('_wpnonce' => wp_create_nonce($gateway->id . '_' . $subscription->id), 'gateway' => $gateway->id, 'ms_relationship_id' => $subscription->id, 'step' => 'process_purchase', 'stripeToken' => $token, 'stripeTokenType' => 'card', 'stripeEmail' => '*****@*****.**'); $_POST = $form_data; $_REQUEST = $_POST; // Right now the subscription must have status PENDING $this->assertEquals(MS_Model_Relationship::STATUS_PENDING, $subscription->status); /* * This function processes the purchase and will set the subscription * to active. */ $controller->process_purchase(); // Check the subscription status. $this->assertEquals(MS_Model_Relationship::STATUS_ACTIVE, $subscription->status); $this->assertEquals(1, count($subscription->payments)); // Modify the expiration date to trigger another payment. $today = date('Y-m-d'); $subscription->expire_date = $today; $this->assertEquals($today, $subscription->expire_date); $this->assertEquals(0, $subscription->get_remaining_period()); // Trigger next payment and validate it. $subscription->check_membership_status(); $this->assertEquals(2, count($subscription->payments)); // Modify the expiration date to trigger another payment. $subscription->expire_date = $today; $this->assertEquals($today, $subscription->expire_date); $this->assertEquals(0, $subscription->get_remaining_period()); // Trigger next payment and validate it. // THIS TIME NO PAYMENT SHOULD BE MADE because paycycle_repetitions = 2! $subscription->check_membership_status(); $this->assertEquals(2, count($subscription->payments)); // Also the subscription should be cancelled at stripe now. $customer_id = $subscription->get_member()->get_gateway_profile(MS_Gateway_Stripe_Api::ID, 'customer_id'); $customer = M2_Stripe_Customer::retrieve($customer_id); $invoice = $subscription->get_previous_invoice(); $stripe_sub_id = $invoice->external_id; $stripe_sub = $customer->subscriptions->retrieve($stripe_sub_id); $this->assertEquals('active', $stripe_sub->status); $this->assertTrue($stripe_sub->cancel_at_period_end); // Clean up. $customer->delete(); }
/** * Load and render the Documentation view. * * @since 1.0.0 */ public function admin_page() { /** * Create / Filter the view. * * @since 1.0.0 * @param object $this The MS_Controller_Help object. */ $view = MS_Factory::create('MS_View_Help'); $data = array(); $data['tabs'] = $this->get_tabs(); $view->data = apply_filters('ms_view_help_data', $data); $view->render(); }
/** * Checks if shared-setup was working. * @test */ function staging_data_is_correct() { $this->assertFalse(empty(TData::id('user', 'admin'))); wp_set_current_user(TData::id('user', 'admin')); $this->assertEquals(get_current_user_id(), TData::id('user', 'admin')); $this->assertFalse(empty(TData::id('user', 'editor'))); $this->assertFalse(empty(TData::id('post', 'sample-page'))); $this->assertEquals('page', get_post_type(TData::id('post', 'sample-page'))); $ms_id = TData::id('membership', 'simple'); $this->assertFalse(empty($ms_id)); $membership = MS_Factory::load('MS_Model_Membership', $ms_id); $this->assertEquals($ms_id, $membership->id); $this->assertEquals(29, $membership->price); }
/** * Check member capability add-on. * @test */ function member_capabilities_rule() { // We only test the addon as an isolated unit. $addon = MS_Factory::load('MS_Rule_MemberCaps_Model'); remove_all_filters('user_has_cap'); $addon->protect_admin_content(); wp_set_current_user(TData::id('user', 'admin')); $this->assertTrue(current_user_can('manage_options'), 'admin'); $this->assertTrue(current_user_can('edit_theme_options'), 'admin'); wp_set_current_user(TData::id('user', 'editor')); $this->assertFalse(current_user_can('manage_options'), 'editor'); $this->assertFalse(current_user_can('edit_theme_options'), 'editor'); $this->assertTrue(current_user_can('edit_pages'), 'editor'); $this->assertTrue(current_user_can('delete_pages'), 'editor'); }
/** * Checks if the user did import data from this source before. * * This information is not entirely reliable, since data could have been * deleted again after import. * * @since 1.0.0 * @return bool */ public static function did_import() { $settings = MS_Factory::load('MS_Model_Settings'); $did_import = !empty($settings->import[self::KEY]); /** * Allow users to manually declare that some M2 subscriptions were * imported from old Membership plugin. * * As a result M2 will additionally listen to the old M1 IPN URL for * PayPal payment notifications. * * @since 1.0.2.4 * @param bool $did_import */ return apply_filters('ms_did_import_m1_data', $did_import); }
/** * Generate/Prepare the dialog attributes. * * @since 1.0.0 */ public function prepare() { $subscription_id = $_POST['subscription_id']; $subscription = MS_Factory::load('MS_Model_Relationship', $subscription_id); $data = array('model' => $subscription); $data = apply_filters('ms_view_member_payment_data', $data); // Dialog Title $this->title = sprintf(__('Subscription Details: %1$s', MS_TEXT_DOMAIN), esc_html($subscription->get_membership()->name)); // Dialog Size $this->width = 940; $this->height = 600; // Contents $this->content = $this->get_contents($data); // Make the dialog modal $this->modal = true; }
public function column_membership($item) { $html = ''; $is_any = true; foreach ($item->membership_id as $id) { if (MS_Model_Membership::is_valid_membership($id)) { $is_any = false; $membership = MS_Factory::load('MS_Model_Membership', $id); $html .= sprintf('<span class="ms-bold">%s</span><br />', $membership->name); } } if ($is_any) { $html = sprintf('<span class="ms-low">%s</span>', __('Any', 'membership2')); } return $html; }
/** * Generate/Prepare the dialog attributes. * * @since 1.0.0 */ public function prepare() { $member_id = $_POST['member_id']; $member = MS_Factory::load('MS_Model_Member', $member_id); $data = array('model' => $member); $data = apply_filters('ms_view_member_dialog_data', $data); // Dialog Title $this->title = sprintf(__('Profile: %1$s %2$s', 'membership2'), esc_html($member->first_name), esc_html($member->last_name)); // Dialog Size $this->width = 940; $this->height = 500; // Contents $this->content = $this->get_contents($data); // Make the dialog modal $this->modal = true; }
/** * Constructor. * * @since 1.0.0 * * @param array $data The data what has to be associated with this render. */ public function __construct($data = array()) { static $Simulate = null; $this->data = $data; /** * Actions to execute when constructing the parent View. * * @since 1.0.0 * @param object $this The MS_View object. */ do_action('ms_view_construct', $this); if (null === $Simulate && MS_Model_Simulate::can_simulate()) { $Simulate = MS_Factory::load('MS_Model_Simulate'); self::$is_simulating = $Simulate->is_simulating(); } }
/** * Generate/Prepare the dialog attributes. * * @since 1.0.0 */ public function prepare() { $subscription_id = $_POST['subscription_id']; $subscription = MS_Factory::load('MS_Model_Relationship', $subscription_id); if (!empty($_REQUEST['statuscheck'])) { $subscription->check_membership_status(); } $data = array('model' => $subscription); $data = apply_filters('ms_view_member_subscription_data', $data); // Dialog Title $this->title = sprintf(__('Subscription Details: %1$s', 'membership2'), esc_html($subscription->get_membership()->name)); // Dialog Size $this->width = 940; $this->height = 800; // Contents $this->content = $this->get_contents($data); // Make the dialog modal $this->modal = true; }
/** * Displays a PopUp to the user that shows a sumary of the setup wizard * including possible next steps for configuration. * * @since 1.0.0 * @param MS_Model_Membership $membership The membership that was created. */ public static function show_setup_note($membership) { $popup = array(); $popup['title'] = sprintf('<i class="dashicons dashicons-yes"></i> %1$s<div class="subtitle">%2$s</div>', __('Congratulations!', 'membership2'), sprintf(__('You have successfully set up your <b>%1$s</b> Membership.', 'membership2'), $membership->name)); $setup = MS_Factory::create('MS_View_Settings_Page_Setup'); $popup['modal'] = true; $popup['close'] = false; $popup['sticky'] = false; $popup['class'] = 'ms-setup-done'; $popup['body'] = $setup->to_html(); $popup['height'] = $setup->dialog_height(); $popup['body'] .= sprintf('<div class="buttons">' . '<a href="%s" class="button">%s</a> ' . '<button type="button" class="button-primary close">%s</button>' . '</div>', MS_Controller_Plugin::get_admin_url('protection'), __('Set-up Access Levels', 'membership2'), __('Finish', 'membership2')); lib3()->html->popup($popup); $settings = MS_Plugin::instance()->settings; $settings->is_first_membership = false; if (!$membership->is_free) { $settings->is_first_paid_membership = false; } $settings->save(); }
/** * Returns tax information that must be applied to the specified amount. * * This function first checks the user-metadata for logged-in users and * takes the details that are stored in the user metadata table. * * If the user is not logged in or no metadata are found then the Taxamo API * is queried to get the default tax details for the country that * Taxamo automatically detects. * * @since 1.0.0 * @api * * @param numeric $amount The amount without taxes. * @return object { * Tax information * * string $country Tax country (2-digit code) * string $name Tax name * numeric $rate Tax rate (percent) * numeric $amount Tax amount * } */ public static function tax_info($amount = 0) { static $Info = null; if (null === $Info) { $settings = MS_Factory::load('MS_Model_Settings'); try { $profile = self::get_tax_profile(); $tax_number = null; if ($profile->use_vat_number) { $tax_number = $profile->vat_number; } $resp = self::taxamo()->calculateSimpleTax(null, $tax_number, null, $profile->tax_country->code, null, null, null, null, 100, $profile->tax_country->code, $settings->currency, null); // Prepare the result object. if (isset($resp->transaction->transaction_lines[0])) { $transaction = $resp->transaction->transaction_lines[0]; $Info = (object) array('country' => $resp->transaction->tax_country_code, 'rate' => $transaction->tax_rate, 'name' => $transaction->tax_name, 'amount' => 0); } } catch (Exception $ex) { MS_Helper_Debug::log('Taxamo error: ' . $ex->getMessage()); } } if (!is_object($Info)) { $Info = (object) array(); } if (!isset($Info->name)) { $Info->name = __('No Tax', 'membership2'); } if (!isset($Info->rate)) { $Info->rate = 0; } if (!isset($Info->amount)) { $Info->amount = 0; } if (!isset($Info->country)) { $Info->country = 'US'; } $Info->amount = $amount / 100 * $Info->rate; return $Info; }
/** * Set the singleton instance if it is not yet defined. * * @since 1.0.0 */ public function store_singleton() { if ($this->_in_cache) { return; } MS_Factory::set_singleton($this); }
/** * Checks if the user did import data from this source before. * * This information is not entirely reliable, since data could have been * deleted again after import. * * @since 1.0.0 * @return bool */ public static function did_import() { $settings = MS_Factory::load('MS_Model_Settings'); return !empty($settings->import[self::KEY]); }