Download Monitor for Membership 2 Pro

With Membership 2 Pro is there plugin/hook that works as Download Monitor?

I.e. I'd like to for force downloads for protected media files and be able to see download count and by what user?

  • Nastia

    Hello Webprouk , I hope you are doing well today!

    Thank you for your question. I am afraid I am not a code expert so I have flagged a developer here to provide feedback.

    Once there is an update the developer or myself will post back in here.

    Please note that the developer response usually takes more time compare to the staff members. This is because they ae dealing with complex issues on a daily basis.

    Kind regards,

  • Lindeni Mahlalela

    Hello Webprouk,

    I hope you are doing great today and thank you for your patience so far. I am sorry for the delayed reply from our end.

    I have looked into the code of the Membership 2 Pro Plugin and found that there is no hook that was built specifically for this function but have found 2 action hooks that can help you achieve exactly what you want.

    There two hooks that run when serving a file as a download, one runs before the file is served and the other runs after the file is served. Here are the hooks:

    ms_rule_media_model_output_file_before //runs before serving file
    ms_rule_media_model_output_file_before //runs after serving file

    These can be used as follows:


    Both action hooks give you access to two parameters, the $file and the media addon class. I have written a basic mu plugin that you can modify to achieve your final goal. Copy the following code, paste in a new file and save it as .php file. Upload it to your worpress install '/wp-content/mu-plugins', so you may have something like:


    The file should have the following code:

    //do_action( 'ms_rule_media_model_output_file_before', $file, $this );
    //do_action( 'ms_rule_media_model_output_file_before', $file, $this );
    function monitor_ms2_file_download($file,$this){
    	if (is_file($file)){
    		$mime = wp_check_filetype( $file );
    		if ( empty( $mime['type'] ) && function_exists( 'mime_content_type' ) ) {
    			$mime['type'] = mime_content_type( $file );
    		if ( $mime['type'] ) {
    			$mimetype = $mime['type'];
    		} else {
    			$mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
    		$last_modified = date_i18n( 'D, d M Y H:i:s', filemtime( $file ) );
    		$modified_timestamp = strtotime( $last_modified );
    		$user = get_user_by('id',get_current_user_id());
    		$user_name = isset($user->login_name)?$user->login_name: "Guest";
    		$downloaded_file = array(
    				'last_modified' => $last_modified,
    				'type' => $mimetype
    		$files = get_option('ms2_downloaded_files');
    		$files_updated = array_merge($files,$downloaded_file);
    function ms2_download_monitor_admin_menus(){
    		__( 'M2 Downloads', 'downloadmonitor' ),
    		__( 'M2 Downloads', 'downloadmonitor' ),
    function m2_dm_render_main_admin_page(){
    	/**$demofiles = array(
    				'url'=>'url to image',
    		array('user'=>"Guest",'file'=>array('url'=>'url to image','last_modified'=>'2014-11-10','type'=>'Image/jpeg')),
    		array('user'=>"Samuel",'file'=>array('url'=>'url to image','last_modified'=>'2014-11-10','type'=>'Image/jpeg'))
    	$files = get_option('ms2_downloaded_files');
    	<h2>Download Monitor</h2>
    	if (count($files)>1){?>
    			<thead><tr><th>Username</th><th>File Info</th></tr></thead>
    				foreach ( $files as $file):
    				echo '<tr>
    					<td>'.$file['file']['url'].', Type: '.$file['file']['type'].', Modified: '.$file['file']['last_modified'].
    		echo "<p><strong>No files downloaded.</strong></p>";

    Once you have downloaded that file, go to your website dashboard and you will notice a new menu item called "M2 Downloads". You should see the download information on this page.

    Please note that the code is not final and may not work at first use, in this case you will have to modify the code yourself and make it do what you want to do.

    I hope this helps. Please let us know if you need any more help.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.