MyBB Community Forums

Full Version: Adding my own postbit function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I want to display my own userprofile field in postbit_classic if fid4 is not empty. I have done it easily with the MyBB conditionals plugin, but was trying to get it done with core edits.

I added this inside functions_post.php:
		if($mybb->user['uid'] != "0") && ($mybb->user['fid4'] != "")
		{
			eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");			
		}
		else
		{
			$post['donatefield'] = "";
		}
		

Then added postbit_donate as a template with this content:
Donation Link: <br><a href="{$post['fid4']}"><img src="images/donate.png"></a>	<br>

Finally I added this to postbit_classic:
{$post['donatefield']}

next to the line for displaying avatar..

When I loaded my page, nothing was displayed! Can someone explain where I've done wrong?
Darn..sorry...found my mistake
Why not try making it as a plugin if its not default system?
I've thought of it, but I still have to readup about hooks. Smile
Is there a syntax error in this:

		if($mybb->user['uid'] != "0") && ($mybb->user['fid4'] != "")
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }	


Because the following works:
		if($mybb->user['fid4'] != "")
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }


So does:
		if($mybb->user['uid'] != "0")
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }
Use postbit hook. Smile

http://wiki.mybb.com/index.php/MyBB_Plugin_Hooks

^You'd need postbit hook.
Found out the syntax error..Seems to be operator precedence. I needed an extra bracket:

This works:
		if(($mybb->user['uid'] != "0") && ($mybb->user['fid4'] != ""))
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }	
(2011-12-10, 05:06 PM)dzchimp Wrote: [ -> ]I've thought of it, but I still have to readup about hooks. Smile
Is there a syntax error in this:

		if($mybb->user['uid'] != "0") && ($mybb->user['fid4'] != "")
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }	


Because the following works:
		if($mybb->user['fid4'] != "")
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }


So does:
		if($mybb->user['uid'] != "0")
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }

Yes, the top code should be:

if ($mybb->user['uid'] != "0" && $mybb->user['fid4'] != "")
{
	eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
}
else
{
	$post['donatefield'] = "Hello";
}
you should consider using the Patches plugin since it will do the edits for you and allow you to reapply the file edits after an upgrade. it wont do templates, but those are usually not an issue
If it does the equivalent of a unix patch, that's close to what I'm using. I use git to keep track of changes and keep commits of changes.
it is similar
I'm still having issues in my logic though:
		if($mybb->user['uid'] != "0" && $mybb->user['fid4'] != "")
        {
            eval("\$post['donatefield'] = \"".$templates->get("postbit_donate")."\";");            
        }
        else
        {
            $post['donatefield'] = "Hello";
        }

I want it to display the template only for users whose fid4 is null. However it seems to display the fid4 value of the user who has set it, for any user who has null value!
Pages: 1 2