File download notification

    • # 1 month, 1 week ago

      Hello,

      I would like to know if there is a way to avoid the notification of the files downloaded by the client to the administrator when it is a set of files uploaded for the same post.

      Currently the administrator receives a notification for each downloaded file. This configuration is as follows: wp customer area->notifacations->individual notification settings->file downloaded->mode->only the first time

      You want to get: Notify the administrator only once when downloading the first file.

      Thank you very much,
      best regards

    • Thomas
      Keymaster
      # 1 month, 1 week ago

      Hello,

      Unfortunately, this is not doable for now. “File downloaded” notifications depend on each attachment from a private file post. So, if you created a private file post with 30 files attached, and select the option “only the first time”, you’ll actually get up to 30 notifications.

      However, WP Customer Area is almost always extendable and this should probably be done by code.

      If you have few development skills, you could try solving this programmatically. Else I would recommend hiring a webdeveloper from your region. This kind of customiztaion request goes outside of our support scope, so we won’t be able to help more than giving a few tips:

      • you could create a custom code snippet and create a function bound to “cuar/private-content/files/on-download”, with a higher priority, and increment the download count for the clicked attachment
      • this means the notifications will then not be sent because the count would be 2, instead of 1

      Note that this code isn’t tested, but just written as a guideline example. Please do no try that on your live site.

      <?php
      /**
       * Change the behavior of "only the first time" option (per attachment), to send only the first time per private file
       * post
       *
       * @param int                   $post_id
       * @param int                   $user_id The user who downloaded the file
       * @param CUAR_PrivateFileAddOn $pf_addon
       * @param string                $file_id
       */
      function wpca_send_file_download_notifications_once_per_post($post_id, $user_id, $pf_addon, $file_id)
      {
      	$notification_id = 'private-file-downloaded';
      	$notif_settings = $this->no_addon->settings()->get_notification_params($notification_id);
      
      	/*
      	 * if only the first time is activated,
      	 * - we'll loop through all attachments from the post if the current has its "download count" to 1 (= first time
      	 * downloading this attachment)
      	 * - If one of attachment already has a count >1, then we increment the download count of the file to 2
      	 * - next function sending emails will bypass sending notifications
      	 */
      	if ($notif_settings['mode'] == 'first')
      	{
      		$attachments = $pf_addon->get_attached_files($post_id);
      		$count = $pf_addon->get_file_download_count($post_id, $file_id, $user_id);
      		if($count === 1)
      		{
      			foreach ($attachments as $attachment_id => $attachment_data)
      			{
      				$count = $pf_addon->get_file_download_count($post_id, $attachment_id, $user_id);
      				if ($count >= 1)
      				{
      					$pf_addon->increment_file_download_count($post_id, $file_id, $user_id);
      					return;
      				}
      			}
      		}
      	}
      }
      
      add_action('cuar/private-content/files/on-download','wpca_send_file_download_notifications_once_per_post', 5, 4);
      add_action('cuar/private-content/files/on-view', 'wpca_send_file_download_notifications_once_per_post', 5, 4);

      I hope that helps.

      Regards.

      Want to help WP Customer Area? It only takes few seconds!
      Rate & review the plugin on WordPress.org 🙂

    • # 1 month, 1 week ago

      Hello,
      Thank you very much for your reply. It is very helpful the support you give.

      I will try to do what you are telling me by following the steps given.

      Best regards.

Viewing 2 reply threads

You must be logged in to reply to this topic.