所以正如标题所说,我想扩展这个插件。
当有人通过下载管理器从网站下载时,插件会将事件记录在数据库中(表:prefix_ahm_download_stats)。
在DB的第二个表(表:prefix_table2)中记录事件对我来说很重要。文件plugins/download-manager/libs/class.DownloadStats.php负责这些操作。
<?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);
}
}问题不在于我不能创建一个类似的函数来将数据插入到另一个表中。问题是,当我上传插件时,我必须重新编辑文件。我试着自己写一个自定义的(外部)插件,但是我不能让它工作。
我对钩子和操作没有太多的经验,所以我认为这就是它不能工作的方式。
有没有人可以帮我扩展这个插件,这样当我更新它时,我就不会丢失我的代码了?
附注:当上面的代码被调用时,我想运行代码。
发布于 2019-07-08 17:58:00
我建议你从这里开始阅读Wordpress的“插件手册”:https://developer.wordpress.org/plugins/hooks/
https://stackoverflow.com/questions/56931971
复制相似问题