MyBB Community Forums

Full Version: Making a global template from plugin?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I from a plugin make a global template?
	// Insert Templates
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	$template = array(
		"title"		=> "TEMPLATE_NAME",
		"template"	=> 'TEMPLATE COPE GOES HERE',
		"sid"		=> -1
	);
	$db->insert_query("templates", $template);
Thanks a lot. How to remove it again when uninstalling?
	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='TEMPLATE_NAME'");
You don't need to require ./inc/adminfunctions_templates.php to do any of this. That file only contains the find_replace_templatesets() function and clearly that isn't needed here. It's completely unnecessary.

You will, however, need to put $db in the global scope to be able to do this. And although the $db->query method can be used to delete things from the database, $db->delete_query should always be preferred.