Example #1
0
/**
 * Adds user expiration to the user profile.
 *
 * @since 3.1.1
 *
 * @global object $wpmem
 * @param  int    $user_id
 */
function wpmem_profile_show_expiration($user_id)
{
    global $wpmem;
    /*
     * If using subscription model, show expiration.
     * If registration is moderated, this doesn't show 
     * if user is not active yet.
     */
    if (defined('WPMEM_EXP_MODULE') && $wpmem->use_exp == 1) {
        if ($wpmem->mod_reg == 1 && get_user_meta($user_id, 'active', true) == 1 || $wpmem->mod_reg != 1) {
            if (function_exists('wpmem_a_extenduser')) {
                wpmem_a_extenduser($user_id);
            }
        }
    }
}
/**
 * Add WP-Members fields to the WP user profile screen.
 *
 * @since 2.1
 *
 * @global array $current_screen The WordPress screen object
 * @global int   $user_ID The user ID
 */
function wpmem_admin_fields()
{
    global $current_screen, $user_ID, $wpmem;
    $user_id = $current_screen->id == 'profile' ? $user_ID : $_REQUEST['user_id'];
    ?>

	<h3><?php 
    /**
     * Filter the heading for additional profile fields.
     *
     * @since 2.8.2
     *
     * @param string The default additional fields heading.
     */
    echo apply_filters('wpmem_admin_profile_heading', __('WP-Members Additional Fields', 'wp-members'));
    ?>
</h3>   
 	<table class="form-table">
		<?php 
    // Get fields.
    $wpmem_fields = $wpmem->fields;
    // get_option( 'wpmembers_fields' );
    // Get excluded meta.
    $exclude = wpmem_get_excluded_meta('admin-profile');
    /**
     * Fires at the beginning of generating the WP-Members fields in the user profile.
     *
     * @since 2.9.3
     *
     * @param int   $user_id      The user's ID.
     * @param array $wpmem_fields The WP-Members fields.
     */
    do_action('wpmem_admin_before_profile', $user_id, $wpmem_fields);
    foreach ($wpmem_fields as $meta) {
        $valtochk = '';
        // Determine which fields to show in the additional fields area.
        $show = $meta[6] == 'n' && !in_array($meta[2], $exclude) ? true : false;
        $show = $meta[1] == 'TOS' && $meta[4] != 'y' ? null : $show;
        if ($show) {
            // Is the field required?
            $req = $meta[5] == 'y' ? ' <span class="description">' . __('(required)') . '</span>' : '';
            $show_field = '
					<tr>
						<th><label>' . __($meta[1], 'wp-members') . $req . '</label></th>
						<td>';
            $val = htmlspecialchars(get_user_meta($user_id, $meta[2], true));
            if ($meta[3] == 'checkbox' || $meta[3] == 'select') {
                $valtochk = $val;
                $val = $meta[7];
            }
            $show_field .= wpmem_create_formfield($meta[2], $meta[3], $val, $valtochk) . '
						</td>
					</tr>';
            /**
             * Filter the profile field.
             * 
             * @since 2.8.2
             *
             * @param string $show_field The HTML string for the additional profile field.
             */
            echo apply_filters('wpmem_admin_profile_field', $show_field);
        }
    }
    // See if reg is moderated, and if the user has been activated.
    if ($wpmem->mod_reg == 1) {
        $user_active_flag = get_user_meta($user_id, 'active', true);
        switch ($user_active_flag) {
            case '':
                $label = __('Activate this user?', 'wp-members');
                $action = 1;
                break;
            case 0:
                $label = __('Reactivate this user?', 'wp-members');
                $action = 1;
                break;
            case 1:
                $label = __('Deactivate this user?', 'wp-members');
                $action = 0;
                break;
        }
        ?>

			<tr>
				<th><label><?php 
        echo $label;
        ?>
</label></th>
				<td><input id="activate_user" type="checkbox" class="input" name="activate_user" value="<?php 
        echo $action;
        ?>
" /></td>
			</tr>

		<?php 
    }
    /*
     * If using subscription model, show expiration.
     * If registration is moderated, this doesn't show 
     * if user is not active yet.
     */
    if (defined('WPMEM_EXP_MODULE') && $wpmem->use_exp == 1) {
        if ($wpmem->mod_reg == 1 && get_user_meta($user_id, 'active', true) == 1 || $wpmem->mod_reg != 1) {
            wpmem_a_extenduser($user_id);
        }
    }
    ?>
		<tr>
			<th><label><?php 
    _e('IP @ registration', 'wp-members');
    ?>
</label></th>
			<td><?php 
    echo get_user_meta($user_id, 'wpmem_reg_ip', true);
    ?>
</td>
		</tr>
		<?php 
    /**
     * Fires after generating the WP-Members fields in the user profile.
     *
     * @since 2.9.3
     *
     * @param int   $user_id      The user's ID.
     * @param array $wpmem_fields The WP-Members fields.
     */
    do_action('wpmem_admin_after_profile', $user_id, $wpmem_fields);
    ?>

	</table><?php 
}
/**
* add WP-Members fields to the WP user profile screen
*
* @since 2.1
*
* @uses apply_filters Calls wpmem_admin_profile_field
& @uses apply_filters Calls wpmem_admin_profile_heading
*
* @global array $current_screen The WordPress screen object
* @global int   $user_ID The user ID
*/
function wpmem_admin_fields()
{
    global $current_screen, $user_ID;
    $user_id = $current_screen->id == 'profile' ? $user_ID : $_REQUEST['user_id'];
    ?>

	<h3><?php 
    echo apply_filters('wpmem_admin_profile_heading', __('WP-Members Additional Fields', 'wp-members'));
    ?>
</h3>   
 	<table class="form-table">
		<?php 
    $wpmem_fields = get_option('wpmembers_fields');
    $valtochk = '';
    for ($row = 0; $row < count($wpmem_fields); $row++) {
        /** determine which fields to show in the additional fields area */
        $show = $wpmem_fields[$row][6] == 'n' && $wpmem_fields[$row][2] != 'password' ? true : false;
        $show = $wpmem_fields[$row][1] == 'TOS' && $wpmem_fields[$row][4] != 'y' ? null : $show;
        if ($show) {
            $show_field = '
					<tr>
						<th><label>' . $wpmem_fields[$row][1] . '</label></th>
						<td>';
            $val = htmlspecialchars(get_user_meta($user_id, $wpmem_fields[$row][2], 'true'));
            if ($wpmem_fields[$row][3] == 'checkbox' || $wpmem_fields[$row][3] == 'select') {
                $valtochk = $val;
                $val = $wpmem_fields[$row][7];
            }
            $show_field .= wpmem_create_formfield($wpmem_fields[$row][2], $wpmem_fields[$row][3], $val, $valtochk) . '
						</td>
					</tr>';
            $valtochk = '';
            // empty for the next field in the loop
            echo apply_filters('wpmem_admin_profile_field', $show_field);
        }
    }
    // see if reg is moderated, and if the user has been activated
    if (WPMEM_MOD_REG == 1) {
        $user_active_flag = get_user_meta($user_id, 'active', 'true');
        switch ($user_active_flag) {
            case '':
                $label = __('Activate this user?', 'wp-members');
                $action = 1;
                break;
            case 0:
                $label = __('Reactivate this user?', 'wp-members');
                $action = 1;
                break;
            case 1:
                $label = __('Deactivate this user?', 'wp-members');
                $action = 0;
                break;
        }
        ?>

			<tr>
				<th><label><?php 
        echo $label;
        ?>
</label></th>
				<td><input id="activate_user" type="checkbox" class="input" name="activate_user" value="<?php 
        echo $action;
        ?>
" /></td>
			</tr>

		<?php 
    }
    // if using subscription model, show expiration
    // if registration is moderated, this doesn't show if user is not active yet.
    if (WPMEM_USE_EXP == 1) {
        if (WPMEM_MOD_REG == 1 && get_user_meta($user_id, 'active', 'true') == 1 || WPMEM_MOD_REG != 1) {
            wpmem_a_extenduser($user_id);
        }
    }
    ?>
		<tr>
			<th><label><?php 
    _e('IP @ registration', 'wp-members');
    ?>
</label></th>
			<td><?php 
    echo get_user_meta($user_id, 'wpmem_reg_ip', 'true');
    ?>
</td>
		</tr>
	</table><?php 
}