/**
     * 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();
    }
 /**
  * validates and prepares the option key before it is used to read/write
  * a value in the database.
  *
  * @since  1.0.0
  * @api Used by MS_Factory
  *
  * @return string
  */
 public function option_key()
 {
     // Option key should be all lowercase.
     $key = strtolower(get_class($this));
     // Network-wide mode uses different options then single-site mode.
     if (MS_Plugin::is_network_wide()) {
         $key .= '-network';
     }
     return substr($key, 0, 64);
 }
Exemple #3
0
 /**
  * Adds the hooks to integrate with Membership2.
  *
  * This function is called when Membership2 is active and initializtion
  * is done.
  *
  * @since  1.0.0
  * @param  MS_Controller_Api $api The API instance.
  */
 public function init($api)
 {
     $this->api = $api;
     if (MS_Plugin::is_network_wide()) {
         $affiliate_plugin = 'affiliate/affiliate.php';
         if (!function_exists('is_plugin_active_for_network')) {
             require_once ABSPATH . '/wp-admin/includes/plugin.php';
         }
         if (!is_plugin_active_for_network($affiliate_plugin) && current_user_can('manage_options')) {
             lib2()->ui->admin_message(__('Membership2 uses network-wide protection.<br>Please network activate the Affiliate plugin to avoid problems with the Membership2 integration for Affiliates.', 'affiliate'), 'err');
         }
     }
     // -- Frontend integration
     // Reward for the referrer of the member.
     add_action('ms_invoice_paid', array($this, 'payment_processed'), 10, 2);
     // -- Admin integration
     // Display Affiliate settings on the Membership payment options page.
     add_action('ms_view_membership_payment_form', array($this, 'form'), 10, 2);
     // Save Affiliate settings via Ajax request.
     add_action('wp_ajax_' . self::AJAX_ACTION, array($this, 'save'));
 }
 /**
  * Get admin url.
  *
  * @since  1.0.0
  * @param  string $slug Optional. Slug of the admin page, if empty the link
  *         points to the main admin page.
  * @return string The full URL to the admin page.
  */
 public static function get_admin_url($slug = '', $args = null)
 {
     $base_slug = self::$base_slug;
     // These slugs are opened in network-admin for network-wide protection.
     $global_slugs = array('memberships', 'addon', 'settings');
     // Determine if the slug is opened in network-admin or site admin.
     $network_slug = MS_Plugin::is_network_wide() && (in_array($slug, $global_slugs) || is_network_admin());
     if ($network_slug) {
         $base_slug = self::MENU_SLUG;
         if ('memberships' === $slug) {
             $slug = '';
         }
     }
     if ('MENU_SLUG' == $slug) {
         $slug = self::MENU_SLUG;
     } elseif (empty($slug)) {
         $slug = self::$base_slug;
     } else {
         $slug = self::MENU_SLUG . '-' . $slug;
     }
     if (!$slug) {
         $slug = self::MENU_SLUG;
     }
     if ($network_slug) {
         $url = network_admin_url('admin.php?page=' . $slug);
     } else {
         $url = admin_url('admin.php?page=' . $slug);
     }
     if ($args) {
         $url = esc_url_raw(add_query_arg($args, $url));
     }
     return apply_filters('ms_controller_plugin_get_admin_url', $url);
 }
 /**
  * Handles all menu-items and calls the correct callback function.
  *
  * We introduce this routing function to monitor all menu-item calls so we
  * can make sure that network-wide protection loads the correct blog or
  * admin-area before displaing the page.
  *
  * This function will only handle submenu items of the Membership2 menu!
  *
  * @since  1.0.0
  */
 public function route_submenu_request()
 {
     global $submenu;
     $handler = null;
     $handle_it = false;
     if (!isset($_GET['page'])) {
         return;
     }
     if ($_GET['page'] === self::$base_slug) {
         $handle_it = true;
     } elseif (isset($submenu[self::$base_slug])) {
         foreach ($submenu[self::$base_slug] as $item) {
             if ($_GET['page'] === $item[2]) {
                 $handle_it = true;
                 break;
             }
         }
     }
     if (!$handle_it) {
         return;
     }
     if (MS_Plugin::is_wizard()) {
         $step_add = MS_Controller_Membership::STEP_ADD_NEW == MS_Plugin::instance()->settings->wizard_step;
         if (!$step_add || self::is_page('setup')) {
             $handler = array('any', array($this->controllers['membership'], 'admin_page_router'));
         } else {
             $handler = array('site', array($this->controllers['protection'], 'admin_page'));
         }
     } else {
         if (self::is_page('')) {
             $handler = array('network', array($this->controllers['membership'], 'admin_page_router'));
         } elseif (self::is_page('protection')) {
             $handler = array('site', array($this->controllers['protection'], 'admin_page'));
         } elseif (self::is_page('members')) {
             $handler = array('network', array($this->controllers['member'], 'admin_page'));
         } elseif (self::is_page('add-member')) {
             $handler = array('network', array($this->controllers['member'], 'admin_page_editor'));
         } elseif (self::is_page('addon')) {
             $handler = array('network', array($this->controllers['addon'], 'admin_page'));
         } elseif (self::is_page('settings')) {
             $handler = array('network', array($this->controllers['settings'], 'admin_page'));
         } elseif (self::is_page('help')) {
             $handler = array('any', array($this->controllers['help'], 'admin_page'));
         } elseif (self::is_page('billing')) {
             $handler = array('network', array($this->controllers['billing'], 'admin_page'));
         }
     }
     /**
      * Filter that allows Add-ons to add their own sub-menu handlers.
      *
      * @since  1.0.0
      */
     $handler = apply_filters('ms_route_submenu_request', $handler, $this);
     // Provide a fallback handler in case we could not identify the handler.
     if (!$handler) {
         $handler = array('network', array($this->controllers['membership'], 'membership_admin_page_router'));
     }
     // Handle the target attribute specified in $handler[0]
     if (MS_Plugin::is_network_wide() && 'any' != $handler[0]) {
         $redirect = false;
         $admin_script = 'admin.php?' . $_SERVER['QUERY_STRING'];
         if ('network' == $handler[0] && !is_network_admin()) {
             $redirect = network_admin_url($admin_script);
         } elseif ('site' == $handler[0] && is_network_admin()) {
             $redirect = admin_url($admin_script);
         }
         if ($redirect) {
             if (headers_sent()) {
                 echo '<script>location.href=' . json_encode($redirect) . ';</script>';
             } else {
                 wp_safe_redirect($redirect);
             }
             exit;
         }
     }
     $this->menu_handler = $handler;
 }
 /**
  * Checks several settings to make sure that M2 is fully working.
  *
  * A) Makes sure that network-wide protection works by ensuring that the
  *    plugin is also network-activated.
  * B) Checks if the permalink structure uses the post-name
  *
  * @since  1.0.0
  */
 private static function check_settings()
 {
     static $Setting_Check_Done = false;
     if (!$Setting_Check_Done) {
         $Setting_Check_Done = true;
         // A) Check plugin activation in network-wide mode.
         if (is_multisite()) {
             if (MS_Plugin::is_network_wide()) {
                 // This function does not exist in network admin
                 if (!function_exists('is_plugin_active_for_network')) {
                     require_once ABSPATH . '/wp-admin/includes/plugin.php';
                 }
                 if (!is_plugin_active_for_network(MS_PLUGIN)) {
                     activate_plugin(MS_PLUGIN, null, true);
                     lib3()->ui->admin_message(__('Info: Membership2 is not activated network-wide', 'membership2'));
                 }
             }
         }
         // B) Check the Permalink settings.
         if (false === strpos(get_option('permalink_structure'), '%postname%')) {
             lib3()->ui->admin_message(sprintf(__('Your %sPermalink structure%s should include the %sPost name%s to ensure Membership 2 is working correctly.', 'membership2'), '<a href="' . admin_url('options-permalink.php') . '">', '</a>', '<strong>', '</strong>'), 'err');
         }
     }
     return;
 }
    /**
     * Display the full settings form, used either by first membership
     * "completed" popup and also by the general settings tab.
     *
     * @since  1.0.0
     * @return string HTML code
     */
    public function html_full_form()
    {
        $fields = $this->prepare_fields();
        ob_start();
        ?>
		<div class="ms-setup-form">
			<?php 
        if (!MS_Plugin::is_network_wide()) {
            ?>
			<div class="ms-setup-nav">
				<div class="ms-title">
					<i class="ms-icon dashicons dashicons-menu"></i>
					<?php 
            _e('Please select pages you want to appear in your Navigation', MS_TEXT_DOMAIN);
            ?>
				</div>
				<div class="ms-description">
					<?php 
            printf(__('You can always change those later by going to %1$s in your admin sidebar.', MS_TEXT_DOMAIN), sprintf('<a href="%1$s" target="_blank">%2$s</a>', admin_url('nav-menus.php'), __('Appearance') . ' &raquo; ' . __('Menus')));
            ?>
				</div>
				<?php 
            echo $this->show_menu_controls();
            ?>
			</div>
			<?php 
        }
        ?>
			<div class="ms-setup-pages">
				<div class="ms-title">
					<i class="ms-icon dashicons dashicons-admin-page"></i>
					<?php 
        _e('Membership 2 Pages', MS_TEXT_DOMAIN);
        ?>
				</div>
				<div class="ms-description">
					<?php 
        _e('Set Up Membership 2 Pages that will be displayed on your website.', MS_TEXT_DOMAIN);
        ?>
				</div>
				<?php 
        if (is_array($fields['pages'])) {
            $page_types = array_keys($fields['pages']);
            $page_types_menu = array('memberships', 'register', 'account');
            $page_types_rest = array_diff($page_types, $page_types_menu);
            $groups = array('in-menu' => $page_types_menu, 'no-menu' => $page_types_rest);
            $pages_site_id = MS_Model_Pages::get_site_info('id');
            MS_Factory::select_blog($pages_site_id);
            foreach ($groups as $group_key => $group_items) {
                printf('<div class="ms-pages-group %1$s">', esc_attr($group_key));
                foreach ($group_items as $key) {
                    $field = $fields['pages'][$key];
                    ?>
							<div class="ms-settings-page-wrapper">
								<?php 
                    MS_Helper_Html::html_element($field);
                    ?>
								<div class="ms-action">
									<?php 
                    MS_Helper_Html::html_link(array('id' => 'url_page_' . $field['value'], 'url' => '', 'value' => __('View Page', MS_TEXT_DOMAIN), 'target' => '_blank', 'data_ms' => array('base' => get_home_url($pages_site_id, 'index.php?page_id='))));
                    ?>
									<span> | </span>
									<?php 
                    MS_Helper_Html::html_link(array('id' => 'edit_url_page_' . $field['value'], 'url' => '', 'value' => __('Edit Page', MS_TEXT_DOMAIN), 'target' => '_blank', 'data_ms' => array('base' => get_admin_url($pages_site_id, 'post.php?action=edit&post='))));
                    ?>
								</div>
							</div>
							<?php 
                }
                echo '</div>';
            }
        } else {
            echo $fields['pages'];
        }
        MS_Factory::revert_blog();
        ?>
			</div>
		</div>
		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_view_settings_page_setup_to_html', $html);
    }
 /**
  * Little hack to force the plugin to store/load the stripe_api data in same
  * option-field as the stripe-gateway settings.
  *
  * @since  1.0.0
  * @return string
  */
 public function option_key()
 {
     // Option key should be all lowercase.
     $key = 'ms_gateway_stripe';
     // Network-wide mode uses different options then single-site mode.
     if (MS_Plugin::is_network_wide()) {
         $key .= '-network';
     }
     return $key;
 }
 /**
  * Returns the post-type of the current object.
  *
  * @since  1.0.0
  * @return string The post-type name.
  */
 protected static function _post_type($orig_posttype)
 {
     // Post-type is always lower case.
     $posttype = strtolower(substr($orig_posttype, 0, 20));
     // Network-wide mode uses different post-types then single-site mode.
     if (MS_Plugin::is_network_wide()) {
         $posttype = substr($posttype, 0, 18);
         $posttype .= '-n';
     }
     return $posttype;
 }
Exemple #10
0
 /**
  * Reverts back to the original blog during network wide protection.
  *
  * @since  1.0.0
  */
 public static function revert_blog()
 {
     global $wpdb;
     if (MS_Plugin::is_network_wide()) {
         $site_id = array_pop(self::$Prev_Blog_Id);
         if ($site_id != $GLOBALS['blog_id']) {
             $GLOBALS['blog_id'] = $site_id;
             $wpdb->set_blog_id($GLOBALS['blog_id']);
             $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
         }
     }
 }
 /**
  * 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);
 }
 /**
  * Checks if the specified rule-key defines a rule that is relevant for the
  * current site in the network.
  *
  * If network-wide protection is disabled this function always returns true.
  *
  * @since  1.0.0
  * @param  string $key
  * @return bool
  */
 public static function is_current_site($key)
 {
     $res = true;
     $site_id = 0;
     if (MS_Plugin::is_network_wide()) {
         $parts = explode(':', $key);
         // Some rules have no site_id prefix (like URL rules)
         if (2 == count($parts)) {
             list($site_id, $type) = $parts;
             $site_id = intval($site_id);
             $res = MS_Factory::current_blog_id() == $site_id;
         }
     }
     return $res;
 }
 /**
  * Makes sure that network-wide protection works by ensuring that the plugin
  * is also network-activated.
  *
  * @since  1.0.0
  */
 private static function check_network_setup()
 {
     static $Network_Checked = false;
     if (!$Network_Checked) {
         $Network_Checked = true;
         // This is only relevant for multisite installations.
         if (!is_multisite()) {
             return;
         }
         if (MS_Plugin::is_network_wide()) {
             // This function does not exist in network admin
             if (!function_exists('is_plugin_active_for_network')) {
                 require_once ABSPATH . '/wp-admin/includes/plugin.php';
             }
             if (!is_plugin_active_for_network(MS_PLUGIN)) {
                 activate_plugin(MS_PLUGIN, null, true);
                 lib2()->ui->admin_message(__('Info: Membership2 is not activated network-wide', MS_TEXT_DOMAIN));
             }
         }
     }
 }
    /**
     * Renders the General help contents
     *
     * @since  1.0.0
     * @return string
     */
    public function render_tab_general()
    {
        ob_start();
        ?>
		<h2>
			<?php 
        /*_ex( 'Overview', 'help', MS_TEXT_DOMAIN ); */
        ?>
			<?php 
        _e('You\'re awesome :)', MS_TEXT_DOMAIN);
        ?>
<br />
		</h2>
		<p>
			<em><?php 
        _e('Thank you for using Membership 2', MS_TEXT_DOMAIN);
        ?>
</em>
			<br/ ><br />
			<?php 
        _ex('Here is a quick overview:', 'help', MS_TEXT_DOMAIN);
        ?>
		</p>
		<div>
		<?php 
        printf(_x('You use verion <strong>%s</strong> of Membership 2', 'help', MS_TEXT_DOMAIN), MS_PLUGIN_VERSION);
        if (function_exists('membership2_init_pro_app')) {
            printf('<br />' . _x('Hey, this is the <strong>PRO version</strong> of Membership 2 - thanks a lot for supporting us!', 'help', MS_TEXT_DOMAIN));
        } else {
            printf('<br />' . _x('This is the <strong>Free version</strong> of Membership 2 - did you check out our %sPRO version%s already?', 'help', MS_TEXT_DOMAIN), '<a href="https://premium.wpmudev.org/project/membership/" target="_blank">', '</a>');
        }
        if (is_multisite()) {
            if (MS_Plugin::is_network_wide()) {
                printf('<br />' . _x('Your Protection mode is <strong>%s network-wide</strong>.', 'help', MS_TEXT_DOMAIN), '<i class="wpmui-fa wpmui-fa-globe"></i>');
            } else {
                printf('<br />' . _x('Your Protection covers <strong>%s only this site</strong>.', 'help', MS_TEXT_DOMAIN), '<i class="wpmui-fa wpmui-fa-home"></i>');
            }
        }
        $admin_cap = MS_Plugin::instance()->controller->capability;
        if ($admin_cap) {
            printf('<br />' . _x('All users with capability <strong>%s</strong> are M2 Admin-users.', 'help', MS_TEXT_DOMAIN), $admin_cap);
        } else {
            printf('<br />' . _x('Only the <strong>Network-Admin</strong> can manage M2.', 'help', MS_TEXT_DOMAIN));
        }
        if (defined('MS_STOP_EMAILS') && MS_STOP_EMAILS) {
            printf('<br />' . _x('Currently M2 is configured to <strong>not send</strong> any emails.', 'help', MS_TEXT_DOMAIN));
        }
        if (defined('MS_LOCK_SUBSCRIPTIONS') && MS_LOCK_SUBSCRIPTIONS) {
            printf('<br />' . _x('Currently M2 is configured <strong>not expire/change</strong> any subscription status.', 'help', MS_TEXT_DOMAIN));
        }
        ?>
		</div>
		<?php 
        MS_Helper_Html::html_separator();
        ?>
		<h2>
			<?php 
        _ex('Plugin menu', 'help', MS_TEXT_DOMAIN);
        ?>
		</h2>
		<table cellspacing="0" cellpadding="4" border="0" width="100%">
			<tr>
				<td>
					<span class="top-menu">
					<div class="menu-image dashicons dashicons-lock"></div>
					<?php 
        _e('Membership 2', MS_TEXT_DOMAIN);
        ?>
					</span>
				</td>
				<td></td>
			</tr>
			<tr class="alternate">
				<td><span><?php 
        _e('Memberships', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Create and manage Membership-Plans that users can sign up for', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr>
				<td><span><?php 
        _e('Protection Rules', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Set the protection options, i.e. which pages are protected by which membership', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr class="alternate">
				<td><span><?php 
        _e('All Members', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Lists all your WordPress users and allows you to manage their Memberships', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr>
				<td><span><?php 
        _e('Add Member', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Create a new WP User or edit subscriptions of an existing user', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr class="alternate">
				<td><span><?php 
        _e('Billing', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Manage sent invoices, including details such as the payment status. <em>Only visible when you have at least one paid membership</em>', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr>
				<td><span><?php 
        _e('Coupons', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Manage your discount coupons. <em>Requires Add-on "Coupons"</em>', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr class="alternate">
				<td><span><?php 
        _e('Invitation Codes', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Manage your invitation codes. <em>Requires Add-on "Invitation Codes"</em>', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr>
				<td><span><?php 
        _e('Add-ons', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Activate Add-ons', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
			<tr class="alternate">
				<td><span><?php 
        _e('Settings', MS_TEXT_DOMAIN);
        ?>
</span></td>
				<td><?php 
        _ex('Global plugin options, such as Membership pages, payment options and email templates', 'help', MS_TEXT_DOMAIN);
        ?>
</td>
			</tr>
		</table>
		<?php 
        return ob_get_clean();
    }
 /**
  * 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)
 {
     $defaults = apply_filters('ms_model_member_get_query_args_defaults', array('order' => 'DESC', 'orderby' => 'ID', 'number' => 20, 'offset' => 0, 'fields' => 'ID'));
     $args = lib2()->array->get($args);
     lib2()->array->equip($args, 'meta_query');
     if ('none' !== $args['meta_query']) {
         $args['meta_query'] = lib2()->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_NOT_MEMBERS:
                 /*
                  * This does a recursive call to first get all member IDs
                  */
                 $members = self::get_member_ids(null, self::SEARCH_ONLY_MEMBERS);
                 $args['exclude'] = $members;
                 break;
             case self::SEARCH_ALL_USERS:
             default:
                 break;
         }
     } else {
         unset($args['meta_query']);
     }
     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);
 }
    /**
     * Display the full settings form, used either by first membership
     * "completed" popup and also by the general settings tab.
     *
     * @since  1.0.0
     * @return string HTML code
     */
    public function html_full_form()
    {
        $fields = $this->prepare_fields();
        ob_start();
        ?>
		<div class="ms-setup-form">
			<?php 
        if (!MS_Plugin::is_network_wide()) {
            ?>
			<div class="ms-setup-nav">
				<div class="ms-title">
					<i class="ms-icon dashicons dashicons-menu"></i>
					<?php 
            _e('Please select pages you want to appear in your Navigation', MS_TEXT_DOMAIN);
            ?>
				</div>
				<div class="ms-description">
					<?php 
            printf(__('You can always change those later by going to %1$s in your admin sidebar.', MS_TEXT_DOMAIN), sprintf('<a href="%1$s" target="_blank">%2$s</a>', admin_url('nav-menus.php'), __('Appearance') . ' &raquo; ' . __('Menus')));
            ?>
				</div>
				<?php 
            echo '' . $this->show_menu_controls();
            ?>
			</div>
			<?php 
        } else {
            ?>
			<div class="ms-setup-site">
				<div class="ms-title">
					<i class="ms-icon dashicons dashicons-admin-network"></i>
					<?php 
            _e('Select the Site that hosts Membership 2 Pages', MS_TEXT_DOMAIN);
            ?>
				</div>
				<div class="ms-description">
					<?php 
            _e('When you change the site new Membership 2 Pages are created on the selected site. You can customize or replace these pages at any time.', MS_TEXT_DOMAIN);
            ?>
				</div>
				<?php 
            $site_options = MS_Helper_Settings::get_blogs();
            $site_fields = array(array('type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'id' => 'network_site', 'title' => __('Select the site that hosts the Membership 2 Pages', MS_TEXT_DOMAIN), 'value' => MS_Model_Pages::get_site_info('id'), 'field_options' => $site_options, 'class' => 'ms-site-options'), array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'action', 'value' => 'network_site'), array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => '_wpnonce', 'value' => wp_create_nonce('network_site')), array('type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => __('Save', MS_TEXT_DOMAIN)), array('type' => MS_Helper_Html::INPUT_TYPE_BUTTON, 'class' => 'ms-setup-pages-cancel', 'value' => __('Cancel', MS_TEXT_DOMAIN)));
            ?>
				<div class="ms-setup-pages-site">
					<div class="ms-setup-pages-site-info"><?php 
            printf(__('Membership pages are located on site %s', MS_TEXT_DOMAIN), '<strong>' . MS_Model_Pages::get_site_info('title') . '</strong>');
            ?>
					<a href="#change-site" class="ms-setup-pages-change-site"><?php 
            _e('Change site...', MS_TEXT_DOMAIN);
            ?>
</a></div>
					<div class="ms-setup-pages-site-form cf" style="display:none;">
						<?php 
            foreach ($site_fields as $field) {
                MS_Helper_Html::html_element($field);
            }
            ?>
					</div>
				</div>
			</div>
			<?php 
        }
        ?>
			<div class="ms-setup-pages">
				<div class="ms-title">
					<i class="ms-icon dashicons dashicons-admin-page"></i>
					<?php 
        _e('Membership 2 Pages', MS_TEXT_DOMAIN);
        ?>
				</div>
				<div class="ms-description">
					<?php 
        _e('Set Up Membership 2 Pages that will be displayed on your website.', MS_TEXT_DOMAIN);
        ?>
				</div>
				<?php 
        if (is_array($fields['pages'])) {
            $page_types = array_keys($fields['pages']);
            $page_types_menu = array('memberships', 'register', 'account');
            $page_types_rest = array_diff($page_types, $page_types_menu);
            $groups = array('in-menu' => $page_types_menu, 'no-menu' => $page_types_rest);
            $pages_site_id = MS_Model_Pages::get_site_info('id');
            MS_Factory::select_blog($pages_site_id);
            foreach ($groups as $group_key => $group_items) {
                printf('<div class="ms-pages-group %1$s">', esc_attr($group_key));
                foreach ($group_items as $key) {
                    $field = $fields['pages'][$key];
                    ?>
							<div class="ms-settings-page-wrapper">
								<?php 
                    MS_Helper_Html::html_element($field);
                    ?>
								<div class="ms-action">
									<?php 
                    MS_Helper_Html::html_link(array('id' => 'url_page_' . $field['value'], 'url' => '', 'value' => __('View Page', MS_TEXT_DOMAIN), 'target' => '_blank', 'data_ms' => array('base' => get_home_url($pages_site_id, 'index.php?page_id='))));
                    ?>
									<span> | </span>
									<?php 
                    MS_Helper_Html::html_link(array('id' => 'edit_url_page_' . $field['value'], 'url' => '', 'value' => __('Edit Page', MS_TEXT_DOMAIN), 'target' => '_blank', 'data_ms' => array('base' => get_admin_url($pages_site_id, 'post.php?action=edit&post='))));
                    ?>
								</div>
							</div>
							<?php 
                }
                echo '</div>';
            }
        } else {
            echo $fields['pages'];
        }
        MS_Factory::revert_blog();
        ?>
			</div>
		</div>
		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_view_settings_page_setup_to_html', $html);
    }
    /**
     * Displays a warning if network-wide protection is enabled for a large
     * network.
     *
     * @since  1.0.0
     */
    protected function check_network()
    {
        if (MS_Plugin::is_network_wide() && wp_is_large_network()) {
            ?>
			<div class="error below-h2">
			<p>
				<strong><?php 
            _e('Warning!', MS_TEXT_DOMAIN);
            ?>
</strong>
			</p>
			<p>
				<?php 
            _e('This network has a large number of sites. Some features of network protection might be slow or unavailable.', MS_TEXT_DOMAIN);
            ?>
			</p>
			</div>
		<?php 
        }
    }
 /**
  * Manages settings actions.
  *
  * Verifies GET and POST requests to manage settings.
  *
  * @since  1.0.0
  */
 public function admin_settings_manager()
 {
     MS_Helper_Settings::print_admin_message();
     $this->get_active_tab();
     $msg = 0;
     $redirect = false;
     if ($this->is_admin_user()) {
         if ($this->verify_nonce() || $this->verify_nonce(null, 'GET')) {
             /**
              * After verifying permissions those filters can be used by Add-ons
              * to process their own settings form.
              *
              * @since  1.0.1.0
              */
             do_action('ms_admin_settings_manager-' . $this->active_tab);
             do_action('ms_admin_settings_manager', $this->active_tab);
             switch ($this->active_tab) {
                 case self::TAB_GENERAL:
                     lib3()->array->equip_request('action', 'network_site');
                     $action = $_REQUEST['action'];
                     $redirect = esc_url_raw(remove_query_arg(array('msg' => $msg)));
                     // See if we change settings for the network-wide mode.
                     if (MS_Plugin::is_network_wide()) {
                         $new_site_id = intval($_REQUEST['network_site']);
                         if ('network_site' == $action && !empty($new_site_id)) {
                             $old_site_id = MS_Model_Pages::get_setting('site_id');
                             if ($old_site_id != $new_site_id) {
                                 MS_Model_Pages::set_setting('site_id', $new_site_id);
                                 $msg = MS_Helper_Settings::SETTINGS_MSG_SITE_UPDATED;
                                 $redirect = esc_url_raw(add_query_arg(array('msg' => $msg)));
                             }
                         }
                     }
                     break;
                 case self::TAB_IMPORT:
                     $tool = MS_Factory::create('MS_Controller_Import');
                     // Output is passed to the view via self::_message()
                     $tool->process();
                     break;
                 case self::TAB_PAYMENT:
                 case self::TAB_MESSAGES:
                     break;
                 default:
                     break;
             }
         }
     }
     if ($redirect) {
         wp_safe_redirect($redirect);
         exit;
     }
 }
 /**
  * Returns the current menu state: If a specific page is added to the menu,
  * this state is saved in the settings. So when the user removes a menu item
  * manually we still have the "inserted" flag in DB.
  *
  * We do this, because the menu items are added to all existing nav menus
  * and the user might remove them from one nav menu but not from all...
  *
  * @since  1.0.0
  * @param  string $page_type
  * @return bool
  */
 public static function has_menu($page_type)
 {
     $state = false;
     if (!MS_Plugin::is_network_wide()) {
         if (self::is_valid_type($page_type)) {
             $state = self::get_setting('has_nav_' . $page_type);
             $state = lib2()->is_true($state);
         }
     }
     return $state;
 }
 /**
  * Creates a new WordPress menu and adds all top level pages to this menu.
  *
  * @since  1.0.0
  */
 public static function create_default_menu()
 {
     if (MS_Plugin::is_network_wide()) {
         return;
     }
     $menu_id = wp_create_nav_menu(__('Default Menu', MS_TEXT_DOMAIN));
     if (!is_numeric($menu_id) || $menu_id <= 0) {
         return;
     }
     // Use the new menu in the menu-location of the theme.
     $locations = get_theme_mod('nav_menu_locations');
     if (is_array($locations) && count($locations) > 0) {
         reset($locations);
         $first = key($locations);
         $locations[$first] = $menu_id;
         set_theme_mod('nav_menu_locations', $locations);
     }
     // Enable the Auto-Add-New-Pages option.
     // Code snippet from wp-admin/includes/nav-menu.php
     $nav_menu_option = (array) get_option('nav_menu_options');
     if (!isset($nav_menu_option['auto_add'])) {
         $nav_menu_option['auto_add'] = array();
     }
     if (!in_array($menu_id, $nav_menu_option['auto_add'])) {
         $nav_menu_option['auto_add'][] = $menu_id;
     }
     update_option('nav_menu_options', $nav_menu_option);
     // Get a list of all published top-level pages.
     $top_pages = get_pages(array('parent' => 0));
     // List of pages that should not be displayed in the menu.
     $skip_pages = array(self::MS_PAGE_PROTECTED_CONTENT, self::MS_PAGE_REG_COMPLETE);
     foreach ($top_pages as $page) {
         // Skip pages that should not appear in menu.
         $ms_type = self::is_membership_page($page->ID);
         if (in_array($ms_type, $skip_pages)) {
             continue;
         }
         // Add the page to our new menu!
         $item = array('menu-item-object-id' => $page->ID, 'menu-item-object' => $page->post_type, 'menu-item-type' => 'post_type', 'menu-item-status' => $page->post_status);
         wp_update_nav_menu_item($menu_id, 0, $item);
     }
 }
    /**
     * When network-wide protection is enabled then allow the user to choose the
     * source-site of the content.
     *
     * Protection options can only be changed on a site-by-site base. So if the
     * user has 3 sites he can protect all pages on all sites but has to select
     * each site individually here.
     *
     * @since  1.0.0
     */
    protected function site_filter()
    {
        if (!MS_Plugin::is_network_wide()) {
            return false;
        }
        $sites = MS_Helper_Settings::get_blogs();
        $site_options = array();
        $current_blog_id = MS_Factory::current_blog_id();
        $admin_script = 'admin.php?' . $_SERVER['QUERY_STRING'];
        foreach ($sites as $blog_id => $title) {
            $key = get_admin_url($blog_id, $admin_script);
            if ($current_blog_id == $blog_id) {
                $current_value = $key;
            }
            $site_options[$key] = $title;
        }
        $site_list = array('id' => 'select-site', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $current_value, 'field_options' => $site_options);
        ?>
		<div class="ms-tab-container">
			<label class="ms-tab-link" for="select-site">
			<?php 
        _e('Select Site', 'membership2');
        ?>
			</label>
		</div>
		<div>
			<?php 
        lib3()->html->element($site_list);
        ?>
		</div>
		<?php 
    }