本文整理汇总了PHP中MS_Plugin::is_network_wide方法的典型用法代码示例。如果您正苦于以下问题:PHP MS_Plugin::is_network_wide方法的具体用法?PHP MS_Plugin::is_network_wide怎么用?PHP MS_Plugin::is_network_wide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MS_Plugin
的用法示例。
在下文中一共展示了MS_Plugin::is_network_wide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: to_html
/**
* 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();
}
示例2: option_key
/**
* 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);
}
示例3: init
/**
* 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'));
}
示例4: get_admin_url
/**
* 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);
}
示例5: route_submenu_request
/**
* 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;
}
示例6: check_settings
/**
* 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;
}
示例7: html_full_form
/**
* 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') . ' » ' . __('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);
}
示例8: option_key
/**
* 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;
}
示例9: _post_type
/**
* 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;
}
示例10: revert_blog
/**
* 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();
}
}
}
示例11: get_query_args
/**
* 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);
}
示例12: is_current_site
/**
* 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;
}
示例13: check_network_setup
/**
* 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));
}
}
}
}
示例14: render_tab_general
/**
* 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
//.........这里部分代码省略.........
示例15: get_query_args
/**
* 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);
}