MyBB Community Forums

Full Version: Adding functionality to the admin cp
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2012-08-01, 07:18 PM)RateU Wrote: [ -> ]You can try using the admin_page_output_nav_tabs_start and/or admin_user_users_begin

Nice, thank you very much.

(2012-08-01, 07:18 PM)RateU Wrote: [ -> ]depends on what you want to do with your plugin.

What's the difference? Can you give me an example of a time when I would choose one over the other?

Thank you so much for your help.


Well, I got the tab added! It was admin_page_output_nav_tabs_start.

Now on to the next part. I'll start a different thread if I have any other questions though.

I'd still like to know the answer to this though, just for posterity.
(2012-08-01, 08:39 PM)TOA Wrote: [ -> ]
(2012-08-01, 07:18 PM)RateU Wrote: [ -> ]depends on what you want to do with your plugin.

What's the difference? Can you give me an example of a time when I would choose one over the other?

Thank you very much for steering me in the right direction.
So I guess it's not quite resolved. I just noticed that my tab shows up on all pages, not just the user module.

Is there a way to target that particular page/tab grouping?


I tried just switching to the admin_user_users_begin hook but get the following error regarding the $sub_tabs array
Quote:Warning [2] end() [function.end]: Passed variable is not an array or object -

So I take it the first hook is right but there must be a way to target just the user module.

Any ideas are appreciated, thanks.
I generally work off of a simple plugin like this:

https://github.com/lukaszklis/BoardMessages
Well, I got it by using this condition

if ($mybb->input['module'] == "user")

But the admin_user_users_begin hook seems the better choice, but I can't make it work yet. I'd still like to find the solution using that method if anyone can help.

Thanks for reading.

(2012-08-03, 07:38 PM)Paul H. Wrote: [ -> ]I generally work off of a simple plugin like this:

https://github.com/lukaszklis/BoardMessages

I'll check it out right now, thank you very much.

Yeah, that's a good one.

This

if ($run_module == 'user')

works just the same as the method I posted previously. I'm going to use this one.

Thanks for sharing.
Something's not right and I can't figure out what or how to fix it.

I've got the tab showing up. Here's where it might be confusing to follow so I'll try to be simple:
If I use a separate file located in modules, it will work and link the tab to the new page.
But if I use a function within my plugin to try to show the page it won't work (this is the method I would prefer to use as I feel a plugin should be self-contained. What is the common practice on this?).
I'm even using the plugin previously suggested by Paul H as a guide and everything seems fine to me, but it just links back to the admin home page.

Am I missing something? Why is this not working?

Here's my relevant code
/**
* Call Hooks
*/
// add the tab
$plugins->add_hook("admin_page_output_nav_tabs_start", 'adminimportusers_addtab');
// add the action of the tab
$plugins->add_hook("admin_user_action_handler", "adminimportusers_action");
// set permissions
$plugins->add_hook("admin_user_permissions", "adminimportusers_permissions");
// load the page
$plugins->add_hook('admin_load', 'adminimportusers_page');

// Add a tab to the Users & Groups module
function adminimportusers_addtab(&$sub_tabs) {
	global $mybb, $lang, $run_module;
	// see if the pugin has been enabled in config
	if ($mybb->settings['adminimportusers_enable'] == 1) {
		// make sure it only shows for the user module
		if ($run_module == 'user') {
			// now add our tab to the list
			$sub_tabs['adminimportusers'] = array(
				'id' => 'adminimportusers',
				'link' => 'index.php?module=user/adminimportusers',
				'description' => 'Import Users into your MyBB forum.',
				'title' => 'Import Users',
			);
			// pass 'em back
			return $sub_tabs;
		}
	}
} 

// Now make the link work by adding the action to the meta
function adminimportusers_action(&$actions) {
	$actions['adminimportusers'] = array('active' => 'adminimportusers', 'file' => 'adminimportusers');
	return $actions;
}

// Lets set some permissions
function adminimportusers_permissions(&$admin_permissions) {
	global $db, $mybb, $lang;
	$admin_permissions['adminimportusers'] = "Can Import Users?";
	return $admin_permissions;
}

// now, the bulk of the script
function adminimportusers_page() {
	global $db, $lang, $mybb, $page, $run_module, $action_file;
	
	// don't show this page unless asked and the plugin is enabled	
	if ($run_module == 'user' && $action_file == 'adminimportusers') {
		echo "Catching condition";
	}
}


Nevermind, Got it.

Figures; I try for an hour and as soon as I post it I get it.
Pages: 1 2