Title: Extend Plugin
Last modified: July 8, 2019

---

# Extend Plugin

 *  [alexpap18](https://wordpress.org/support/users/alexpap18/)
 * (@alexpap18)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/extend-plugin/)
 * So as the title says, i want to extend the plugin.
    when someone downloads from
   the site through [Download Manager](https://wordpress.org/plugins/download-manager/),
   the plugin it logs the event at database (table: prefix_ahm_download_stats). 
   It’s important to me to log the event in a second table at DB (table: prefix_table2).
   The file plugins/download-manager/libs/class.DownloadStats.php is responsible
   for these actions.
 *     ```
       <?php
       /**
        * Class DoawnloadStats
        */
       namespace WPDM\libs;
   
       use WPDM\Session;
   
       class DownloadStats{
   
           function __construct(){
   
           }
   
           function newStat($pid, $uid, $oid){
               global $wpdb, $current_user;
               //if(isset($_SESSION['downloaded_'.$pid])) return;
               //if(isset($_COOKIE['downloaded_'.$pid])) return;
               if(Session::get('downloaded_'.$pid)) return;
               $ip = (get_option('__wpdm_noip') == 0)?$_SERVER['REMOTE_ADDR']:"";
               $wpdb->insert("{$wpdb->prefix}ahm_download_stats",array('pid'=>(int)$pid, 'uid'=>(int)$uid,'oid'=>$oid, 'year'=> date("Y"), 'month'=> date("m"), 'day'=> date("d"), 'timestamp'=> time(),'ip'=>"$ip"));
               update_post_meta($pid, '__wpdm_download_count',intval(get_post_meta($pid, '__wpdm_download_count', true))+1);
               if($oid!='' && class_exists('\WPDMPP\Libs\Order')){
                   $order = new \WPDMPP\Libs\Order();
                   $order->Update(array('download'=>1), $oid);
               }
   
               $udl = maybe_unserialize(get_post_meta($pid, "__wpdmx_user_download_count", true));
               if (is_user_logged_in()) {
                   $index = $current_user->ID;
               }
               else {
                   $index = str_replace(".", "_", $_SERVER['REMOTE_ADDR']);
               }
               $udl["{$index}"] = isset($udl["{$index}"])?(int)$udl["{$index}"]+1:1;
               update_post_meta($pid, '__wpdmx_user_download_count', $udl);
               //setcookie('downloaded_'.$pid,  $ip, 1800);
               if($ip == '') $ip = uniqid();
               Session::set('downloaded_'.$pid, $ip);
           }
       }
       ```
   
 * The problem isn’t that i can’t create a similar function to insert data to another
   table. The problem is when i upload the plugin i have to re-edit the file. I 
   tried to write a custom (external) plugin myself but i couldn’t make it to work.
   I don’t have many experience with hooks and actions so i think this is way it
   doesn’t work :p. Can anyone help me to extend the plugin so when i update it,
   i don’t lose my code?
    P.S. I want to run the code when the code above is being
   called.

The topic ‘Extend Plugin’ is closed to new replies.

 * ![](https://ps.w.org/download-manager/assets/icon-256x256.png?rev=1561688)
 * [Download Manager](https://wordpress.org/plugins/download-manager/)
 * [Support Threads](https://wordpress.org/support/plugin/download-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/download-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/download-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/download-manager/reviews/)

## Tags

 * [extend](https://wordpress.org/support/topic-tag/extend/)

 * 0 replies
 * 1 participant
 * Last reply from: [alexpap18](https://wordpress.org/support/users/alexpap18/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/extend-plugin/)
 * Status: not resolved