MyBB Community Forums

Full Version: How to assign mybb->settings to a variable?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to assign mybb->settings to a variable.
e.g. using find and replace function, I added my variable {$test1} in the index page. and in the function testplugin() I am assigning value as
global $test1;
$test1= $mybb->settings['mytest_setting1'];
But this thing remove my whole index.php Toungue a blank page. I run the plugin without assigning value to $test1, and it runs fine

First off, why would you want to output a setting in the templates? Secondly, you need to actually add the setting to the database. Post the complete code of the plugin you made.
You need to globalise $mybb too otherwise it can't access it.
Here is the plugin code,
<?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("index_start","test");

function test_info()
		{
return array(
		
		"name"=> "This is a test plugin",
		"description"=> "This test plugin will add a box above form",
		"website"=> "www.vubscs.tk",
		"author"=> "sunjava1",
		"authorsite"=> "www.vubscs.tk",
		"version"=> "1.0",
			);
		}
		
function test_activate(){
global $db;
	
	$test_group = array(
		"name" => "test",
		"title" => "Add a box",
		"description" => "Add a box as a test",
		"disporder" => "500",
		"isdefault" => "no",
		);
	$group['gid'] = $db->insert_query("settinggroups", $test_group);
	$gid = $db->insert_id();
	
	$test_box_width = array(
		"name" => "box_width",
		"title" => "Width",
		"description" => "Set width, default is 300",
		"optionscode" => "text",
		"value" => "300",
		"disporder" => "2",
		"gid" => intval($gid),
		);
	$db->insert_query("settings", $test_box_width);
	
	
	
 require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("index", "#".preg_quote('{$forums}')."#i", '<table border=\'1\' width=\'{$test_1}\'><tr><td>hi this is a demo plugin test </td></tr></table> {$forums}'); 
	rebuild_settings();
}		

function test_deactivate(){
global $db;
	
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='test'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='box_width'");

  require MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("index", "#".preg_quote('<table border=\'1\' width=\'{$test_1}\'><tr><td>hi this is a demo plugin test </td></tr></table> {$forums}')."#i", '{$forums}'); 

	// Rebuilding settings
    
	rebuild_settings();
	}

function test(){
global $mybb, $test_1;	

	$test_1=$mybb->settings['box_width'];
	
	}
		

?>



(2011-09-21, 01:03 PM)MattRogowski Wrote: [ -> ]You need to globalise $mybb too otherwise it can't access it.

I have globalized it also
Looks ok to me, just skimming over it.

Just a note you will want to add http:// before website and authorsite

(2011-09-21, 05:30 PM)PJGIH Wrote: [ -> ]Looks ok to me, just skimming over it.

Just a note you will want to add http:// before website and authorsite

Yeah , But I want to fix This value taking thing Undecided
you are globalling "test' but populating and expecting a variable called "test_1"
(2011-09-21, 05:43 PM)pavemen Wrote: [ -> ]you are globalling "test' but populating and expecting a variable called "test_1"

Derp, how didn't I see that Toungue

Yes, what he said.
(2011-09-21, 05:43 PM)pavemen Wrote: [ -> ]you are globalling "test' but populating and expecting a variable called "test_1"

Thanks lol, I was blind Big Grin