예제 #1
0
/**
 * User management panel
 *
 * Creates the bulk user management panel for the
 * Users > WP-Members page.
 *
 * @since 2.4
 */
function wpmem_admin_users()
{
    // define variables
    $col_phone = '';
    $col_country = '';
    $user_action_msg = '';
    // check to see if we need phone and country columns
    $wpmem_fields = get_option('wpmembers_fields');
    for ($row = 0; $row < count($wpmem_fields); $row++) {
        if ($wpmem_fields[$row][2] == 'country' && $wpmem_fields[$row][4] == 'y') {
            $col_country = true;
        }
        if ($wpmem_fields[$row][2] == 'phone1' && $wpmem_fields[$row][4] == 'y') {
            $col_phone = true;
        }
    }
    // should run other checks for expiration, activation, etc...
    // here is where we handle actions on the table...
    if ($_POST) {
        $action = isset($_POST['action']) ? $_POST['action'] : false;
        $users = isset($_POST['users']) ? $_POST['users'] : false;
        switch ($action) {
            case "activate":
                // find out if we need to set passwords
                $wpmem_fields = get_option('wpmembers_fields');
                $chk_pass = false;
                for ($row = 0; $row < count($wpmem_fields); $row++) {
                    if ($wpmem_fields[$row][2] == 'password') {
                        $chk_pass = true;
                    }
                }
                $x = 0;
                foreach ($users as $user) {
                    // check to see if the user is already activated, if not, activate
                    if (!get_user_meta($user, 'active', true)) {
                        wpmem_a_activate_user($user, $chk_pass);
                        $x++;
                    }
                }
                $user_action_msg = sprintf(__('%d users were activated.', 'wp-members'), $x);
                break;
            case "export":
                update_option('wpmembers_export', $users);
                $user_action_msg = sprintf(__('Users ready to export, %s click here %s to generate and download a CSV.', 'wp-members'), '<a href="' . WPMEM_DIR . '/admin/export.php" target="_blank">', '</a>');
                break;
        }
    }
    ?>

	<div class="wrap">

		<div id="icon-users" class="icon32"><br /></div>
		<h2><?php 
    _e('WP-Members Users', 'wp-members');
    ?>
  <a href="user-new.php" class="button add-new-h2"><?php 
    _e('Add New', 'wp-members');
    ?>
</a></h2>
		
	<?php 
    if ($user_action_msg) {
        ?>

		<div id="message" class="updated fade"><p><strong><?php 
        echo $user_action_msg;
        ?>
</strong></p></div>

	<?php 
    }
    ?>

		<form id="posts-filter" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
" method="post">
	
		<div class="filter">
			<ul class="subsubsub">
			
			<?php 
    // For now, I don't see a good way of working this for localization without a
    // huge amount of additional programming (like a multi-dimensional array)
    $show = $lcas = $curr = '';
    $tmp = array("All", "Not Active", "Trial", "Subscription", "Expired", "Not Exported");
    $show = isset($_GET['show']) ? $_GET['show'] : false;
    //if( isset( $_GET['show'] ) ) { $show = $_GET['show']; }
    for ($row = 0; $row < count($tmp); $row++) {
        $link = "users.php?page=wpmem-users";
        if ($row != 0) {
            $lcas = strtolower($tmp[$row]);
            $lcas = str_replace(" ", "", $lcas);
            $link .= "&#038;show=";
            $link .= $lcas;
            $curr = "";
            $curr = $show == $lcas ? ' class="current"' : '';
            //if( $show == $lcas ) { $curr = ' class="current"'; }
        } else {
            $curr = !$show ? ' class="current"' : '';
            //if( ! $show ) { $curr = ' class="current"'; }
        }
        $end = "";
        if ($row != 5) {
            $end = " |";
        }
        $echolink = true;
        if ($lcas == "notactive" && WPMEM_MOD_REG != 1) {
            $echolink = false;
        }
        if ($lcas == "trial" && WPMEM_USE_TRL != 1) {
            $echolink = false;
        }
        if (($lcas == "subscription" || $lcas == "expired") && WPMEM_USE_EXP != 1) {
            $echolink = false;
        }
        if ($echolink) {
            echo "<li><a href=\"{$link}\"{$curr}>{$tmp[$row]} <span class=\"count\"></span></a>{$end}</li>";
        }
    }
    ?>
			</ul>
		</div>

		<?php 
    // NOT YET...
    ?>
<!--
			<p class="search-box">
				<label class="screen-reader-text" for="user-search-input">Search Users:</label>
				<input type="text" id="user-search-input" name="usersearch" value="" />

				<input type="submit" value="Search Users" class="button" />
			</p>-->
	<?php 
    // done with the action items, now build the page
    $users_per_page = 10;
    // workout the different queries, etc...
    if (!$show) {
        $result = count_users();
        /* if( isset( $_REQUEST['paged'] ) ) { 
        				$paged = $_REQUEST['paged']; 
        			} else {
        				$paged = 1;
        			} */
        $paged = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : 1;
        $arr = array('show' => 'Total Users', 'show_num' => $users_per_page, 'total_users' => $result['total_users'], 'pages' => ceil($result['total_users'] / $users_per_page), 'paged' => $paged, 'link' => "users.php?page=wpmem-users");
        /* if( $paged == 1 ) { 
        				$offset = 0;
        			} else {
        				$offset = ( ( $arr['paged'] * $users_per_page ) - $users_per_page );
        			} */
        $offset = $paged == 1 ? 0 : $arr['paged'] * $users_per_page - $users_per_page;
        $args = array('offset' => $offset, 'number' => $users_per_page, 'fields' => 'all');
    } elseif ($show == 'notactive') {
        /*global $wpdb;
        		
        		$sql = "SELECT user_id FROM `wp32`.`wp_usermeta` WHERE meta_key = 'active' AND meta_value = 1;";
        		$user = $wpdb->get_results($sql, OBJECT);
        		
        		*/
    } elseif ($show == 'notexported') {
    }
    // http://codex.wordpress.org/Function_Reference/get_users
    $users = get_users($args);
    // get_users_of_blog();
    ?>
		


		<?php 
    wpmem_a_build_user_action(true, $arr);
    ?>

		<table class="widefat fixed" cellspacing="0">
			<thead>
			<?php 
    //$colspan = wpmem_a_build_user_tbl_head( $col_phone, $col_country );
    ?>
			<?php 
    $colspan = wpmem_a_build_user_tbl_head(array('phone' => $col_phone, 'country' => $col_country));
    ?>
			</thead>

			<tfoot>
			<?php 
    //$colspan = wpmem_a_build_user_tbl_head( $col_phone, $col_country );
    ?>
			<?php 
    $colspan = wpmem_a_build_user_tbl_head(array('phone' => $col_phone, 'country' => $col_country));
    ?>
			</tfoot>

			<tbody id="users" class="list:user user-list">

			<?php 
    if (WPMEM_DEBUG == true) {
        echo "<pre>\n";
        print_r($users);
        echo "</pre>\n";
    }
    $x = 0;
    $class = '';
    foreach ($users as $user) {
        // are we filtering results? (active, trials, etc...)
        $chk_show = false;
        switch ($show) {
            case "notactive":
                $chk_show = get_user_meta($user->ID, 'active', 'true') != 1 ? true : false;
                // if( get_user_meta( $user->ID, 'active', 'true' ) != 1 ) { $chk_show = true; }
                break;
            case "trial":
                $chk_exp_type = get_user_meta($user->ID, 'exp_type', 'true');
                $chk_show = $chk_exp_type == 'trial' ? true : false;
                // if( $chk_exp_type == 'trial' ) { $chk_show = true; }
                break;
            case "subscription":
                $chk_exp_type = get_user_meta($user->ID, 'exp_type', 'true');
                $chk_show = $chk_exp_type == 'subscription' ? true : false;
                // if( $chk_exp_type == 'subscription' ) { $chk_show = true; }
                break;
            case "expired":
                $chk_show = wpmem_chk_exp($user->ID) ? true : false;
                // if( wpmem_chk_exp( $user->ID ) ) { $chk_show = true; }
                break;
            case "notexported":
                $chk_show = get_user_meta($user->ID, 'exported', 'true') != 1 ? true : false;
                // if( get_user_meta( $user->ID, 'exported', 'true' ) != 1 ) { $chk_show = true; }
                break;
        }
        if (!$show || $chk_show == true) {
            $class = $class == 'alternate' ? '' : 'alternate';
            echo "<tr id=\"{$user->ID}\" class=\"{$class}\">\n";
            echo "\t<th scope='row' class='check-column'><input type='checkbox' name='users[]' id=\"user_{$user->ID}\" class='administrator' value=\"{$user->ID}\" /></th>\n";
            echo "\t<td class=\"username column-username\" nowrap>\n";
            echo "\t\t<strong><a href=\"user-edit.php?user_id={$user->ID}&#038;" . esc_attr(stripslashes($_SERVER['REQUEST_URI'])) . "\">" . $user->user_login . "</a></strong><br />\n";
            echo "\t</td>\n";
            echo "\t<td class=\"name column-name\" nowrap>" . htmlspecialchars(get_user_meta($user->ID, 'first_name', 'true')) . "&nbsp" . htmlspecialchars(get_user_meta($user->ID, 'last_name', 'true')) . "</td>\n";
            echo "\t<td class=\"email column-email\" nowrap><a href='mailto:" . $user->user_email . "' title='E-mail: " . $user->user_email . "'>" . $user->user_email . "</a></td>\n";
            if ($col_phone == true) {
                echo "\t<td class=\"email column-email\" nowrap>" . htmlspecialchars(get_user_meta($user->ID, 'phone1', 'true')) . "</td>\n";
            }
            if ($col_country == true) {
                echo "\t<td class=\"email column-email\" nowrap>" . htmlspecialchars(get_user_meta($user->ID, 'country', 'true')) . "</td>\n";
            }
            if (WPMEM_MOD_REG == 1) {
                echo "\t<td class=\"role column-role\" nowrap>";
                if (get_user_meta($user->ID, 'active', 'true') != 1) {
                    _e('No', 'wp-members');
                }
                echo "</td>\n";
            }
            if (WPMEM_USE_EXP == 1) {
                if (WPMEM_USE_TRL == 1) {
                    echo "\t<td class=\"email column-email\" nowrap>";
                    echo ucfirst(get_user_meta($user->ID, 'exp_type', true));
                    echo "</td>\n";
                }
                echo "\t<td class=\"email column-email\" nowrap>";
                echo get_user_meta($user->ID, 'expires', true);
                echo "</td>\n";
            }
            echo "</tr>\n";
            $x++;
        }
    }
    if ($x == 0) {
        echo "<tr><td colspan=\"{$colspan}\">";
        _e('No users matched your criteria', 'wp-members');
        echo "</td></tr>";
    }
    ?>

		</table>
		
		<?php 
    //wpmem_a_build_user_action( false, $arr );
    ?>

		</form>
		
		<br />
		<p>This button exports the full user list. To export based on other criteria, use the form above.</p>
		<form method="link" action="<?php 
    echo WPMEM_DIR . 'admin/export-full.php';
    ?>
">
			<input type="submit" class="button-secondary" value="Export All Users">
		</form>
	</div>
<?php 
}
예제 #2
0
/**
 * Executes shortcode for settings, register, and login pages
 *
 * @since 2.4 
 *
 * @param  array $attr page|status|field
 * @param  string $content
 * @return string returns the result of wpmem_do_sc_pages|wpmem_list_users|wpmem_sc_expmessage|$content
 */
function wpmem_shortcode($attr, $content = null)
{
    // handles the 'page' attribute
    if (isset($attr['page'])) {
        if ($attr['page'] == 'user-list') {
            return do_shortcode(wpmem_list_users($attr, $content));
        } else {
            return do_shortcode(wpmem_do_sc_pages($attr['page']));
        }
    }
    // handles the 'status' attribute
    if (isset($attr['status'])) {
        if ($attr['status'] == 'in' && is_user_logged_in()) {
            return do_shortcode($content);
        } elseif ($attr['status'] == 'out' && !is_user_logged_in()) {
            return do_shortcode($content);
        } elseif ($attr['status'] == 'sub' && is_user_logged_in()) {
            if (WPMEM_USE_EXP == 1) {
                if (!wpmem_chk_exp()) {
                    return do_shortcode($content);
                } elseif ($attr['msg'] == true) {
                    return do_shortcode(wpmem_sc_expmessage());
                }
            }
        }
    }
    // handles the 'field' attribute
    if (isset($attr['field'])) {
        global $user_ID;
        $user_info = get_userdata($user_ID);
        return htmlspecialchars($user_info->{$attr}['field']) . do_shortcode($content);
    }
}
 /**
  * Executes various shortcodes 
  *
  * This function executes shortcodes for pages (settings, register, login, user-list, 
  * and tos pages), as well as login status and field attributes when the wp-members tag
  * is used.  Also executes shortcodes for login status with the wpmem_logged_in tags 
  * and fields when the wpmem_field tags are used.
  *
  * @since 2.4 
  *
  * @param  array  $attr page|url|status|msg|field|id
  * @param  string $content
  * @param  string $tag
  * @return string returns the result of wpmem_do_sc_pages|wpmem_list_users|wpmem_sc_expmessage|$content
  */
 function wpmem_shortcode($attr, $content = null, $tag = 'wp-members')
 {
     // set all default attributes to false
     $defaults = array('page' => false, 'url' => false, 'status' => false, 'msg' => false, 'field' => false, 'id' => false);
     // merge defaults with $attr and extract
     extract(shortcode_atts($defaults, $attr, $tag));
     // handles the 'page' attribute
     if ($page) {
         if ($page == 'user-list') {
             //return ( function_exists( 'wpmem_list_users' ) ) ? do_shortcode( wpmem_list_users( $attr, $content ) ) : '';
             if (function_exists('wpmem_list_users')) {
                 $content = do_shortcode(wpmem_list_users($attr, $content));
             }
         } elseif ($page == 'tos') {
             return $url;
         } else {
             //return do_shortcode( wpmem_do_sc_pages( $page ) );
             $content = do_shortcode(wpmem_do_sc_pages($page));
         }
         // resolve any texturize issues...
         if (strstr($content, '[wpmem_txt]')) {
             // fix the wptexturize
             remove_filter('the_content', 'wpautop');
             remove_filter('the_content', 'wptexturize');
             add_filter('the_content', 'wpmem_texturize', 99);
         }
         return $content;
     }
     // handles the 'status' attribute
     if ($status || $tag == 'wpmem_logged_in') {
         $do_return = false;
         // if using the wpmem_logged_in tag with no attributes & the user is logged in
         if ($tag == 'wpmem_logged_in' && !$attr && is_user_logged_in()) {
             $do_return = true;
         }
         // if there is a status attribute of "in" and the user is logged in
         if ($status == 'in' && is_user_logged_in()) {
             $do_return = true;
         }
         // if there is a status attribute of "out" and the user is not logged in
         if ($status == 'out' && !is_user_logged_in()) {
             $do_return = true;
         }
         // if there is a status attribute of "sub" and the user is logged in
         if ($status == 'sub' && is_user_logged_in()) {
             if (WPMEM_USE_EXP == 1) {
                 if (!wpmem_chk_exp()) {
                     $do_return = true;
                 } elseif ($msg == true) {
                     $do_return = true;
                     $content = wpmem_sc_expmessage();
                 }
             }
         }
         // return content (or empty content) depending on the result of the above logic
         return $do_return ? do_shortcode($content) : '';
     }
     // handles the wpmem_logged_out tag with no attributes & the user is not logged in
     if ($tag == 'wpmem_logged_out' && !$attr && !is_user_logged_in()) {
         return do_shortcode($content);
     }
     // handles the 'field' attribute
     if ($field || $tag == 'wpmem_field') {
         if ($id) {
             // we are getting some other user
             if ($id == 'get') {
                 $the_user_ID = isset($_GET['uid']) ? $_GET['uid'] : '';
             } else {
                 $the_user_ID = $id;
             }
         } else {
             // get the current user
             $the_user_ID = get_current_user_id();
         }
         $user_info = get_userdata($the_user_ID);
         // @todo - check this change
         return $user_info ? htmlspecialchars($user_info->{$field}) . do_shortcode($content) : do_shortcode($content);
         // return ( $user_info ) ? htmlspecialchars( $user_info->$field ) . do_shortcode( $content ) : '';
     }
     // logout link shortcode
     if (is_user_logged_in() && $tag == 'wpmem_logout') {
         $link = $url ? wpmem_chk_qstr($url) . 'a=logout' : wpmem_chk_qstr(get_permalink()) . 'a=logout';
         $text = $content ? $content : __('Click here to log out.', 'wp-members');
         return do_shortcode("<a href=\"{$link}\">{$text}</a>");
     }
 }
예제 #4
0
/**
 * Handles the logged in status shortcodes.
 *
 * There are two shortcodes to display content based on a user being logged
 * in - [wp-members status=in] and [wpmem_logged_in] (status=in is a legacy
 * shortcode, but will still function). There are several attributes that
 * can be used with the shortcode: in|out, sub for subscription only info,
 * id, and role. IDs and roles can be comma separated values for multiple
 * users and roles. Additionally, status=out can be used to display content
 * only to logged out users or visitors.
 *
 * @since 3.0.0
 *
 * @global object $wpmem The WP_Members object.
 *
 * @param  array  $atts
 * @param  string $content
 * @param  string $tag
 * @return string $content
 */
function wpmem_sc_logged_in($atts, $content = null, $tag = 'wpmem_logged_in')
{
    global $wpmem;
    // Handles the 'status' attribute.
    if (isset($atts['status']) || $tag == 'wpmem_logged_in') {
        $do_return = false;
        // If there is a status attribute of "out" and the user is not logged in.
        $do_return = isset($atts['status']) && $atts['status'] == 'out' && !is_user_logged_in() ? true : $do_return;
        if (is_user_logged_in()) {
            // In case $current_user is not already global
            $current_user = wp_get_current_user();
            // If there is a status attribute of "in" and the user is logged in.
            $do_return = isset($atts['status']) && $atts['status'] == 'in' ? true : $do_return;
            // If using the wpmem_logged_in tag with no attributes & the user is logged in.
            $do_return = $tag == 'wpmem_logged_in' && !$atts ? true : $do_return;
            // If there is an "id" attribute and the user ID is in it.
            if (isset($atts['id'])) {
                $ids = explode(',', $atts['id']);
                foreach ($ids as $id) {
                    if (trim($id) == $current_user->ID) {
                        $do_return = true;
                    }
                }
            }
            // If there is a "role" attribute and the user has a matching role.
            if (isset($atts['role'])) {
                $roles = explode(',', $atts['role']);
                foreach ($roles as $role) {
                    if (in_array(trim($role), $current_user->roles)) {
                        $do_return = true;
                    }
                }
            }
            // If there is a status attribute of "sub" and the user is logged in.
            if (isset($atts['status']) && $atts['status'] == 'sub' && is_user_logged_in()) {
                if (defined('WPMEM_EXP_MODULE') && $wpmem->use_exp == 1) {
                    if (!wpmem_chk_exp()) {
                        $do_return = true;
                    } elseif ($atts['msg'] == true) {
                        $do_return = true;
                        $content = wpmem_sc_expmessage();
                    }
                }
            }
        }
        // Return content (or empty content) depending on the result of the above logic.
        return $do_return ? do_shortcode($content) : '';
    }
}