Exemplo n.º 1
0
 function __construct()
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     add_action('plugins_loaded', array(&$this, 'load_textdomain'));
     // Set up Actions
     add_action('init', array(&$this, 'initialise_plugin'), 1);
     add_filter('query_vars', array(&$this, 'add_queryvars'));
     add_action('generate_rewrite_rules', array(&$this, 'add_rewrites'));
     // Add protection
     add_action('parse_request', array(&$this, 'initialise_membership_protection'), 2);
     // Download protection
     add_action('pre_get_posts', array(&$this, 'handle_download_protection'), 3);
     // Payment return
     add_action('pre_get_posts', array(&$this, 'handle_paymentgateways'), 1);
     // add feed protection
     add_filter('feed_link', array(&$this, 'add_feed_key'), 99, 2);
     // Register
     add_filter('register', array(&$this, 'override_register'));
     // Ultimate Facebook Compatibility
     add_filter('wdfb_registration_redirect_url', array(&$this, 'wdfb_registration_redirect_url'));
     // Level shortcodes filters
     add_filter('membership_level_shortcodes', array(&$this, 'build_level_shortcode_list'));
     add_filter('membership_not_level_shortcodes', array(&$this, 'build_not_level_shortcode_list'));
 }
Exemplo n.º 2
0
 function __construct($id = false, &$tips = false)
 {
     global $wpdb, $site_id;
     $this->db = $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     // If we're constructing before the tables exist, just exit.
     $table = membership_db_prefix($this->db, 'coupons');
     if ($this->db->get_var("SHOW TABLES LIKE '{$table}'") != $table) {
         return;
     }
     // If we are passing a non numeric ID we should try to find the ID by searching for the coupon name instead.
     if (!is_numeric($id)) {
         $search = $this->db->get_var($this->db->prepare("SELECT id FROM {$this->coupons} WHERE couponcode = %s", strtoupper($id)));
         if (!empty($search)) {
             $this->id = $search;
         }
     } else {
         $this->id = $id;
     }
     if ($tips !== false) {
         $this->_tips = $tips;
     }
     // Get the coupon for further usage
     $this->_coupon = $this->get_coupon();
 }
Exemplo n.º 3
0
 function __construct($id = false)
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     $this->id = $id;
 }
Exemplo n.º 4
0
 function __construct()
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     add_action('add_admin_bar_menus', array(&$this, 'add_admin_bar_items'));
     add_action('membership_dashboard_membershipuselevel', array(&$this, 'switch_membership_level'));
 }
Exemplo n.º 5
0
 function __construct()
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     // if logged in:
     add_action('wp_ajax_processwizard', array(&$this, 'ajax_process_wizard'));
     add_action('admin_init', array(&$this, 'process_visibility'));
 }
Exemplo n.º 6
0
 function __construct($id = false, $fullload = false, $loadtype = array('public', 'core'))
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     $this->id = $id;
     if ($fullload) {
         $this->load_rules($loadtype);
     }
 }
Exemplo n.º 7
0
 function M_Gateway()
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     // Actions and Filters
     add_filter('M_gateways_list', array(&$this, 'gateways_list'));
     add_action('membership_process_payment_return', array(&$this, 'process_payment_return'));
     add_action('membership_record_user_gateway', array(&$this, 'record_user_gateway'));
 }
Exemplo n.º 8
0
 function __construct()
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     // Set up Actions
     add_action('init', array(&$this, 'set_up_schedule'));
     add_filter('cron_schedules', array(&$this, 'add_time_period'));
     if (!$this->get_expiring_relationships_count() >= 50) {
         // Schedule for quarter hourly to get number of processing down a bit
         add_action('membership_process_quarterhourly_cron', array(&$this, 'transition_user_through_subscriptions'));
     } else {
         // We don't have that many, so let's process hourly instead
         add_action('membership_process_hourly_cron', array(&$this, 'transition_user_through_subscriptions'));
     }
 }
Exemplo n.º 9
0
 function __construct($id = false, &$tips = false)
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     // If we are passing a non numeric ID we should try to find the ID by searching for the coupon name instead.
     if (!is_numeric($id)) {
         $search = $this->db->get_var($this->db->prepare("SELECT * FROM {$this->coupons} WHERE `couponcode` = %s", $id));
         if (!empty($search)) {
             $this->id = $search;
         }
     } else {
         $this->id = $id;
     }
     if ($tips !== false) {
         $this->_tips = $tips;
     }
 }
Exemplo n.º 10
0
 public function __construct($id = false, $fullload = false, $loadtype = array('public', 'core'))
 {
     global $wpdb, $M_options;
     $this->id = $id;
     $this->db = $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     if (is_null($this->active)) {
         //only run if hasn't been run before
         //check if this level is active - if it isn't we don't want to load it's rules
         $this->active = (bool) $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT level_active\n\t\t\t\tFROM {$this->membership_levels}\n\t\t\t\tWHERE level_active = 1\n\t\t\t\t\tAND id = %d", $this->id));
     }
     $allow_page_cascade = isset($M_options['allow_page_rule_cascade']) ? $M_options['allow_page_rule_cascade'] : 'yes';
     $this->allow_page_cascade = 'yes' == $allow_page_cascade ? true : false;
     if ($fullload && $this->active) {
         $this->load_rules($loadtype);
     }
     add_action('remove_this_level_members', 'remove_level_members', 10, 1);
 }
Exemplo n.º 11
0
 function __construct()
 {
     global $nxtdb;
     $this->db =& $nxtdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     // Add administration actions
     add_action('init', array(&$this, 'initialise_plugin'), 1);
     // Add in admin area membership levels
     add_action('init', array(&$this, 'initialise_membership_protection'), 999);
     add_action('admin_menu', array(&$this, 'add_admin_menu'));
     add_action('plugins_loaded', array(&$this, 'load_textdomain'));
     // Header actions
     add_action('load-toplevel_page_membership', array(&$this, 'add_admin_header_membership'));
     add_action('load-membership_page_members', array(&$this, 'add_admin_header_members'));
     add_action('load-membership_page_membershiplevels', array(&$this, 'add_admin_header_membershiplevels'));
     add_action('load-membership_page_membershipsubs', array(&$this, 'add_admin_header_membershipsubs'));
     add_action('load-membership_page_membershipgateways', array(&$this, 'add_admin_header_membershipgateways'));
     add_action('load-membership_page_membershipoptions', array(&$this, 'add_admin_header_membershipoptions'));
     add_action('load-membership_page_membershipurlgroups', array(&$this, 'add_admin_header_membershipurlgroups'));
     add_action('load-membership_page_membershippings', array(&$this, 'add_admin_header_membershippings'));
     add_action('load-users_page_membershipuser', array(&$this, 'add_admin_header_membershipuser'));
     add_filter('membership_level_sections', array(&$this, 'default_membership_sections'));
     // Media management additional fields
     add_filter('attachment_fields_to_edit', array(&$this, 'add_media_protection_settings'), 99, 2);
     add_filter('attachment_fields_to_save', array(&$this, 'save_media_protection_settings'), 99, 2);
     // rewrites
     add_action('generate_rewrite_rules', array(&$this, 'add_rewrites'));
     add_filter('query_vars', array(&$this, 'add_queryvars'));
     // profile field for feeds
     add_action('show_user_profile', array(&$this, 'add_profile_feed_key'));
     // Pings
     add_action('membership_subscription_form_after_levels', array(&$this, 'show_subscription_ping_information'));
     add_action('membership_subscription_add', array(&$this, 'update_subscription_ping_information'));
     add_action('membership_subscription_update', array(&$this, 'update_subscription_ping_information'));
     add_action('membership_level_form_after_rules', array(&$this, 'show_level_ping_information'));
     add_action('membership_level_add', array(&$this, 'update_level_ping_information'));
     add_action('membership_level_update', array(&$this, 'update_level_ping_information'));
 }
Exemplo n.º 12
0
 function __construct()
 {
     global $nxtdb;
     $this->db =& $nxtdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     add_action('plugins_loaded', array(&$this, 'load_textdomain'));
     // Set up Actions
     add_action('init', array(&$this, 'initialise_plugin'), 1);
     add_filter('query_vars', array(&$this, 'add_queryvars'));
     add_action('generate_rewrite_rules', array(&$this, 'add_rewrites'));
     // Add protection
     add_action('parse_request', array(&$this, 'initialise_membership_protection'), 2);
     // Download protection
     add_action('pre_get_posts', array(&$this, 'handle_download_protection'), 3);
     // Payment return
     add_action('pre_get_posts', array(&$this, 'handle_paymentgateways'), 1);
     // add feed protection
     add_filter('feed_link', array(&$this, 'add_feed_key'), 99, 2);
     // Register
     add_filter('register', array(&$this, 'override_register'));
 }
Exemplo n.º 13
0
function membership_news_stream()
{
    global $wpdb;
    $table = membership_db_prefix($wpdb, 'membership_news');
    // Superfluous prepare, but do it anyway
    $news = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table} ORDER BY newsdate DESC LIMIT %d, %d", 0, 50));
    ?>

	<div class="postbox " id="dashboard_news">
		<h3 class="hndle"><span><?php 
    _e('News', 'membership');
    ?>
</span></h3>
		<div class="inside">
			<?php 
    if (!empty($news)) {
        foreach ($news as $key => $newsitem) {
            echo "<p id='newsitem-" . $newsitem->id . "'>";
            echo "[ ";
            echo date("Y-m-d : H:i", strtotime($newsitem->newsdate));
            echo " ] ";
            echo $newsitem->newsitem;
            echo "</p>";
        }
    } else {
        echo "<p>" . __('There will be some interesting news here when your site gets going.', 'membership') . "</p>";
    }
    ?>
			<br class="clear">
		</div>
	</div>

	<?php 
}
Exemplo n.º 14
0
function M_build_database_structure()
{
    global $wpdb;
    $bi = 'bigint(20)';
    $biu = 'bigint(20) unsigned';
    $bi11 = 'bigint(11)';
    $bi35 = 'bigint(35)';
    $i = 'int(11)';
    $v1 = 'varchar(1)';
    $v5 = 'varchar(5)';
    $v10 = 'varchar(10)';
    $v30 = 'varchar(30)';
    $v35 = 'varchar(35)';
    $v50 = 'varchar(50)';
    $v20 = 'varchar(20)';
    $v200 = 'varchar(200)';
    $v250 = 'varchar(250)';
    $t = 'text';
    $jd = 'date';
    $d = 'datetime';
    $ts = 'timestamp';
    $dc = 'decimal(11,2)';
    $structure = array(membership_db_prefix($wpdb, 'membership_levels') => array('id' => $bi, 'level_title' => $v250, 'level_slug' => $v250, 'level_active' => $i, 'level_count' => $bi), membership_db_prefix($wpdb, 'membership_relationships') => array('rel_id' => $bi, 'user_id' => $bi, 'sub_id' => $bi, 'level_id' => $bi, 'startdate' => $d, 'updateddate' => $d, 'expirydate' => $d, 'order_instance' => $bi, 'usinggateway' => $v50), membership_db_prefix($wpdb, 'membership_rules') => array('level_id' => $bi, 'rule_ive' => $v20, 'rule_area' => $v20, 'rule_value' => $t, 'rule_order' => $i), membership_db_prefix($wpdb, 'subscriptions') => array('id' => $bi, 'sub_name' => $v200, 'sub_active' => $i, 'sub_public' => $i, 'sub_count' => $bi, 'sub_description' => $t, 'sub_pricetext' => $v200), membership_db_prefix($wpdb, 'subscriptions_levels') => array('sub_id' => $bi, 'level_id' => $bi, 'level_period' => $i, 'sub_type' => $v20, 'level_price' => $dc, 'level_currency' => $v5, 'level_order' => $bi, 'level_period_unit' => $v1), membership_db_prefix($wpdb, 'subscription_transaction') => array('transaction_ID' => $biu, 'transaction_subscription_ID' => $bi, 'transaction_user_ID' => $bi, 'transaction_sub_ID' => $bi, 'transaction_paypal_ID' => $v30, 'transaction_payment_type' => $v20, 'transaction_stamp' => $bi35, 'transaction_total_amount' => $bi, 'transaction_currency' => $v35, 'transaction_duedate' => $jd, 'transaction_gateway' => $v50, 'transaction_note' => $t, 'transaction_expires' => $d), membership_db_prefix($wpdb, 'urlgroups') => array('id' => $bi, 'groupname' => $v250, 'groupurls' => $t, 'isregexp' => $i, 'stripquerystring' => $i), membership_db_prefix($wpdb, 'communications') => array('id' => $bi11, 'subject' => $v250, 'message' => $t, 'periodunit' => $i, 'periodtype' => $v5, 'periodprepost' => $v5, 'lastupdated' => $ts, 'active' => $i, 'periodstamp' => $bi), membership_db_prefix($wpdb, 'pings') => array('id' => $bi, 'pingname' => $v250, 'pingurl' => $v250, 'pinginfo' => $t, 'pingtype' => $v10), membership_db_prefix($wpdb, 'ping_history') => array('id' => $bi, 'ping_id' => $bi, 'ping_sent' => $ts, 'ping_info' => $t, 'ping_return' => $t), membership_db_prefix($wpdb, 'levelmeta') => array('id' => $bi, 'level_id' => $bi, 'meta_key' => $v250, 'meta_value' => $t, 'meta_stamp' => $ts), membership_db_prefix($wpdb, 'subscriptionmeta') => array('id' => $bi, 'sub_id' => $bi, 'meta_key' => $v250, 'meta_value' => $t, 'meta_stamp' => $ts), membership_db_prefix($wpdb, 'member_payments') => array('id' => $bi11, 'member_id' => $bi, 'sub_id' => $bi, 'level_id' => $bi, 'level_order' => $i, 'paymentmade' => $d, 'paymentexpires' => $d), membership_db_prefix($wpdb, 'coupons') => array('id' => $biu, 'site_id' => $bi, 'couponcode' => $v250, 'discount' => $dc, 'discount_type' => $v5, 'discount_currency' => $v5, 'coupon_startdate' => $d, 'coupon_enddate' => $d, 'coupon_sub_id' => $bi, 'coupon_uses' => $i, 'coupon_used' => $i, 'coupon_apply_to' => $v20));
    return $structure;
}
Exemplo n.º 15
0
 function prepare_query()
 {
     global $wpdb, $wp_version;
     $this->first_user = ($this->page - 1) * $this->users_per_page;
     $this->query_limit = $wpdb->prepare(" LIMIT %d, %d", $this->first_user, $this->users_per_page);
     $this->query_orderby = ' ORDER BY user_login';
     $search_sql = '';
     if ($this->search_term) {
         $searches = array();
         $search_sql = 'AND (';
         foreach (array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col) {
             $searches[] = $col . " LIKE '%{$this->search_term}%'";
         }
         $search_sql .= implode(' OR ', $searches);
         $search_sql .= ')';
     }
     // The following code changes in WP3 and above
     // We are on version 3.0 or above
     $this->query_from = " FROM {$wpdb->users}";
     $this->query_where = " WHERE 1=1 {$search_sql}";
     if ($this->role) {
         $this->query_from .= " INNER JOIN {$wpdb->usermeta} ON {$wpdb->users}.ID = {$wpdb->usermeta}.user_id";
         $this->query_where .= $wpdb->prepare(" AND {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities' AND {$wpdb->usermeta}.meta_value LIKE %s", '%' . $this->role . '%');
     } elseif (is_multisite()) {
         $level_key = $wpdb->prefix . 'capabilities';
         // wpmu site admins don't have user_levels
         $this->query_from .= ", {$wpdb->usermeta}";
         $this->query_where .= " AND {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$level_key}'";
     }
     if ($this->sub_id) {
         $sql = $wpdb->prepare("SELECT user_id FROM " . membership_db_prefix($wpdb, "membership_relationships") . " WHERE sub_id = %d", $this->sub_id);
         $subs = $wpdb->get_col($sql);
         if (!empty($subs)) {
             $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $subs) . ")";
             // wp 2.9.2 and lower
             $this->query_from_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $subs) . ")";
         } else {
             $this->query_where .= " AND {$wpdb->users}.ID IN (0)";
             // wp 2.9.2 and lower
             $this->query_from_where .= " AND {$wpdb->users}.ID IN (0)";
         }
     }
     if ($this->level_id) {
         $sql = $wpdb->prepare("SELECT user_id FROM " . membership_db_prefix($wpdb, "membership_relationships") . " WHERE level_id = %d", $this->level_id);
         $levels = $wpdb->get_col($sql);
         if (!empty($levels)) {
             $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $levels) . ")";
             // wp 2.9.2 and lower
             $this->query_from_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $levels) . ")";
         } else {
             $this->query_where .= " AND {$wpdb->users}.ID IN (0)";
             // wp 2.9.2 and lower
             $this->query_from_where .= " AND {$wpdb->users}.ID IN (0)";
         }
     }
     if ($this->active) {
         $sql = $wpdb->prepare("SELECT user_id FROM " . $wpdb->usermeta . " WHERE meta_key = '" . membership_db_prefix($wpdb, 'membership_active', false) . "' AND meta_value = 'no'");
         $actives = $wpdb->get_col($sql);
         if (!empty($actives)) {
             if ($this->active == 'yes') {
                 $this->query_where .= " AND {$wpdb->users}.ID NOT IN (" . implode(',', $actives) . ")";
                 // wp 2.9.2 and lower
                 $this->query_from_where .= " AND {$wpdb->users}.ID NOT IN (" . implode(',', $actives) . ")";
             } else {
                 // no
                 $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $actives) . ")";
                 // wp 2.9.2 and lower
                 $this->query_from_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $actives) . ")";
             }
         } else {
             if ($this->active == 'yes') {
                 $this->query_where .= " AND {$wpdb->users}.ID NOT IN (0)";
                 // wp 2.9.2 and lower
                 $this->query_from_where .= " AND {$wpdb->users}.ID NOT IN (0)";
             } else {
                 // no
                 $this->query_where .= " AND {$wpdb->users}.ID IN (0)";
                 // wp 2.9.2 and lower
                 $this->query_from_where .= " AND {$wpdb->users}.ID IN (0)";
             }
         }
     }
     do_action_ref_array('pre_user_search', array(&$this));
 }
Exemplo n.º 16
0
 function get_subscriptions()
 {
     global $wpdb;
     return $wpdb->get_results("SELECT * FROM " . membership_db_prefix($wpdb, 'subscriptions') . " WHERE sub_active = 1");
 }
Exemplo n.º 17
0
 function deactivate()
 {
     update_user_meta($this->ID, membership_db_prefix($this->db, 'membership_active', false), 'no');
 }
Exemplo n.º 18
0
function get_last_transaction_for_user_and_sub($user_id, $sub_id)
{
    global $wpdb;
    $sql = $wpdb->prepare("SELECT * FROM " . membership_db_prefix($wpdb, 'subscription_transaction') . " WHERE transaction_user_ID = %d and transaction_subscription_ID = %d ORDER BY transaction_stamp DESC LIMIT 0,1", $user_id, $sub_id);
    return $wpdb->get_row($sql);
}
Exemplo n.º 19
0
 /**
  * Get target groups
  **/
 function the_targets($single_list_echo = 1, $groups = 1, $roles = 1, $membership = 1)
 {
     global $wpdb;
     $targets = array();
     if ($groups) {
         $groups = $this->get_groups();
         foreach ($groups as $group) {
             $count = count($this->get_members_of_group($group['group_id'], '', 1));
             if ($count) {
                 $targets['groups']['name'] = __('eNewsletter Groups', 'email-newsletter');
                 $targets['groups'][] = '<label><input type="checkbox" name="target[groups][]" value="' . $group['group_id'] . '"> ' . $group['group_name'] . ' (' . $count . ')</input></label>';
             }
         }
     }
     if ($membership) {
         if (class_exists('MS_Plugin')) {
             // Support for the Membership 2 plugin.
             $api = MS_Plugin::$api;
             $memberships = $api->list_memberships();
             if (count($memberships)) {
                 $targets['m2'] = array();
                 $targets['m2']['name'] = __('Membership 2 Subscribers', 'email-newsletter');
                 foreach ($memberships as $membership) {
                     $count = $this->get_members_of_membership2($membership->id, 1);
                     $targets['m2'][] = sprintf('<label><input type="checkbox" name="target[m2][]" value="%2$s" /> %1$s (%3$s)</label>', $membership->name, $membership->id, $count);
                 }
             }
         } elseif (function_exists('membership_db_prefix')) {
             // Support for old Membership1 plugin (deprecated).
             $prefix = membership_db_prefix($wpdb, 'membership_levels');
             $membership_levels = $wpdb->get_results("SELECT * FROM {$prefix} WHERE level_active = 1", "ARRAY_A");
             foreach ($membership_levels as $membership_level) {
                 $count = $this->get_members_of_membership($membership_level, 1);
                 if ($count) {
                     $targets['membership_levels']['name'] = __('Membership Plugin Levels', 'email-newsletter');
                     $targets['membership_levels'][] = '<label><input type="checkbox" name="target[membership_levels][]" value="' . $membership_level['id'] . '"> ' . $membership_level['level_title'] . ' (' . $count . ')</input></label>';
                 }
             }
         }
     }
     if (1 == $wpdb->blogid && class_exists('ProSites') && 0 == 1) {
         $psts_levels = get_site_option('psts_levels');
         foreach ($psts_levels as $psts_level_id => $psts_level) {
             $targets['psts_levels'][] = '<label><input type="checkbox" name="target[prosite_levels][]" value="' . $psts_level_id . '"> ' . $psts_level['name'] . '</input></label>';
         }
     }
     if ($roles) {
         $roles = $this->get_roles();
         foreach ($roles as $role_id => $role) {
             $targets['roles']['name'] = __('WordPress User Roles', 'email-newsletter');
             $targets['roles'][] = '<label><input type="checkbox" name="target[roles][]" value="' . $role_id . '"> ' . $role['name'] . '</input></label>';
         }
     }
     if (1 == $wpdb->blogid && function_exists('is_multisite') && is_multisite()) {
         $count = $this->get_global_wp_user_ids();
         $count = count($count);
         if ($count) {
             $targets['site_admins'][] = '<label><input type="checkbox" name="target[site_admins]" value="yes"> <strong>' . __('Admins of all sites', 'email-newsletter') . '</strong> (' . $count . ')</input></label>';
         }
     }
     if ($single_list_echo) {
         foreach ($targets as $type) {
             if (isset($type['name'])) {
                 $type['name'] = '<strong>' . $type['name'] . ':</strong>';
             }
             $targets_echo[] = implode('<br/>', $type);
         }
         echo implode('<br/><br/>', $targets_echo);
     } else {
         return $targets;
     }
 }
Exemplo n.º 20
0
 function get_groups()
 {
     global $wpdb;
     $sql = $wpdb->prepare("SELECT * FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname NOT LIKE (%s) ORDER BY id ASC", '\\_%');
     $results = $wpdb->get_results($sql);
     if (!empty($results)) {
         return $results;
     } else {
         return false;
     }
 }
Exemplo n.º 21
0
function membership_exclude_inactive_users($bp_user_query)
{
    global $wpdb;
    if (Membership_Plugin::is_enabled()) {
        $query = new WP_User_Query(array('meta_key' => membership_db_prefix($wpdb, 'membership_active', false), 'meta_value' => 'no', 'meta_compare' => '='));
        if ($query->get_total() > 0) {
            $bp_user_query->query_vars['exclude'] = wp_list_pluck($query->get_results(), 'ID');
        }
    }
}
 function __construct()
 {
     global $wpdb;
     $this->db =& $wpdb;
     foreach ($this->tables as $table) {
         $this->{$table} = membership_db_prefix($this->db, $table);
     }
     // Instantiate the tooltips class and set the icon
     $this->_tips = new WpmuDev_HelpTooltips();
     $this->_tips->set_icon_url(membership_url('membershipincludes/images/information.png'));
     // Initiate the wizard class
     $this->potter = new M_Wizard();
     // Add administration actions
     add_action('init', array(&$this, 'initialise_plugin'), 1);
     // Add in admin area membership levels
     add_action('init', array(&$this, 'initialise_membership_protection'), 999);
     if (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('membership/membershippremium.php') && (defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true)) {
         add_action('network_admin_menu', array(&$this, 'add_admin_menu'));
     } else {
         add_action('admin_menu', array(&$this, 'add_admin_menu'));
     }
     add_action('plugins_loaded', array(&$this, 'load_textdomain'));
     // Header actions for users page
     add_action('load-users.php', array(&$this, 'add_header_users_page'));
     // Custom header actions
     add_action('load-toplevel_page_membership', array(&$this, 'add_admin_header_membership'));
     add_action('load-membership_page_membershipmembers', array(&$this, 'add_admin_header_members'));
     add_action('load-membership_page_membershiplevels', array(&$this, 'add_admin_header_membershiplevels'));
     add_action('load-membership_page_membershipsubs', array(&$this, 'add_admin_header_membershipsubs'));
     add_action('load-membership_page_membershipcoupons', array(&$this, 'add_admin_header_membershipcoupons'));
     add_action('load-membership_page_membershipgateways', array(&$this, 'add_admin_header_membershipgateways'));
     add_action('load-membership_page_membershipoptions', array(&$this, 'add_admin_header_membershipoptions'));
     add_action('load-membership_page_membershipcommunication', array(&$this, 'add_admin_header_membershipcommunication'));
     add_action('load-membership_page_membershipurlgroups', array(&$this, 'add_admin_header_membershipurlgroups'));
     add_action('load-membership_page_membershippings', array(&$this, 'add_admin_header_membershippings'));
     add_action('load-users_page_membershipuser', array(&$this, 'add_admin_header_membershipuser'));
     add_filter('membership_level_sections', array(&$this, 'default_membership_sections'));
     // Media management additional fields
     add_filter('attachment_fields_to_edit', array(&$this, 'add_media_protection_settings'), 99, 2);
     add_filter('attachment_fields_to_save', array(&$this, 'save_media_protection_settings'), 99, 2);
     // rewrites
     add_action('generate_rewrite_rules', array(&$this, 'add_rewrites'));
     add_filter('query_vars', array(&$this, 'add_queryvars'));
     // profile field for feeds
     add_action('show_user_profile', array(&$this, 'add_profile_feed_key'));
     // Pings
     add_action('membership_subscription_form_after_levels', array(&$this, 'show_subscription_ping_information'));
     add_action('membership_subscription_add', array(&$this, 'update_subscription_ping_information'));
     add_action('membership_subscription_update', array(&$this, 'update_subscription_ping_information'));
     add_action('membership_level_form_after_rules', array(&$this, 'show_level_ping_information'));
     add_action('membership_level_add', array(&$this, 'update_level_ping_information'));
     add_action('membership_level_update', array(&$this, 'update_level_ping_information'));
     // Ajax calls have to go here because admin-ajax.php is an admin call even though we're calling it from the front end.
     add_action('wp_ajax_nopriv_buynow', array(&$this, 'popover_signup_form'));
     //login and register are no-priv only because, well they aren't logged in or registered
     add_action('wp_ajax_nopriv_register_user', array(&$this, 'popover_register_process'));
     add_action('wp_ajax_nopriv_login_user', array(&$this, 'popover_login_process'));
     // if logged in:
     add_action('wp_ajax_buynow', array(&$this, 'popover_sendpayment_form'));
     add_action('wp_ajax_extra_form', array(&$this, 'popover_extraform_process'));
     add_action('wp_ajax_register_user', array(&$this, 'popover_register_process'));
     add_action('wp_ajax_login_user', array(&$this, 'popover_login_process'));
     // Helper actions
     add_action('membership_activate_addon', array(&$this, 'activate_addon'), 10, 1);
     add_action('membership_deactivate_addon', array(&$this, 'deactivate_addon'), 10, 1);
     // Level shortcodes filters
     add_filter('membership_level_shortcodes', array(&$this, 'build_level_shortcode_list'));
     add_action('plugins_loaded', array(&$this, 'load_tutorial'), 11);
     //init tutorial after translation loaded
     // Add in the coupon class
     $this->_coupons = new M_Coupon();
 }
Exemplo n.º 23
0
 function prepare_query($query = array())
 {
     global $wpdb;
     $qv =& $this->query_vars;
     if (is_array($qv['fields'])) {
         $qv['fields'] = array_unique($qv['fields']);
         $this->query_fields = array();
         foreach ($qv['fields'] as $field) {
             $this->query_fields[] = $wpdb->users . '.' . esc_sql($field);
         }
         $this->query_fields = implode(',', $this->query_fields);
     } elseif ('all' == $qv['fields']) {
         $this->query_fields = "{$wpdb->users}.*";
     } else {
         $this->query_fields = "{$wpdb->users}.ID";
     }
     if ($qv['count_total']) {
         $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
     }
     $this->query_from = "FROM {$wpdb->users}";
     $this->query_where = "WHERE 1=1";
     // sorting
     if (in_array($qv['orderby'], array('nicename', 'email', 'url', 'registered'))) {
         $orderby = 'user_' . $qv['orderby'];
     } elseif (in_array($qv['orderby'], array('user_nicename', 'user_email', 'user_url', 'user_registered'))) {
         $orderby = $qv['orderby'];
     } elseif ('name' == $qv['orderby'] || 'display_name' == $qv['orderby']) {
         $orderby = 'display_name';
     } elseif ('post_count' == $qv['orderby']) {
         // todo: avoid the JOIN
         $where = get_posts_by_author_sql('post');
         $this->query_from .= " LEFT OUTER JOIN (\n\t\t\t\t\tSELECT post_author, COUNT(*) as post_count\n\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\t{$where}\n\t\t\t\t\tGROUP BY post_author\n\t\t\t\t) p ON ({$wpdb->users}.ID = p.post_author)\n\t\t\t\t";
         $orderby = 'post_count';
     } elseif ('ID' == $qv['orderby'] || 'id' == $qv['orderby']) {
         $orderby = 'ID';
     } else {
         $orderby = 'user_login';
     }
     $qv['order'] = strtoupper($qv['order']);
     if ('ASC' == $qv['order']) {
         $order = 'ASC';
     } else {
         $order = 'DESC';
     }
     $this->query_orderby = "ORDER BY {$orderby} {$order}";
     // limit
     if ($qv['number']) {
         if ($qv['offset']) {
             $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
         } else {
             $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
         }
     }
     $search = trim($qv['search']);
     if ($search) {
         $leading_wild = ltrim($search, '*') != $search;
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         $search_columns = array();
         if ($qv['search_columns']) {
             $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename', 'display_name'));
         }
         if (!$search_columns) {
             if (false !== strpos($search, '@')) {
                 $search_columns = array('user_email');
             } elseif (is_numeric($search)) {
                 $search_columns = array('user_login', 'ID');
             } elseif (preg_match('|^https?://|', $search) && !wp_is_large_network('users')) {
                 $search_columns = array('user_url');
             } else {
                 $search_columns = array('user_login', 'user_nicename');
             }
         }
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     $blog_id = absint($qv['blog_id']);
     if ('authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     $role = trim($qv['role']);
     if ($blog_id && ($role || is_multisite())) {
         $cap_meta_query = array();
         $cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
         if ($role) {
             $cap_meta_query['value'] = '"' . $role . '"';
             $cap_meta_query['compare'] = 'like';
         }
         $qv['meta_query'][] = $cap_meta_query;
     }
     $meta_query = new WP_Meta_Query();
     $meta_query->parse_query_vars($qv);
     if (!empty($meta_query->queries)) {
         $clauses = $meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ('OR' == $meta_query->relation) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     if (!empty($qv['include'])) {
         $ids = implode(',', wp_parse_id_list($qv['include']));
         $this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
     }
     if ($this->sub_id) {
         $sql = $wpdb->prepare("SELECT user_id FROM " . membership_db_prefix($wpdb, "membership_relationships") . " WHERE sub_id = %d", $this->sub_id);
         $subs = $wpdb->get_col($sql);
         if (empty($subs)) {
             $subs = array(0);
         }
         $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $subs) . ")";
     }
     if ($this->level_id) {
         $sql = $wpdb->prepare("SELECT user_id FROM " . membership_db_prefix($wpdb, "membership_relationships") . " WHERE level_id = %d", $this->level_id);
         $levels = $wpdb->get_col($sql);
         if (empty($levels)) {
             $levels = array(0);
         }
         $this->query_where .= " AND {$wpdb->users}.ID IN (" . implode(',', $levels) . ")";
     }
     if ($this->active) {
         $sql = $wpdb->prepare("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '" . membership_db_prefix($wpdb, 'membership_active', false) . "' AND meta_value = %s", 'no');
         $actives = $wpdb->get_col($sql);
         if (empty($actives)) {
             $actives = array(0);
         }
         $this->query_where .= $this->active == 'yes' ? " AND {$wpdb->users}.ID NOT IN (" . implode(',', $actives) . ")" : " AND {$wpdb->users}.ID IN (" . implode(',', $actives) . ")";
     }
     do_action_ref_array('pre_user_query', array($this));
 }
Exemplo n.º 24
0
 function get_group()
 {
     global $wpdb;
     $sql = $wpdb->prepare("SELECT id FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname = %s ORDER BY id DESC LIMIT 0,1", '_bpgroups-' . $this->level_id);
     $results = $wpdb->get_var($sql);
     if (!empty($results)) {
         return $results;
     } else {
         return false;
     }
 }
Exemplo n.º 25
0
 function get_groups()
 {
     global $nxtdb;
     $sql = $nxtdb->prepare("SELECT * FROM " . membership_db_prefix($nxtdb, 'urlgroups') . " ORDER BY id ASC");
     $results = $nxtdb->get_results($sql);
     if (!empty($results)) {
         return $results;
     } else {
         return false;
     }
 }
Exemplo n.º 26
0
 function get_subscriptions()
 {
     global $wpdb;
     $sql = $wpdb->prepare("SELECT * FROM " . membership_db_prefix($wpdb, 'subscriptions') . " WHERE sub_active = %d", 1);
     return $wpdb->get_results($sql);
 }
Exemplo n.º 27
0
 function get_membership_levels()
 {
     global $wpdb;
     $sql = $wpdb->prepare("SELECT * FROM " . membership_db_prefix($wpdb, 'membership_levels') . " WHERE level_active = 1;");
     return $wpdb->get_results($sql);
 }