Skip to content

Instantly share code, notes, and snippets.

@leefish
Forked from tommm/mybb_get-pmid.txt
Created April 11, 2014 15:59
Show Gist options
  • Save leefish/10480108 to your computer and use it in GitHub Desktop.
Save leefish/10480108 to your computer and use it in GitHub Desktop.
$plugins->add_hook('datahandler_pm_insert', 'pm_insert');
$plugins->add_hook('private_do_send_end', 'pm_private_end');
function pm_insert($handler)
{
global $cache;
static $last_uid;
if(!isset($cache->cache['pmcache']))
{
// Hijack the cache for our dastardly plan
$cache->cache['pmcache'] = array();
}
if(!empty($handler->pmid))
{
// Update the PMID for the last user
$cache->cache['pmcache'][$last_uid] = array('uid' => $last_uid, 'pmid' => $handler->pmid);
}
$last_uid = $handler->pm_insert_data['toid'];
}
function pm_private_end()
{
global $mybb, $pmhandler;
// pm_insert doesn't handle the last recipient but we still have the data; update it.
$pm = $pmhandler->pm_insert_data;
$pmcache = $mybb->cache->read('pmcache');
$pmcache[$pm['toid']] = array('user' => $pm['toid'], 'pmid' => $pmhandler->pmid);
// $pmcache now contains all recipients and their respective PMIDs
print_r($pmcache);
die;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment