MyBB Community Forums

Full Version: Plugin repeated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am developing a plugin that counts the amount of threads a user has made. It works, however when I deactivate then reactivate it sort of "executes" the plugin again (see image).
[Image: croppedi.png]
I'm not sure why it does this, my code is as follows.
<?php 
$plugins->add_hook('member_profile_end', 'tcount');

function tcount_info()
{
	return array(
		"name"			=> "tcount",
		"description"	=> "Shows threads made in members profile.",
		"website"		=> "",
		"author"		=> "",
		"authorsite"	=> "",
		"version"		=> "1.0",
		"compatibility" => "16*"
	);
}

function tcount_activate()
{
	global $db, $mybb, $templates;

	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("member_profile", '#{\$reputation}#', "{\$reputation}\n{\$tcount}\n");

}

function tcount_deactivate()
{
	global $db, $mybb;

	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("member_profile", '#(\n?){\$tcount}(\n?)#', '', 0);

}

function tcount()
{
	global $mybb, $theme, $templates, $db, $tcount, $memprofile;
	
	$query = $db->simple_select("threads", "*", "uid='".$mybb->input['uid']."'");

	$tcount = "<tr>
	<td class=\"trow1\"><strong>Threads:</strong></td>
	<td class=\"trow1\">{$db->num_rows($query)}</td>
</tr>";

}


?>
It works fine for me. I do suggest to change the following though:

function tcount()

to something like:

function tcount_profile()
I changed it, now when I try and access a member profile it says the website encountered an error.

It seems that if it isn't named tcount() it won't let me load a member profile. Weird.
(2011-12-12, 03:37 AM)Shannon Wrote: [ -> ]I changed it, now when I try and access a member profile it says the website encountered an error.

It seems that if it isn't named tcount() it won't let me load a member profile. Weird.

You would need to change the hook as well to:

$plugins->add_hook('member_profile_end', 'tcount_profile');
Too right, I'll check up now.

The page loads now, but the plugin is still playing up. I went into Tools and Maintenance and it says I haven't CHMOD all the files required, so I did so. I reloaded the page and it still says I haven't. Can you CHMOD files in localhost? I am just doing "chmod 777 file" in terminal.
Try unsetting the the $tcount variable during deactivation.
You're a legend pyridine. Thanks so much.

I guess this plugin is complete. First plugin ever! Big Grin