WP-Members 3.1.1 is primarily a feature release continuing development objectives from the 3.1 project.
WP-Members 3.1.1
Home of WP-Members, The Original WordPress Membership Plugin
Chad Butler · ·
WP-Members 3.1.1 is primarily a feature release continuing development objectives from the 3.1 project.
Allows you to filter the settings for the user upload directory when using a file or image upload field.
The default directory will be /wpmembers/user_files/{user id}/ in your main uploads directory (usually /wp-content/uploads/). This is not secure from random sweeps of your possible directories. If uploaded files are more sensitive/personal in nature, consider other options such as obfuscation of the directory names by using randomized values. The examples below give some instruction on how to do this using the wpmem_user_upload_dir filter.
$args
(array) (required) An array of arguments that make up the user upload directory.
Defaults:
$args = array(
'user_id' => $user_id,
'wpmem_dir' => 'wpmembers/',
'user_dir' => 'user_files/' . $user_id,
);This filter can be used to make changes to the directory a user uploaded file will be stored in. One of the parameters in the array is the $user_id so you can change directories based on the user ID. The sub directories are option in a sense, but one is not used, you must return the array key with an empty value.
The wpmem_dir subdirectory should have a trailing slash, but not leading slash (i.e. $args['wpmem_dir'] should be “directory_name/” not “/directory_name”). The user_dir subdirctory should likewise not contain a leading slash. The final directory in the user_dir subdirectory should not have a trailing slash ( i.e. $args['user_dir'] should be “user_dir/some_directory/someother_sub” but not “/user_dir/some_directory/someother_sub/”)
/**
* This example makes a completely custom path for
* user file uploads based on the specific user ID.
*/
add_filter( 'wpmem_user_upload_dir', function( $args ) {
// Change default directory if user ID is "10"
if ( 10 == $args['user_id'] ) {
$args['wpmem_dir'] = 'special_dir/',
$args['user_dir'] = 'special_sub'
}
// Make sure to return $args.
return $args;
});If you wanted to create user upload directories that obfuscate the directory name by using a hash value, you could consider the following use of the wpmem_user_upload_dir filter:
/**
* Add a random hash to the user upload directory.
*
* Change the default name of the user upload directory.
* This example completely removes the user ID value from the
* directory name, leaving it as a completely random string.
*
* Change $hash_len to set the length. Example creates a random
* string 36 characters long.
*/
add_filter( 'wpmem_user_upload_dir', function( $args ) {
// How long of a hash?
$hash_len = 36;
// Check if user already has a directory hash.
$hash = get_user_meta( $args['user_id'], 'wpmem_file_dir_hash', true );
if ( ! $hash ) {
/*
* If there is no existing hash, we need to create one.
*
* To make sure it is unique without having to do a for/while loop
* while checking the db, we can use the user ID in the string.
* Since the random hash is already long, inserting the user ID
* does not degrade the randomness. Theoretically, one could just
* add the user ID without this step, but I like to have everything
* being the same length so that a one digit user ID results in the
* same directory name length as a four digit user ID.
*
* This example makes it user ID + hash. For example, where the
* user ID is "234", the resulting direcotry would be like this:
*
* 234LXd2B8SE31u19TAS0SnwQW6ji
*
* For ultimate randomness in this example, consider switching to
* add the user ID to the end rather than the beginning. I did it
* at the beginning to allow a user with file system access to be
* able to browse the directory by user ID if they understood the
* directory name construction being done here.
*/
$uid_len = strlen( $args['user_id'] );
$hash = $args['user_id'] . wp_generate_password( ($hash_len-$uid_len), false, false );
update_user_meta( $args['user_id'], 'wpmem_file_dir_hash', $hash );
}
$args['user_dir'] = $hash;
return $args;
});Added in version 3.1.0
wpmem_user_upload_dir is located in includes/class-wp-members-forms.php
Filters the links array of the logged in state for WP-Members special pages (login, register, user profile). This filter comes before wpmem_{$page}_links and allows you much more control over the elements that are in that HTML output.
{$page} can be the following:
$arr
(array) (required) An array of information for the links displayed when logged in:
The following example uses the {register} tag (so wpmem_register_links_args) to customize the links display of the logged in state of the [wpmem_form register] shortcode:
add_filter( 'wpmem_register_links_args', function( $args ) {
// Change link #2. (Note PHP arrays begin at 0)
$args['rows'][1] = '<li><a href=' . home_url( 'my-page' ) . '>Enter the members area</a></li>';
// Add another link.
$args['rows'][] = '<li><a href=' . home_url( 'some-page' ) . '>My Extra Link</a></li>';
return $args;
});The array this filter handles is used to assemble a string of HTML for the logged in state of various pages (profile|register|login). This filter makes it easy to target specific parts of HTML so you can more easily change content, HTML tags, or the attributes of various tags (such as classes and IDs). The assembled HTML can be filtered later as a single string using the following (depending on the specific page/$tag):
wpmem_{$page}_links_args is located in /includes/class-wp-members-shortcodes.php.
Chad Butler · ·
WP User Avatar is a popular choice for allowing users to upload and use a custom avatar instead of gravatar that is integrated in WordPress. This post describes a nicely integrated process for a user to update their avatar on the WP-Members user profile screen.
This code snippet will add a link to the WP-Members user profile update screen to update the user’s avatar, and will set up a custom screen for avatar update screen.
The snippet can be used “cut-and-paste” but also has some elements that could be customized. Additionally, the features of the WP User Avatar front end process could have some CSS applied for theme integration. The screenshot here is a demo site using Twenty Fourteen, so colors and buttons will look different for you.
Note: you must also have WP User Avatar installed for this to work. Continue Reading →
Chad Butler · ·
WP-Members 3.1 contains some long awaited features, some fixes, and some improvements.
There are no changes to the database with this update so if you are currently at 3.0 or higher, you should be able to roll back without difficulty. (If you are using a version earlier than 3.0, there are changes from 2.x to 3.x that will be implemented in this update that would affect rolling back to 2.x. If that’s the case for you, you should test the update on a development system prior to upgrading.)
This version is currently available on GitHub as version 3.0.10. There will be no official 3.0.10 release on wordpress.org – this is merely a transitional release tag for building and testing leading into the official 3.1.0 release. The 3.0.10 is packaged and available for testing. The full production release of 3.1.0 will be available soon.
Here is a list of new features, improvements, and fixes: Continue Reading →
Ready to get started?