本文整理汇总了PHP中MS_Model_Addon类的典型用法代码示例。如果您正苦于以下问题:PHP MS_Model_Addon类的具体用法?PHP MS_Model_Addon怎么用?PHP MS_Model_Addon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MS_Model_Addon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_enabled
/**
* Add a dependency check to this add-on: It can only be enabled when the
* parent Add-on "Media" is also enabled.
*
* Filter: 'ms_model_addon_is_enabled_addon_mediafiles'
*
* @since 1.0.0
* @internal
*
* @param bool $enabled State of this add-on
* (without considering the parent add-on)
* @return bool The actual state of this add-on.
*/
public function is_enabled($enabled)
{
if ($enabled) {
$enabled = MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MEDIA);
}
return $enabled;
}
示例2: is_active
/**
* Checks if the current Add-on is enabled
*
* @since 1.0.0
* @return bool
*/
public static function is_active()
{
if (!self::buddypress_active() && MS_Model_Addon::is_enabled(self::ID)) {
$model = MS_Factory::load('MS_Model_Addon');
$model->disable(self::ID);
}
return MS_Model_Addon::is_enabled(self::ID);
}
示例3: get_columns
/**
* Get list table columns.
*
* @since 1.0.0
*
* @return array {
* Returns array of $id => $title.
*
* @type string $id The list table column id.
* @type string $title The list table column title.
* }
*/
public function get_columns()
{
$columns = array('cb' => '<input type="checkbox" />', 'username' => __('Username', MS_TEXT_DOMAIN), 'email' => __('E-mail', MS_TEXT_DOMAIN), 'membership' => __('Membership', MS_TEXT_DOMAIN), 'infos' => ' ');
if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_TRIAL)) {
unset($columns['trial']);
}
return apply_filters('ms_helper_listtable_member_get_columns', $columns);
}
示例4: get_fields
/**
* Prepares fields for the edit form.
*
* @since 1.0.1.0
* @return array
*/
protected function get_fields()
{
$args = array('include_guest' => false);
$memberships = MS_Model_Membership::get_memberships($args);
$membership = $this->data['membership'];
$action = MS_Controller_Membership::AJAX_ACTION_UPDATE_MEMBERSHIP;
$nonce = wp_create_nonce($action);
$fields = array();
/*
* The value of "allow_val" is negated, because the radio-slider is
* reversed. So allow_val == false means that upgrading is allowed.
*
* This is just a UI tweak, the function ->update_allowed() returns true
* when upgrading is allowed.
*/
$list = array();
$list['guest'] = array('allow' => __('Users without Membership can subscribe', 'membership2'), 'allow_val' => !$membership->update_allowed('guest'));
foreach ($memberships as $item) {
if ($item->id == $membership->id) {
continue;
}
$list[$item->id] = array('allow' => sprintf(__('Members of %s can subscribe', 'membership2'), $item->get_name_tag()), 'allow_val' => !$membership->update_allowed($item->id));
if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS)) {
$list[$item->id]['replace'] = sprintf(__('Cancel %s on subscription', 'membership2'), $item->get_name_tag());
$list[$item->id]['replace_val'] = $membership->update_replaces($item->id);
}
}
foreach ($list as $id => $data) {
$fields[] = array('id' => 'deny_update[' . $id . ']', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => $data['allow'], 'value' => $data['allow_val'], 'before' => __('Allow', 'membership2'), 'after' => __('Deny', 'membership2'), 'class' => 'reverse', 'wrapper_class' => 'ms-block inline-label ms-allow', 'ajax_data' => array(1));
if (!empty($data['replace'])) {
if (MS_Addon_Prorate::is_active()) {
$after_label = __('Cancel and Pro-Rate', 'membership2');
} else {
$after_label = __('Cancel', 'membership2');
}
$fields[] = array('id' => 'replace_update[' . $id . ']', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'title' => $data['replace'], 'value' => $data['replace_val'], 'before' => __('Keep', 'membership2'), 'after' => $after_label, 'class' => 'reverse', 'wrapper_class' => 'ms-block inline-label ms-update-replace', 'ajax_data' => array(1));
}
$fields[] = array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR);
}
foreach ($fields as $key => $field) {
if (!empty($field['ajax_data'])) {
if (!empty($field['ajax_data']['action'])) {
continue;
}
if (!isset($fields[$key]['ajax_data']['field'])) {
$fields[$key]['ajax_data']['field'] = $fields[$key]['id'];
}
$fields[$key]['ajax_data']['_wpnonce'] = $nonce;
$fields[$key]['ajax_data']['action'] = $action;
$fields[$key]['ajax_data']['membership_id'] = $membership->id;
}
}
return $fields;
}
示例5: protect_content
/**
* Set initial protection.
*
* Add [ms-protect-content] shortcode to protect membership content inside post.
*
* @since 1.0.0
*/
public function protect_content()
{
parent::protect_content();
self::$membership_ids[] = $this->membership_id;
add_shortcode(self::PROTECT_CONTENT_SHORTCODE, array(__CLASS__, 'protect_content_shortcode'));
if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_SHORTCODE)) {
global $shortcode_tags;
$exclude = MS_Helper_Shortcode::get_membership_shortcodes();
foreach ($shortcode_tags as $shortcode => $callback_funciton) {
if (in_array($shortcode, $exclude)) {
continue;
}
if (!parent::has_access($shortcode)) {
$shortcode_tags[$shortcode] = array(&$this, 'do_protected_shortcode');
}
}
}
}
示例6: get_contents
/**
* Returns the contens of the dialog
*
* @since 1.0.0
*
* @return object
*/
public function get_contents($data)
{
$member = $data['model'];
$currency = MS_Plugin::instance()->settings->currency;
$show_trial = MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_TRIAL);
$all_subscriptions = MS_Model_Relationship::get_subscriptions(array('user_id' => $member->id, 'status' => 'all', 'meta_key' => 'expire_date', 'orderby' => 'meta_value', 'order' => 'DESC'));
// Prepare the form fields.
$inp_dialog = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'dialog', 'value' => 'View_Member_Dialog');
$inp_id = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'member_id', 'value' => $member->id);
$inp_nonce = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => '_wpnonce', 'value' => wp_create_nonce(self::ACTION_SAVE));
$inp_action = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'dialog_action', 'value' => self::ACTION_SAVE);
$inp_save = array('type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => __('Save', 'membership2'), 'class' => 'ms-submit-form', 'data' => array('form' => 'ms-edit-member'));
$inp_cancel = array('type' => MS_Helper_Html::INPUT_TYPE_BUTTON, 'value' => __('Close', 'membership2'), 'class' => 'close');
ob_start();
?>
<div>
<form class="ms-form wpmui-ajax-update ms-edit-member" data-wpmui-ajax="<?php
echo esc_attr('save');
?>
">
<div class="ms-form wpmui-form wpmui-grid-8">
<table class="widefat">
<thead>
<tr>
<th class="column-membership">
<?php
_e('Membership', 'membership2');
?>
</th>
<th class="column-status">
<?php
_e('Status', 'membership2');
?>
</th>
<th class="column-start">
<?php
_e('Subscribed on', 'membership2');
?>
</th>
<th class="column-expire">
<?php
_e('Expires on', 'membership2');
?>
</th>
<?php
if ($show_trial) {
?>
<th class="column-trialexpire">
<?php
_e('Trial until', 'membership2');
?>
</th>
<?php
}
?>
<th class="column-payments">
<?php
_e('Payments', 'membership2');
?>
</th>
</tr>
</thead>
<tbody>
<?php
foreach ($all_subscriptions as $subscription) {
$membership = $subscription->get_membership();
$payments = $subscription->get_payments();
$num_payments = count($payments);
$amount_payments = 0;
foreach ($payments as $payment) {
$amount_payments += $payment['amount'];
}
$subscription_info = array('subscription_id' => $subscription->id);
$update_info = array('subscription_id' => $subscription->id, 'statuscheck' => 'yes');
?>
<tr>
<td class="column-membership">
<?php
$membership->name_tag();
?>
</td>
<td class="column-status">
<?php
printf('<a href="#" data-ms-dialog="View_Member_Subscription" data-ms-data="%2$s">%1$s</a>
<a href="#" data-ms-dialog="View_Member_Subscription" data-ms-data="%3$s" title="%5$s">%4$s</a>', $subscription->status, esc_attr(json_encode($subscription_info)), esc_attr(json_encode($update_info)), '<i class="dashicons dashicons-update"></i>', __('Check and update subscription status', 'membership2'));
?>
</td>
<td class="column-start">
<?php
echo $subscription->start_date;
?>
</td>
<td class="column-expire">
//.........这里部分代码省略.........
示例7: add_rewrite_rules
/**
* Add rewrite rules.
*
* @since 1.0.0
*/
public function add_rewrite_rules()
{
$settings = MS_Factory::load('MS_Model_Settings');
// Gateway return - IPN.
add_rewrite_rule('ms-payment-return/(.+)/?', 'index.php?paymentgateway=$matches[1]', 'top');
// Alternative payment return URL: Membership
if (MS_Model_Import_Membership::did_import()) {
add_rewrite_rule('paymentreturn/(.+)/?', 'index.php?paymentgateway=$matches[1]', 'top');
}
// Media / download
$mmask = $settings->downloads['masked_url'];
$mtype = $settings->downloads['protection_type'];
if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MEDIA) && $mmask) {
if (MS_Rule_Media_Model::PROTECTION_TYPE_HYBRID == $mtype) {
add_rewrite_rule(sprintf('^%1$s/?$', $mmask), 'index.php?protectedfile=0', 'top');
} else {
add_rewrite_rule(sprintf('^%1$s/([^/]+)', $mmask), 'index.php?protectedfile=$matches[1]', 'top');
}
}
// End: Media / download
do_action('ms_plugin_add_rewrite_rules', $this);
}
示例8: has_rule_for_current_page
/**
* Checks if the current page is a special page and if the special page is
* protected by this rule.
*
* @since 1.0.0
*
* @return bool
*/
public function has_rule_for_current_page()
{
if (null === $this->_has_rule) {
if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_SPECIAL_PAGES)) {
$this->_has_rule = false;
} else {
$base = $this->get_membership()->get_base();
$base_rule = $base->get_rule($this->rule_type);
$this->_has_rule = $this->check_current_page($base_rule->rule_value);
}
}
return $this->_has_rule;
}
示例9: is_read_only
/**
* Determine whether Membership access can be changed or is read-only.
*
* @since 1.0.0
* @param string $post_type The post type of the post.
* @return bool
*/
public function is_read_only($post_type)
{
if ('post' == $post_type && !MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_POST_BY_POST)) {
$read_only = true;
} elseif ('attachment' == $post_type) {
$read_only = true;
} else {
$read_only = false;
}
return apply_filters('ms_controller_membership_metabox_is_read_only', $read_only, $post_type, $this);
}
示例10: membership_signup
/**
* Membership signup callback function.
*
* @since 1.0.0
*
* @param mixed[] $atts Shortcode attributes.
*/
public function membership_signup($atts)
{
MS_Helper_Shortcode::did_shortcode(MS_Helper_Shortcode::SCODE_SIGNUP);
$data = apply_filters('ms_controller_shortcode_membership_signup_atts', shortcode_atts(array(MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP . '_text' => __('Signup', 'membership2'), MS_Helper_Membership::MEMBERSHIP_ACTION_MOVE . '_text' => __('Change', 'membership2'), MS_Helper_Membership::MEMBERSHIP_ACTION_CANCEL . '_text' => __('Cancel', 'membership2'), MS_Helper_Membership::MEMBERSHIP_ACTION_RENEW . '_text' => __('Renew', 'membership2'), MS_Helper_Membership::MEMBERSHIP_ACTION_PAY . '_text' => __('Complete Payment', 'membership2')), $atts));
$member = MS_Model_Member::get_current_member();
$data['member'] = $member;
$data['subscriptions'] = array();
$exclude = array();
if ($member->is_valid()) {
// Get member's memberships, including pending relationships.
$data['subscriptions'] = MS_Model_Relationship::get_subscriptions(array('user_id' => $data['member']->id, 'status' => 'valid'));
foreach ($data['subscriptions'] as $key => $subscription) {
$exclude[] = $subscription->membership_id;
if (!$member->can_subscribe_to($subscription->membership_id)) {
unset($data['subscriptions'][$key]);
}
}
}
$memberships = MS_Model_Membership::get_signup_membership_list(null, $exclude);
$data['memberships'] = $memberships;
$move_from_ids = array();
// When Multiple memberships is not enabled, a member should move to another membership.
if (!MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS)) {
// Membership Relationship status which can move to another one
$valid_status = array(MS_Model_Relationship::STATUS_TRIAL, MS_Model_Relationship::STATUS_ACTIVE, MS_Model_Relationship::STATUS_EXPIRED);
foreach ($data['member']->subscriptions as $subscription) {
if ($subscription->is_system()) {
continue;
}
if (in_array($subscription->status, $valid_status)) {
$move_from_ids[] = $subscription->membership_id;
}
}
foreach ($data['memberships'] as $key => $membership) {
$data['memberships'][$key]->_move_from = $move_from_ids;
}
} else {
foreach ($data['memberships'] as $key => $membership) {
$move_from_ids = $member->cancel_ids_on_subscription($membership->id);
$data['memberships'][$key]->_move_from = $move_from_ids;
}
}
$data['action'] = MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP;
$data['step'] = MS_Controller_Frontend::STEP_PAYMENT_TABLE;
$view = MS_Factory::create('MS_View_Shortcode_MembershipSignup');
$view->data = apply_filters('ms_view_shortcode_membershipsignup_data', $data, $this);
return $view->to_html();
}
示例11: init
/**
* Initializes the Add-on. Always executed.
*
* @since 1.0.1.0
*/
public function init()
{
MS_Model_Addon::disable(self::ID);
}
示例12: is_active
/**
* Returns the active flag for a specific rule.
* State depends on Add-on
*
* @since 1.0.0
* @return bool
*/
public static function is_active()
{
return MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_POST_BY_POST);
}
示例13: is_active
/**
* Returns the active flag for a specific rule.
* State depends on Add-on
*
* @since 1.0.0
* @return bool
*/
public static function is_active()
{
$def = MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MEMBERCAPS);
$adv = MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_MEMBERCAPS_ADV);
return $def && !$adv;
}
示例14: has_access
/**
* Verify access to the current content.
*
* @since 1.0.0
*
* @param string $id The content id to verify access.
* @return bool|null True if has access, false otherwise.
* Null means: Rule not relevant for current page.
*/
public function has_access($id, $admin_has_access = true)
{
$has_access = null;
// Only verify permission if ruled by cpt post by post.
if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_CPT_POST_BY_POST)) {
if (empty($id)) {
$id = $this->get_current_post_id();
}
if (!empty($id)) {
$post_type = get_post_type($id);
$mspt = MS_Rule_CptGroup_Model::get_ms_post_types();
$cpt = MS_Rule_CptGroup_Model::get_custom_post_types();
if (in_array($post_type, $mspt)) {
// Always allow access to Membership2 pages.
$has_access = true;
} elseif (in_array($post_type, $cpt)) {
// Custom post type
$has_access = parent::has_access($id, $admin_has_access);
} else {
// WordPress core pages are ignored by this rule.
$has_access = null;
}
}
}
return apply_filters('ms_rule_custom_post_type_has_access', $has_access, $id, $this);
}
示例15: can_access_file
/**
* Checks if the current user can access the specified attachment.
*
* @since 1.0.0
* @param int $attachment_id
* @return bool
*/
public function can_access_file($attachment_id)
{
$access = false;
if (MS_Model_Member::is_normal_admin()) {
return true;
}
if (!MS_Model_Addon::is_enabled(MS_Addon_Mediafiles::ID)) {
/*
* Default protection mode:
* Protect Attachments based on the parent post.
*/
$parent_id = get_post_field('post_parent', $attachment_id);
if (!$parent_id) {
$access = true;
} else {
$member = MS_Model_Member::get_current_member();
foreach ($member->subscriptions as $subscription) {
$membership = $subscription->get_membership();
$access = $membership->has_access_to_post($parent_id);
if ($access) {
break;
}
}
}
} else {
/*
* Advanced protection mode (via Add-on):
* Each Attachment can be protected individually.
*/
$member = MS_Model_Member::get_current_member();
foreach ($member->subscriptions as $subscription) {
$rule = $subscription->get_membership()->get_rule(MS_Rule_Media::RULE_ID);
$access = $rule->has_access($attachment_id);
if ($access) {
break;
}
}
}
return apply_filters('ms_rule_media_can_access_file', $access, $attachment_id);
}