PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

counting downloads

s2Member Plugin. A Membership plugin for WordPress®.

Re: counting downloads

Postby Jason Caldwell » December 2nd, 2011, 5:05 pm

Thanks for the follow-up.

Right, Members at Level 4 would need access to Custom Capabilities in order to download files that are inside Custom Capability sub-directories. However, s2Member also supports Membership Level sub-directories. So files placed here would be available to Level 4 Members, and only to Level 4 Members.
/s2member-files/access-s2member-level4/file.mov


If all else fails, you might consider implementing your own counter using a Hook into s2Member's existing routines. For instance, you might do something like this.

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )
Code: Select all
<?php
add_action 
("ws_plugin__s2member_during_file_download_access", "my_s2_file_download_counts");
function my_s2_file_download_counts ($vars = array ())
    {
        if ($vars["serving"] && $vars["valid_file_download_key"] && ($file = $vars["req"]["file_download"]))
            if (is_user_logged_in () && is_object ($user = wp_get_current_user ()) && !empty ($user->ID) && ($user_id = $user->ID))
                {
                    $current_download_counts = (array)get_user_option ("my_s2_file_download_counts", $user_id);
                    update_user_option ($user_id, "my_s2_file_download_counts", (int)@$current_download_counts[$file] + 1);
                }
    }
function my_s2_file_download_count_for ($file = FALSE, $user_id = FALSE)
    {
        if ($file && ($user_id || (is_object ($user = wp_get_current_user ()) && !empty ($user->ID) && ($user_id = $user->ID))))
            {
                $current_download_counts = (array)get_user_option ("my_s2_file_download_counts", $user_id);
                return (int)@$current_download_counts[$file];
            }
        return /* Default return value. */ 0;
    }
?>

With this file in place, you now have your own API Function for download counts.
Code: Select all
<?php echo my_s2_file_download_count_for("access-s2member-ccap-post345/file.mov"); # Returns the count for this file, for the current User. ?>
Or, to find the count of a specific file, for a specific User's ID.
Code: Select all
<?php echo my_s2_file_download_count_for("access-s2member-ccap-post345/file.mov", ($user_id = 123)); # Returns the count for this file, for a specific User. ?>
s2-hacks.zip
(523 Bytes) Downloaded 17 times
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Previous

Return to s2Member Plugin

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 2 guests

cron