Adding functionality to the admin cp
#11
(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.
-TOA
Ordo Ab Chao
"Insanity: doing the same thing over again and expecting different results." - Einstein
Reply
#12
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.
-TOA
Ordo Ab Chao
"Insanity: doing the same thing over again and expecting different results." - Einstein
Reply
#13
I generally work off of a simple plugin like this:

https://github.com/lukaszklis/BoardMessages
-Paul H.

Cogisne lingua latina?
Reply
#14
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.
-TOA
Ordo Ab Chao
"Insanity: doing the same thing over again and expecting different results." - Einstein
Reply
#15
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.
-TOA
Ordo Ab Chao
"Insanity: doing the same thing over again and expecting different results." - Einstein
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)