MyBB Community Forums

Full Version: insert_warning()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

why hook is no between array and query but after update user? this solution is more problematic



function insert_warning()
{
global $db, $mybb, $plugins;

$warning = &$this->data;

$this->write_warning_data = array(
"uid" => (int)$warning['uid'],
"tid" => (int)$warning['type'],
"pid" => (int)$warning['pid'],
"title" => $db->escape_string($warning['title']),
"points" => (int)$warning['points'],
"dateline" => TIME_NOW,
"issuedby" => $mybb->user['uid'],
"expires" => (int)$warning['expires'],
"expired" => 0,
"revokereason" => '',
"notes" => $db->escape_string($warning['notes'])
);

$this->write_warning_data['wid'] = $db->insert_query("warnings", $this->write_warning_data);

$this->update_user();

$plugins->run_hooks("datahandler_warnings_insert_warning", $this);

return $this->write_warning_data;
}
The hooks is runned after the warning has been inserted and attribued to user, seems logical to me.
but it is problematic when we need add warnings to custom content

for ex in datahendler post this is better
(when we add new post)

// Insert the post.
			$this->post_insert_data = array(
				"tid" => (int)$post['tid'],
				"replyto" => (int)$post['replyto'],
				"fid" => (int)$post['fid'],
				"subject" => $db->escape_string($post['subject']),
				"icon" => (int)$post['icon'],
				"uid" => $post['uid'],
				"username" => $db->escape_string($post['username']),
				"dateline" => $post['dateline'],
				"message" => $db->escape_string($post['message']),
				"ipaddress" => $db->escape_binary($post['ipaddress']),
				"includesig" => $post['options']['signature'],
				"smilieoff" => $post['options']['disablesmilies'],
				"visible" => $visible
			);

			$plugins->run_hooks("datahandler_post_insert_post", $this);

			$this->pid = $db->insert_query("posts", $this->post_insert_data);