MyBB Community Forums

Full Version: Code Suggestion
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the following code of a hidelinks plugin, I want to add a feature which will hide links only in a specific forum id (fid). With the following code, all over the forum, the usergroup (ID 2) encounters with a hidelink message for links, but I want the usergroup (ID 2) to encounter with the hidelink message on a specific forum id. So what kind of code should I include over there? If you are advanced in php and understand the following codes, I believe you can help me. I'll try your suggestion.

// Run plugin
function hidelinks_hide(&$message)
{
	global $settings, $mybb;
	
	if ($mybb->settings['hidelinks_enabled'] == "1")
	{
		if($mybb->user['usergroup'] == "2")
		{
			$message = preg_replace("!<a[^>]*(http|www)(.*)</a>!siU", "{$mybb->settings['hidelinks_message']}", $message);
		}
	}
}
what hook are you using?
Hide Links to Guests by DragonFever
not the plugin, but what hook is calling the function you posted, that will let us know what variables are available to do what you want.
// Plugin hook
$plugins->add_hook("parse_message", "hidelinks_hide");
Well if you only wanted this to hide links for Usergroup 2 on 1 specific forum you could just replace the _hide function with this:
// Run plugin
function hidelinks_hide(&$message)
{
    global $settings, $mybb, $post;
    
    if ($mybb->settings['hidelinks_enabled'] == "1")
    {
        if($mybb->user['usergroup'] == "2" && $post['fid'] == "FIDHERE")
        {
            $message = preg_replace("!<a[^>]*(http|www)(.*)</a>!siU", "{$mybb->settings['hidelinks_message']}", $message);
        }
    }
}
^^this is what I was getting at. needed to know when the function was being called to know what variables are available. in this case, $post is available and it contains the 'fid' array key for you to use
Thanks for your help. Your code suggestion really works on the specific forum!
However, I have another question related to this matter. How can we include more than one fid?

if($mybb->user['usergroup'] == "2" && $post['fid'] == "FIDHERE")

I tried with comas, but it didn't work. Waiting for your suggestions. Thanks again.

Edit:
In the meantime, the following code solves the problem, but I have to add two lines for each fid? It will be a bit long; so I hope you might suggest a shorter way for this. Thanks.

		if($mybb->user['usergroup'] == "2" && $post['fid'] == "414")
		{
			$message = preg_replace("!<a[^>]*(http|www)(.*)</a>!siU", "{$mybb->settings['hidelinks_message']}", $message);
		}
		if($mybb->user['usergroup'] == "2" && $post['fid'] == "23")
		{
			$message = preg_replace("!<a[^>]*(http|www)(.*)</a>!siU", "{$mybb->settings['hidelinks_message']}", $message);
		}
		if($mybb->user['usergroup'] == "2" && $post['fid'] == "526")
		{
			$message = preg_replace("!<a[^>]*(http|www)(.*)</a>!siU", "{$mybb->settings['hidelinks_message']}", $message);
		}
you can cahnge

$post['fid'] == "414"

to

in_array($post['fid'], array(414, 415, 416))
Your suggestion is valuable. Thank you very much!