MyBB Community Forums

Full Version: Make links visible to only registered members ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I want to make links visible to only registered members. How can i do that ? So if you are not registered it should display like "Please register to see links"

Thank you
(2012-01-05, 07:25 PM)MonsterMMORPG Wrote: [ -> ]Hello. I want to make links visible to only registered members. How can i do that ? So if you are not registered it should display like "Please register to see links"

Thank you

download & install the template conditionals plugin
and some code like
<if $GLOBALS['mybb']->user['usergroup'] >= 2 then>
                      some link
           elseif
                    please register
          </if>

It works well but look at this
(2012-01-05, 07:48 PM)ranjani Wrote: [ -> ]see scd code hide plugin

Hello. Thanks for reply. Does this work with 1.6.5 ?
(2012-01-05, 07:39 PM)JimR Wrote: [ -> ]
(2012-01-05, 07:25 PM)MonsterMMORPG Wrote: [ -> ]Hello. I want to make links visible to only registered members. How can i do that ? So if you are not registered it should display like "Please register to see links"

Thank you

download & install the template conditionals plugin
and some code like
<if $GLOBALS['mybb']->user['usergroup'] >= 2 then>
                      some link
           elseif
                    please register
          </if>

It works well but look at this

I am trying to hide user posted links.
OK, just make a new plugin by your self.

Here I will post a basic code.

Make a file called onlyreglinks.php in you "inc/plugins" folder

<?php
if(!defined("IN_MYBB"))
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");

$plugins->add_hook("parse_message", "onlyreglinks");

function onlyreglinks_info() {
   return array(
   "name" => "Registered Members Links",
   "description" => "Links for only registered members",
   "author" => "your name",
   "version" => "1.0.0",
   "compatibility" => "16*"
   );
}

function onlyreglinks_active() {
}

function onlyreglinks_deactive() {
}

function onlyreglinks($content) {

   global $mybb;  
  
   if($mybb->user['usergroup'] < 2)  {
		$content = preg_replace("/<a href=\"(.*?)\" target=\"(.*?)\">(.*?)<\/a>/is","<a href=\"".$mybb->settings['bburl']."/member.php?action=register\">Please Register to see links</a>",$content);		
	}
	return $content;
}

?>

Now just Active this plugin.

I've not tried this. If this does not work then reply immediately.
(2012-01-06, 12:24 AM)svr2009wwe Wrote: [ -> ]OK, just make a new plugin by your self.

Here I will post a basic code.

Make a file called onlyreglinks.php in you "inc/plugins" folder

<?php
if(!defined("IN_MYBB"))
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");

$plugins->add_hook("parse_message", "onlyreglinks");

function onlyreglinks_info() {
   return array(
   "name" => "Registered Members Links",
   "description" => "Links for only registered members",
   "author" => "your name",
   "version" => "1.0.0",
   "compatibility" => "16*"
   );
}

function onlyreglinks_active() {
}

function onlyreglinks_deactive() {
}

function onlyreglinks($content) {

   global $mybb;  
  
   if($mybb->user['usergroup'] < 2)  {
		$content = preg_replace("/<a href=\"(.*?)\" target=\"(.*?)\">(.*?)<\/a>/is","<a href=\"".$mybb->settings['bburl']."/member.php?action=register\">Please Register to see links ".$mybb->users['uid'] ."</a>",$content);		
	}
	return $content;
}

?>

Now just Active this plugin.

I've not tried this. If this does not work then reply immediately.


Thanks a lot for answer. Working great. I also want to make images to requires register. How can i do that ? Thank you.
No problem man. And can you expand your last question? I didn't quite catch that..

And one more thing.. Please remove
".$mybb->users['uid'] ."
from the script. I just put that when I was checking. Or it might display user id too.
(2012-01-06, 06:44 AM)svr2009wwe Wrote: [ -> ]No problem man. And can you expand your last question? I didn't quite catch that..

And one more thing.. Please remove
".$mybb->users['uid'] ."
from the script. I just put that when I was checking. Or it might display user id too.

I was also wondering that Big Grin

Now my extended question is what if i want also block images user posted ?
If you are gonna use both plugins at the same time then just add following line in your code ("onlyreglinks.php")

$content = preg_replace("/<img src=\"(.*?)\" border=\"(.*?)\" alt=\"(.*?)\" \/>/is","<a href=\"".$mybb->settings['bburl']."/member.php?action=register\">Please Register to see Image</a>",$content);

between

if($mybb->user['usergroup'] < 2)  {

// INSERT THAT CODE HERE IN YOUR"ONLEYREGLINKS.PHP" FILE

$content = preg_replace("/<a href=\"(.*?)\" target=\"(.*?)\">(.*?)<\/a>/is"....