/** * Overrides parent's to_html() method. * * Creates an output buffer, outputs the HTML and grabs the buffer content before releasing it. * Creates a wrapper 'ms-wrap' HTML element to contain content and navigation. The content inside * the navigation gets loaded with dynamic method calls. * e.g. if key is 'settings' then render_settings() gets called, if 'bob' then render_bob(). * * @todo Could use callback functions to call dynamic methods from within the helper, thus * creating the navigation with a single method call and passing method pointers in the $tabs array. * * @since 1.0.0 * * @return object */ public function to_html() { $this->check_simulation(); $items = $this->data['addon']->get_addon_list(); $lang = (object) array('active_badge' => __('ACTIVE', 'membership2'), 'show_details' => __('Details...', 'membership2'), 'close_details' => __('Close', 'membership2')); $filters = array('all' => __('All', 'membership2'), 'active' => __('Active', 'membership2'), 'inactive' => __('Inactive', 'membership2'), 'options' => __('With options', 'membership2')); ob_start(); ?> <div class="ms-wrap ms-addon-list"> <h2 class="ms-settings-title"> <i class="wpmui-fa wpmui-fa-puzzle-piece"></i> <?php _e('Membership Add-ons', 'membership2'); ?> </h2> <form action="" method="post"> <?php lib3()->html->addon_list($items, $lang, $filters); ?> </form> </div> <?php $html = ob_get_clean(); echo $html; }
public static function print_admin_message() { $msg = !empty($_GET['msg']) ? (int) $_GET['msg'] : 0; $class = $msg > 0 ? 'updated' : 'error'; if ($msg = self::get_admin_message($msg)) { lib3()->ui->admin_message($msg, $class); } }
/** * Prepare fields that are displayed in the form. * * @since 1.0.1.0 * @return array */ protected function prepare_fields() { $api_status = MS_Addon_Mailchimp::get_api_status(); $settings = $this->data['settings']; $action = MS_Controller_Settings::AJAX_ACTION_UPDATE_CUSTOM_SETTING; $auto_opt_in = $settings->get_custom_setting('mailchimp', 'auto_opt_in'); $auto_opt_in = lib3()->is_true($auto_opt_in); $fields = array('mailchimp_api_test' => array('id' => 'mailchimp_api_test', 'type' => MS_Helper_Html::TYPE_HTML_TEXT, 'title' => __('MailChimp API test status: ', 'membership2'), 'value' => $api_status ? __('Verified', 'membership2') : __('Failed', 'membership2'), 'class' => $api_status ? 'ms-ok' : 'ms-nok'), 'mailchimp_api_key' => array('id' => 'mailchimp_api_key', 'name' => 'custom[mailchimp][api_key]', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('MailChimp API Key', 'membership2'), 'desc' => sprintf('<div>' . __('Visit <a href="%1$s">your API dashboard</a> to create an API Key.', 'membership2') . '</div>', 'http://admin.mailchimp.com/account/api" target="_blank'), 'value' => $settings->get_custom_setting('mailchimp', 'api_key'), 'class' => 'ms-text-medium', 'ajax_data' => array('group' => 'mailchimp', 'field' => 'api_key', 'action' => $action)), 'separator' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'auto_opt_in' => array('id' => 'auto_opt_in', 'name' => 'custom[mailchimp][auto_opt_in]', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => __('Automatically opt-in new users to the mailing list.', 'membership2'), 'desc' => __('Users will not receive an email confirmation. You are responsible to inform your users.', 'membership2'), 'value' => $auto_opt_in, 'class' => 'inp-before', 'ajax_data' => array('group' => 'mailchimp', 'field' => 'auto_opt_in', 'action' => $action)), 'separator1' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'mail_list_registered' => array('id' => 'mail_list_registered', 'name' => 'custom[mailchimp][mail_list_registered]', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'title' => __('Registered users mailing list (not members)', 'membership2'), 'field_options' => MS_Addon_Mailchimp::get_mail_lists(), 'value' => $settings->get_custom_setting('mailchimp', 'mail_list_registered'), 'ajax_data' => array('group' => 'mailchimp', 'field' => 'mail_list_registered', 'action' => $action)), 'mail_list_members' => array('id' => 'mail_list_members', 'name' => 'custom[mailchimp][mail_list_members]', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'title' => __('Members mailing list', 'membership2'), 'field_options' => MS_Addon_Mailchimp::get_mail_lists(), 'value' => $settings->get_custom_setting('mailchimp', 'mail_list_members'), 'ajax_data' => array('group' => 'mailchimp', 'field' => 'mail_list_members', 'action' => $action)), 'mail_list_deactivated' => array('id' => 'mail_list_deactivated', 'name' => 'custom[mailchimp][mail_list_deactivated]', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'title' => __('Deactivated memberships mailing list', 'membership2'), 'field_options' => MS_Addon_Mailchimp::get_mail_lists(), 'value' => $settings->get_custom_setting('mailchimp', 'mail_list_deactivated'), 'ajax_data' => array('group' => 'mailchimp', 'field' => 'mail_list_deactivated', 'action' => $action))); return $fields; }
/** * Change a setting of the addon * * @since 1.0.0 * * @param string $key * @param string $value */ public function set($key, $value) { switch ($key) { case 'is_live': // This is a boolean value, not a string. $value = lib3()->is_true($value); break; } return $this->set_custom_setting(self::GROUP, $key, $value); }
private function get_query_args() { $defaults = MS_Model_Invoice::get_query_args(); lib3()->array->equip_request('s'); $per_page = $this->get_items_per_page('invoice_per_page', self::DEFAULT_PAGE_SIZE); $current_page = $this->get_pagenum(); $args = array('posts_per_page' => $per_page, 'offset' => ($current_page - 1) * $per_page); // Filter by search-term $search_filter = $_REQUEST['s']; if (!empty($search_filter)) { $this->search_string = $search_filter; } $args = wp_parse_args($args, $defaults); return $args; }
/** * Initializes the Add-on. Always executed. * * @since 1.0.1.0 */ public function init() { if (self::is_active()) { $this->first_click_free = lib3()->is_true($this->get_setting('first_click_free')); $this->add_filter('ms_model_membership_is_system', 'is_system', 10, 2); $this->add_filter('ms_model_membership_is_valid_type', 'is_valid_type', 10, 2); $this->add_filter('ms_model_membership_get_types', 'get_types'); $this->add_filter('ms_helper_listtable_membership_column_name_actions', 'list_table_actions', 10, 2); $this->add_filter('ms_helper_listtable_memberships_name_badge', 'list_table_badge', 10, 2); $this->add_action('ms_init_done', 'apply_membership'); // Last action in the init sequence. $this->create_membership(); } else { $this->add_filter('ms_model_membership_get_memberships', 'hide_membership', 10, 2); } }
protected function prepare_fields() { $gateway = $this->data['model']; $action = MS_Controller_Gateway::AJAX_ACTION_UPDATE_GATEWAY; $nonce = wp_create_nonce($action); $fields = array('mode' => array('id' => 'mode', 'title' => __('Mode', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $gateway->mode, 'field_options' => $gateway->get_mode_types(), 'class' => 'ms-text-large', 'ajax_data' => array(1)), 'api_login_id' => array('id' => 'api_login_id', 'title' => __('API Login ID', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'value' => $gateway->api_login_id, 'class' => 'ms-text-large', 'ajax_data' => array(1)), 'api_transaction_key' => array('id' => 'api_transaction_key', 'title' => __('API Transaction Key', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'value' => $gateway->api_transaction_key, 'class' => 'ms-text-large', 'ajax_data' => array(1)), 'pay_button_url' => array('id' => 'pay_button_url', 'title' => apply_filters('ms_translation_flag', __('Payment button label or URL', 'membership2'), 'gateway-button' . $gateway->id), 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'value' => $gateway->pay_button_url, 'class' => 'ms-text-large', 'ajax_data' => array(1)), 'secure_cc' => array('id' => 'secure_cc', 'title' => __('Secure Payments', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'value' => lib3()->is_true($gateway->secure_cc), 'ajax_data' => array(1)), 'secure_cc_off' => array('id' => 'secure_cc_off', 'type' => MS_Helper_Html::TYPE_HTML_TEXT, 'value' => __('Default payment option: Credit card details need to be entered once and can be reused without entering the CVC number again.', 'membership2'), 'class' => 'hidden secure_cc_off'), 'secure_cc_on' => array('id' => 'secure_cc_on', 'type' => MS_Helper_Html::TYPE_HTML_TEXT, 'value' => __('Secure payment option: The user needs to enter the credit cards CVC number for every transaction - even for saved credit cards and every recurring payment.', 'membership2'), 'class' => 'hidden secure_cc_on')); // Process the fields and add missing default attributes. foreach ($fields as $key => $field) { if (!empty($field['ajax_data'])) { $fields[$key]['ajax_data']['field'] = $fields[$key]['id']; $fields[$key]['ajax_data']['_wpnonce'] = $nonce; $fields[$key]['ajax_data']['action'] = $action; $fields[$key]['ajax_data']['gateway_id'] = $gateway->id; } } return $fields; }
/** * Processes a form submit and changes the rule values, if valid form data * is found. * * @since 1.0.0 */ private function process_form() { $action = false; if (isset($_POST['rule_action'])) { $action = $_POST['rule_action']; if (!$this->verify_nonce($action)) { $action = false; } } elseif (isset($_GET['rule_action'])) { $action = $_GET['rule_action']; if (!$this->verify_nonce($action, 'GET')) { $action = false; } } if (empty($action)) { return; } $redirect = false; switch ($action) { case self::ACTION_ADD: lib3()->array->strip_slashes($_POST, 'url_value'); $url = $_POST['url_value']; $base = MS_Model_Membership::get_base(); $rule = $base->get_rule(self::RULE_ID); $rule->add_url($url); $base->set_rule(self::RULE_ID, $rule); $base->save(); $redirect = true; break; case self::ACTION_DELETE: $id = $_REQUEST['item']; $base = MS_Model_Membership::get_base(); $rule = $base->get_rule(self::RULE_ID); $rule->delete_url($id); $base->set_rule(self::RULE_ID, $rule); $base->save(); $redirect = true; break; } if ($redirect) { $target = esc_url_raw(remove_query_arg(array('_wpnonce', 'item', 'rule_action'))); wp_safe_redirect($target); exit; } }
/** * Outputs the content of the widget. * * @since 1.0.0 * * @param array $args * @param array $instance */ public function widget($args, $instance) { $redirect_login = false; $redirect_logout = false; $shortcode_args = ''; if (!empty($instance['redirect_login'])) { $redirect_login = lib3()->net->expand_url($instance['redirect_login']); } if (!empty($instance['redirect_logout'])) { $redirect_logout = lib3()->net->expand_url($instance['redirect_logout']); } if (!empty($instance['shortcode_args'])) { $shortcode_args = $instance['shortcode_args']; } echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; echo apply_filters('widget_title', $instance['title']); echo $args['after_title']; } $scode = sprintf('[%1$s header="no" %2$s %3$s %4$s]', MS_Helper_Shortcode::SCODE_LOGIN, $redirect_login ? 'redirect_login="******"' : '', $redirect_logout ? 'redirect_logout="' . $redirect_logout . '"' : '', $shortcode_args); echo do_shortcode($scode); echo $args['after_widget']; }
/** * Internal helper function that saves a user profile value either to DB or * to the session (depending if the user is logged in or not). * * @since 1.0.0 * @internal * * @param MS_Model_Member $member * @param string $key The field key. * @param mixed $value The value to save * @return bool True means that the value was set in $member, otherwise it * was set in the session. */ protected static function set_tax_profile_value($member, $key, $value) { if (is_object($member) && $member->is_valid()) { $member->set_custom_data($key, $value); $need_save = true; } else { lib3()->session->get_clear('ms_' . $key); lib3()->session->add('ms_' . $key, $value); $need_save = false; } return $need_save; }
/** * Adds activation details for a single add-on to the import object * * @since 1.0.0 * @param string $name The add-on name */ protected function activate_addon($name) { $this->data->settings['addons'] = lib3()->array->get($this->data->settings['addons']); $this->data->settings['addons'][$name] = true; }
/** * Load Membership manager specific scripts. * * @since 1.0.0 */ public function enqueue_scripts() { $data = array('ms_init' => array(), 'lang' => array('msg_delete' => __('Do you want to completely delete the membership <strong>%s</strong> including all subscriptions?', 'membership2'), 'btn_delete' => __('Delete', 'membership2'), 'btn_cancel' => __('Cancel', 'membership2'), 'quickedit_error' => __('Error while saving changes.', 'membership2'))); $step = $this->get_step(); switch ($step) { case self::STEP_WELCOME_SCREEN: break; case self::STEP_ADD_NEW: $data['ms_init'][] = 'view_membership_add'; $data['initial_url'] = MS_Controller_Plugin::get_admin_url(); break; case self::STEP_OVERVIEW: $data['ms_init'][] = 'view_membership_overview'; break; case self::STEP_PAYMENT: $data['ms_init'][] = 'view_membership_payment'; $data['ms_init'][] = 'view_settings_payment'; break; case self::STEP_EDIT: $data['ms_init'][] = 'view_membership_payment'; $tab = $this->get_active_edit_tab(); switch ($tab) { case self::TAB_TYPE: add_thickbox(); $data['ms_init'][] = 'view_membership_add'; break; case self::TAB_UPGRADE: $data['ms_init'][] = 'view_membership_upgrade'; break; case self::TAB_MESSAGES: $data['ms_init'][] = 'view_settings_protection'; break; case self::TAB_EMAILS: $data['ms_init'][] = 'view_settings_automated_msg'; break; } do_action('ms_controller_membership_enqueue_scripts_tab-' . $tab, $this); break; case self::STEP_MS_LIST: $data['ms_init'][] = 'view_membership_list'; $data['ms_init'][] = 'view_settings_setup'; break; } lib3()->ui->data('ms_data', $data); wp_enqueue_script('ms-admin'); wp_enqueue_script('jquery-validate'); do_action('ms_controller_membership_enqueue_scripts', $this); do_action('ms_controller_membership_enqueue_scripts-' . $step, $this); }
/** * Load specific scripts. * * @since 1.0.0 */ public function enqueue_scripts() { $data = array('ms_init' => array('view_help')); lib3()->ui->data('ms_data', $data); wp_enqueue_script('ms-admin'); }
/** * Load Membership admin scripts. * * @since 1.0.0 */ public function enqueue_scripts() { $active_tab = $this->get_active_tab(); do_action('ms_controller_settings_enqueue_scripts_' . $active_tab); $plugin_url = MS_Plugin::instance()->url; $version = MS_Plugin::instance()->version; $initial_url = MS_Controller_Plugin::get_admin_url(); $data = array('ms_init' => array(), 'initial_url' => $initial_url); $data['ms_init'][] = 'view_settings'; switch ($active_tab) { case self::TAB_PAYMENT: add_thickbox(); $data['ms_init'][] = 'view_settings_payment'; break; case self::TAB_MESSAGES: $data['ms_init'][] = 'view_settings_protection'; break; case self::TAB_EMAILS: $data['ms_init'][] = 'view_settings_automated_msg'; break; case self::TAB_GENERAL: $data['ms_init'][] = 'view_settings_setup'; break; } lib3()->ui->data('ms_data', $data); wp_enqueue_script('ms-admin'); }
/** * Enqueues necessary scripts and styles. * * Related Action Hooks: * - wp_enqueue_scripts * - admin_enqueue_scripts * * @since 1.0.0 */ public function enqueue_scripts() { $data = array('ms_init' => array('controller_adminbar'), 'switching_text' => __('Switching...', 'membership2')); lib3()->ui->add('select'); lib3()->ui->data('ms_data', $data); wp_enqueue_script('ms-admin'); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_style('ms-public'); }
/** * Adds a javascript to the page that will translate the jQuery validator * messages. * * @since 1.0.0 */ public static function translate_jquery_validator() { ob_start(); ?> jQuery.extend( jQuery.validator.messages, { required: "<?php _e('This field is required.', 'membership2'); ?> ", remote: "<?php _e('Please fix this field.', 'membership2'); ?> ", email: "<?php _e('Please enter a valid email address.', 'membership2'); ?> ", url: "<?php _e('Please enter a valid URL.', 'membership2'); ?> ", date: "<?php _e('Please enter a valid date.', 'membership2'); ?> ", dateISO: "<?php _e('Please enter a valid date ( ISO ).', 'membership2'); ?> ", number: "<?php _e('Please enter a valid number.', 'membership2'); ?> ", digits: "<?php _e('Please enter only digits.', 'membership2'); ?> ", creditcard: "<?php _e('Please enter a valid credit card number.', 'membership2'); ?> ", equalTo: "<?php _e('Please enter the same value again.', 'membership2'); ?> ", maxlength: jQuery.validator.format( "<?php _e('Please enter no more than {0} characters.', 'membership2'); ?> " ), minlength: jQuery.validator.format( "<?php _e('Please enter at least {0} characters.', 'membership2'); ?> " ), rangelength: jQuery.validator.format( "<?php _e('Please enter a value between {0} and {1} characters long.', 'membership2'); ?> " ), range: jQuery.validator.format( "<?php _e('Please enter a value between {0} and {1}.', 'membership2'); ?> " ), max: jQuery.validator.format( "<?php _e('Please enter a value less than or equal to {0}.', 'membership2'); ?> " ), min: jQuery.validator.format( "<?php _e('Please enter a value greater than or equal to {0}.', 'membership2'); ?> " ) }); <?php $script = ob_get_clean(); lib3()->ui->script($script); }
/** * Returns HTML partial that contains password-reset form. * Based on WordPress core code from wp-login.php * * @since 1.0.0 * * @return string */ private function reset_form() { static $Reset_Result = null; if (null === $Reset_Result) { lib3()->array->equip_get('login', 'key'); lib3()->array->equip_post('pass1', 'pass2'); $rp_login = wp_unslash($_GET['login']); $rp_key = wp_unslash($_GET['key']); $err_msg = new WP_Error(); $fatal_error = false; lib3()->array->strip_slashes($_POST, 'pass1', 'pass2'); $pass1 = $_POST['pass1']; $pass2 = $_POST['pass2']; // Get the user object and validate the key. if ($rp_login && $rp_key) { $user = check_password_reset_key($rp_key, $rp_login); } else { $user = false; } if (!$user || is_wp_error($user)) { // If the user was not found then show an error message. if ($user && 'expired_key' == $user->get_error_code()) { $fatal_error = true; $err_msg->add('password_expired_key', __('Sorry, this reset-key is not valid anymore. Please request a new reset email and try again.', 'membership2')); } else { $fatal_error = true; $err_msg->add('password_invalid_key', __('Sorry, we did not find a valid reset-key. Please request a new reset email and try again.', 'membership2')); } } else { // If the user provided a new password, then check it now. if ($pass1 && $pass1 != $pass2) { $pass1 = false; $err_msg->add('password_reset_mismatch', __('The passwords do not match, try again.', 'membership2')); } } if ($fatal_error && count($err_msg->errors)) { $url = esc_url_raw(add_query_arg(array('show' => 'lostpass'), remove_query_arg(array('action', 'key', 'login')))); $Reset_Result = sprintf('[ms-note type="warning"]%s[/ms-note]<a href="%s">%s</a>', $err_msg->get_error_message(), $url, __('Request a new password-reset key', 'membership2')); } elseif ($pass1) { // This action is documented in wp-login.php do_action('validate_password_reset', $err_msg, $user); reset_password($user, $_POST['pass1']); // All done! Show success message and link to login form $url = esc_url_raw(remove_query_arg(array('action', 'key', 'login'))); $Reset_Result = sprintf('[ms-note type="info"]%s[/ms-note]<a href="%s">%s</a>', __('Your Password has been reset.', 'membership2'), $url, __('Login with your new password', 'membership2')); } else { // This action is documented in wp-login.php do_action('validate_password_reset', $err_msg, $user); wp_enqueue_script('utils'); wp_enqueue_script('user-profile'); ob_start(); if (count($err_msg->errors)) { printf('[ms-note type="warning"]%s[/ms-note]', implode('<br>', $err_msg->get_error_messages())); } ?> <form name="resetpassform" id="resetpassform" action="" method="post" autocomplete="off" class="ms-form"> <input type="hidden" id="user_login" value="<?php echo esc_attr($rp_login); ?> " autocomplete="off"/> <p class="user-pass1-wrap"> <label for="pass1"><?php _e('New password'); ?> </label><br /> <div class="wp-pwd"> <span class="password-input-wrapper"> <input type="password" data-reveal="1" data-pw="<?php echo esc_attr(wp_generate_password(16)); ?> " name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" aria-describedby="pass-strength-result" /> </span> <div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php _e('Strength indicator'); ?> </div> </div> </p> <p class="user-pass2-wrap"> <label for="pass2"><?php _e('Confirm new password'); ?> </label><br /> <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /> </p> <p class="description indicator-hint"><?php echo wp_get_password_hint(); ?> </p> <br class="clear"/> <?php // This action is documented in wp-login.php do_action('resetpass_form', $user); ?> <p class="submit"> <input type="hidden" name="rp_key" value="<?php echo esc_attr($rp_key); ?> " /> <button type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large"> <?php _e('Reset Password', 'membership2'); ?> </button> </p> </form> <?php $html = ob_get_clean(); $Reset_Result = apply_filters('ms_compact_code', $html); } $Reset_Result = do_shortcode($Reset_Result); } return $Reset_Result; }
/** * Returns property associated with the render. * * @since 1.0.0 * @param string $property The name of a property. * @return mixed Returns mixed value of a property or NULL if a property doesn't exist. */ public function __get($property) { $value = null; switch ($property) { case 'rule_value': case 'dripped': $this->{$property} = lib3()->array->get($this->{$property}); $value = $this->{$property}; break; default: if (property_exists($this, $property)) { $value = $this->{$property}; } break; } return apply_filters('ms_rule__get', $value, $property, $this); }
/** * Load Billing specific scripts. * * @since 1.0.0 */ public function enqueue_scripts() { $data = array('ms_init' => array()); if (isset($_GET['action']) && 'edit' == $_GET['action']) { wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-validate'); $data['ms_init'][] = 'view_billing_edit'; } else { $module = ''; if (isset($_GET['show'])) { $module = $_GET['show']; } if ('logs' == $module || 'matching' == $module) { $data['ms_init'][] = 'view_billing_transactions'; $data['lang'] = array('link_title' => __('Link Transaction', 'membership2')); } } lib3()->ui->data('ms_data', $data); wp_enqueue_script('ms-admin'); }
/** * Handle Ajax update dripped rules action. * * Related Action Hooks: * - wp_ajax_update_dripped * * @since 1.0.0 */ public function ajax_action_update_dripped() { $msg = MS_Helper_Membership::MEMBERSHIP_MSG_NOT_UPDATED; $this->_resp_reset(); $fields = array('membership_ids', 'rule_type', 'item_id'); if (!$this->verify_nonce('inline')) { $this->_resp_err('Invalid Nonce'); } elseif (!$this->is_admin_user()) { $this->_resp_err('Access Denied'); } elseif (!self::validate_required($fields, 'POST', false)) { $this->_resp_err('Missing Data'); } if ($this->_resp_ok()) { $ids = $_POST['membership_ids']; $rule_type = $_POST['rule_type']; $item_id = $_POST['item_id']; if (!is_array($ids)) { $ids = explode(',', $ids); } // Loop all specified memberships and set the rule values. foreach ($ids as $id) { if (empty($_POST['ms_' . $id])) { continue; } $data = lib3()->array->get($_POST['ms_' . $id]); lib3()->array->equip($data, 'dripped_type', 'date', 'delay_unit', 'delay_type'); $membership = MS_Factory::load('MS_Model_Membership', $id); $rule = $membership->get_rule($rule_type); $rule->set_dripped_value($item_id, $data['dripped_type'], $data['date'], $data['delay_unit'], $data['delay_type']); $membership->set_rule($rule_type, $rule); $membership->save(); } $msg = MS_Helper_Membership::MEMBERSHIP_MSG_UPDATED; } if (MS_Helper_Membership::MEMBERSHIP_MSG_UPDATED == $msg) { // If everything went well then get a refershed version of the list-table. $GLOBALS['hook_suffix'] = 'membership-2_page_' . MS_Controller_Plugin::MENU_SLUG . '-protection'; $table = apply_filters('ms_rule_listtable-' . $rule_type, null); if ($table) { $args = array('offset' => isset($_POST['offset']) ? $_POST['offset'] : 0, 'number' => isset($_POST['number']) ? $_POST['number'] : 20); $items = $table->get_model()->get_contents($args); if (isset($items[$item_id])) { echo $table->display_rows(array($items[$item_id])); } } } else { $msg .= $this->_resp_code(); echo $msg; } exit; }
/** * Add custom filters to the searchbox * * @since 1.0.0 */ public function searchbox_filters() { lib3()->array->equip_request('search_options'); $search_options = array('id' => 'search_options', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $_REQUEST['search_options'], 'field_options' => array('username' => __('Username / E-mail', 'membership2'), 'nickname' => __('Nickname', 'membership2'), 'first_name' => __('First Name', 'membership2'), 'last_name' => __('Last Name', 'membership2'))); // Display the extra search options MS_Helper_Html::html_element($search_options); }
/** * Get WP_Query object arguments. * * Default search arguments for this model. * * @since 1.0.0 * @internal * * @param $args The query user args * @see @link http://codex.wordpress.org/Class_Reference/WP_User_Query * @param string $search_option The search options (only members, not members, all users). * @return array $args The parsed args. */ public static function get_query_args($args = null, $search_option = self::SEARCH_ONLY_MEMBERS) { global $wpdb; $defaults = apply_filters('ms_model_member_get_query_args_defaults', array('order' => 'DESC', 'orderby' => 'ID', 'number' => 20, 'offset' => 0, 'fields' => 'ID')); $args = lib3()->array->get($args); lib3()->array->equip($args, 'meta_query', 'membership_id', 'subscription_status'); if ('none' !== $args['meta_query']) { $args['meta_query'] = lib3()->array->get($args['meta_query']); switch ($search_option) { case self::SEARCH_ONLY_MEMBERS: $args['meta_query'] = array(array('key' => 'ms_is_member', 'value' => true)); break; case self::SEARCH_ALL_USERS: default: break; } } else { unset($args['meta_query']); } // For performance reasons we execute a custom SQL to get relevant user_ids. if (!empty($args['membership_id']) || !empty($args['subscription_status']) && 'all' != $args['subscription_status']) { $membership_id = intval($args['membership_id']); $status = $args['subscription_status']; switch ($status) { case 'expired': $status_val = implode(',', array("'" . MS_Model_Relationship::STATUS_TRIAL_EXPIRED . "'", "'" . MS_Model_Relationship::STATUS_EXPIRED . "'")); break; default: $status_val = $wpdb->prepare(" '%s' ", $status); break; } $sql = "\n\t\t\tSELECT DISTINCT usr.meta_value\n\t\t\tFROM {$wpdb->posts} p\n\t\t\tINNER JOIN {$wpdb->postmeta} mem ON mem.post_id=p.ID AND mem.meta_key='membership_id'\n\t\t\tINNER JOIN {$wpdb->postmeta} sta ON sta.post_id=p.ID AND sta.meta_key='status'\n\t\t\tINNER JOIN {$wpdb->postmeta} usr ON usr.post_id=p.ID AND usr.meta_key='user_id'\n\t\t\tWHERE\n\t\t\t\tp.post_type = %s\n\t\t\t\tAND ('0' = %s OR mem.meta_value = %s)\n\t\t\t\tAND ('' = %s OR sta.meta_value IN ({$status_val}))\n\t\t\t"; $sql = $wpdb->prepare($sql, MS_Model_Relationship::get_post_type(), $membership_id, $membership_id, $status); $ids = $wpdb->get_col($sql); if (empty($ids) || !is_array($ids)) { $ids = array(0); } $args['include'] = $ids; } if (MS_Plugin::is_network_wide()) { $defaults['blog_id'] = false; } $args = wp_parse_args($args, $defaults); return apply_filters('ms_model_member_get_query_args', $args, $defaults); }
/** * Enqueue admin scripts in the settings screen. * * @since 1.0.0 */ public function enqueue_scripts() { $data = array('ms_init' => array('view_settings_import'), 'lang' => array('progress_title' => __('Importing data...', 'membership2'), 'close_progress' => __('Okay', 'membership2'), 'import_done' => __('All done!', 'membership2'), 'task_start' => __('Preparing...', 'membership2'), 'task_done' => __('Cleaning up...', 'membership2'), 'task_import_member' => __('Importing Member', 'membership2'), 'task_import_membership' => __('Importing Membership', 'membership2'), 'task_import_settings' => __('Importing Settings', 'membership2'))); lib3()->ui->data('ms_data', $data); wp_enqueue_script('ms-admin'); }
/** * Get the current page number * * @since 1.0.0 * @access protected * * @return int */ protected function get_pagenum() { lib3()->array->equip_request('paged'); $pagenum = absint($_REQUEST['paged']); if (isset($this->_pagination_args['total_pages']) && $pagenum > $this->_pagination_args['total_pages']) { $pagenum = $this->_pagination_args['total_pages']; } return max(1, $pagenum); }
/** * Checks, if some BuddyPress pages overlap with M2 membership pages. * * In some cases people used the same page-ID for both BuddyPress * registration and M2 registration. This will cause problems and must be * resolved to have M2 and BuddyPress work symbiotically. * * @since 1.0.1.1 */ protected function collission_check() { $buddy_pages = MS_Factory::get_option('bp-pages'); if (!is_array($buddy_pages)) { // Okay, no BuddyPress pages set up yet. return; } $duplicates = array(); foreach ($buddy_pages as $type => $page_id) { $collission = MS_Model_Pages::get_page_by('id', $page_id); if ($collission) { $title = $collission->post_title; if (!$title) { $title = $collission->post_name; } $duplicates[] = sprintf('%s - %s', $page_id, $title); } } if (count($duplicates)) { $msg = sprintf('%s<br><br>%s', sprintf(__('BuddyPress uses a page that is also used as a Membership page by Membership 2.<br>Please assign a different page for either %sMembership 2%s or %sBuddyPress%s to avoid conflicts.', 'membership2'), '<a href="' . MS_Controller_Plugin::get_admin_url('settings') . '">', '</a>', '<a href="' . admin_url('admin.php?page=bp-page-settings') . '">', '</a>'), implode('<br>', $duplicates)); lib3()->ui->admin_message($msg, 'error'); } }
/** * Load Membership manager specific scripts. * * @since 1.0.0 */ public function enqueue_scripts() { /* * Get a list of the dripped memberships: * We need this info in the javascript. */ $dripped = array(); foreach (MS_Model_Membership::get_dripped_memberships() as $item) { $dripped[$item->id] = $item->name; } $data = array('ms_init' => array(), 'lang' => array('quickedit_error' => __('Error while saving changes.', 'membership2')), 'dripped' => $dripped); $data['ms_init'][] = 'view_protected_content'; switch ($this->get_active_tab()) { case 'url': $data['valid_rule_msg'] = __('Valid', 'membership2'); $data['invalid_rule_msg'] = __('Invalid', 'membership2'); $data['empty_msg'] = __('Before testing you have to first enter one or more Page URLs above.', 'membership2'); $data['ms_init'][] = 'view_membership_urlgroup'; break; default: wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-validate'); break; } lib3()->ui->data('ms_data', $data); wp_enqueue_script('ms-admin'); do_action('ms_controller_protection_enqueue_scripts', $this); }
/** * Handle saving of Communication settings. * * @since 1.0.0 * * @param mixed[] $fields The data to process. */ public function save_communication($type, $fields) { $msg = MS_Helper_Settings::SETTINGS_MSG_NOT_UPDATED; if (!$this->is_admin_user()) { return $msg; } $membership_id = null; if (isset($_POST['membership_id'])) { $membership_id = intval($_POST['membership_id']); } $comm = MS_Model_Communication::get_communication($type, $membership_id, true); if (!empty($fields)) { lib3()->array->equip($fields, 'enabled', 'subject', 'email_body', 'period_unit', 'period_type', 'cc_enabled', 'cc_email'); $comm->enabled = lib3()->is_true($fields['enabled']); $comm->subject = $fields['subject']; $comm->message = $fields['email_body']; $comm->period = array('period_unit' => $fields['period_unit'], 'period_type' => $fields['period_type']); $comm->cc_enabled = !empty($fields['cc_enabled']); $comm->cc_email = $fields['cc_email']; $comm->save(); $msg = MS_Helper_Settings::SETTINGS_MSG_UPDATED; } return apply_filters('ms_controller_communication_save', $msg, $type, $fields, $this); }
/** * Flush the WordPress rewrite rules. * * @since 1.0.0 */ public function maybe_flush_rewrite_rules() { $refresh = lib3()->session->get_clear('refresh_url_rules'); if (!$refresh) { return; } // Set up the plugin specific rewrite rules again. $this->add_rewrite_rules(); $this->add_rewrite_tags(); do_action('ms_plugin_flush_rewrite_rules', $this); $url = remove_query_arg('ms_ts'); $url = esc_url_raw(add_query_arg('ms_flushed', 'yes', $url)); wp_safe_redirect($url); exit; }
/** * Set specific property. * * @since 1.0.0 * * @param string $property The name of a property to associate. * @param mixed $value The value of a property. */ public function __set($property, $value) { if (property_exists($this, $property)) { switch ($property) { case 'code': $value = sanitize_text_field(preg_replace('/[^a-zA-Z0-9\\s]/', '', $value)); $this->{$property} = strtoupper($value); $this->name = $this->{$property}; break; case 'discount': $this->{$property} = floatval($value); break; case 'discount_type': if (self::is_valid_discount_type($value)) { $this->{$property} = $value; } break; case 'start_date': $this->{$property} = $this->validate_date($value); break; case 'expire_date': $this->{$property} = $this->validate_date($value); if (strtotime($this->{$property}) < strtotime($this->start_date)) { $this->{$property} = null; } break; case 'membership_id': $value = lib3()->array->get($value); foreach ($value as $ind => $id) { if (!MS_Model_Membership::is_valid_membership($id)) { unset($value[$ind]); } } if (empty($value)) { $this->{$property} = array(0); } else { $this->{$property} = array_values($value); } break; case 'max_uses': case 'used': $this->{$property} = absint($value); break; default: if (property_exists($this, $property)) { $this->{$property} = $value; } break; } } do_action('ms_addon_coupon_model__set_after', $property, $value, $this); }
$msg .= "\nIn " . $callee['file'] . ' on line ' . $callee['line']; } error_log($msg); } public static function debug_trace($return = false) { if (!WP_DEBUG && !WDEV_DEBUG) { return; } $traces = debug_backtrace(); $fields = array('file', 'line', 'function', 'class'); $log = array('---------------------------- Trace start ----------------------------'); foreach ($traces as $i => $trace) { $line = array(); foreach ($fields as $field) { if (!empty($trace[$field])) { $line[] = "{$field}: {$trace[$field]}"; } } $log[] = " [{$i}]" . implode('; ', $line); } if ($return) { return implode("\n", $log); } else { error_log(implode("\n", $log)); } } } MS_Helper_Debug::log('**************************** REQUEST START ****************************'); MS_Helper_Debug::log('***** URL: ' . lib3()->net->current_url());