• So as the title says, i want to extend a plugin.
    when someone downloads from the site through 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.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Extend Plugin (Download Manager by W3 Eden)’ is closed to new replies.