Usercp Menu Plugin Problem
#1
Hi.

I am developing a plugin that will restrict the users to change their password and email from the USER CP Menu.

I developed the plugin but it does not work.

When user clicks on the action to edit the password it works fine. If the usergroup has the permission to change the password he can change it otherwise you do not.

The problem now is with the menu on the left side. If user has the permission to edit password the User CP menu "Change Password" does not show up. The code is executed just fine but when it comes to the part to replace the custom template value $changepasswordop it does not work.

Any ideas what is going on?

See below my code.

$plugins->add_hook("usercp_menu", "change_password");
$plugins->add_hook("usercp_password", "password_validate");

function password_activate () {
	global $db;
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
	find_replace_templatesets('usercp_nav_profile', '#'.preg_quote('<div><a href="usercp.php?action=password" class="usercp_nav_item usercp_nav_password">{$lang->ucp_nav_change_pass}</a></div>').'#', '{$changepasswordop}');
}

function password_deactivate () {
	global $db;
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
	find_replace_templatesets('usercp_nav_profile', '#{\$changepasswordop}#', '<div><a href="usercp.php?action=password" class="usercp_nav_item usercp_nav_password">{$lang->ucp_nav_change_pass}</a></div>');
}

function change_password() {
	global $mybb, $templates, $changepasswordop;
	$changepasswordop = '';
	if($mybb->usergroup['canchangepassword'] == 1) {
		eval("\$changepasswordop = \"".$templates->get("usercp_nav_changepassword")."\";");
	}
}

function password_validate() {
	global $mybb;
	if($mybb->usergroup['canchangepassword'] != 1) {
		error_no_permission();
	}
}
Reply
#2
Only add this manually and there you are....

usercp.php?action=password

usercp.php?action=email

There's no reason to use other code, why, because you've got an error maybe if you use THIS_SCRIPT then you put own values there you have it... I think is not necesary to do all this, only set values of new groups if you wish and the conditionals to do some or got an error and that's all !!!
The only infinite thing is the universe and human stupidity, but the universe is not for sure

Plugins 1.6.x

Plugins 1.8.x

Reply
#3
Dark Neo

Thanks for the reply...

But for the sake of it if I want to use this code what is the problem and the eval below does not work?

eval("\$changepasswordop = \"".$templates->get("usercp_nav_changepassword")."\";");

(01-22-2015, 08:58 AM)Dark Neo Wrote: Only add this manually and there you are....

usercp.php?action=password

usercp.php?action=email

There's no reason to use other code, why, because you've got an error maybe if you use THIS_SCRIPT then you put own values there you have it... I think is not necesary to do all this, only set values of new groups if you wish and the conditionals to do some or got an error and that's all !!!

The only way to work is adding the code in here but I do not want to edit the core files.

function usercp_menu_profile()
{
	global $db, $mybb, $templates, $theme, $usercpmenu, $lang, $collapsed, $collapsedimg;

	$changenameop = '';
	if($mybb->usergroup['canchangename'] != 0)
	{
		eval("\$changenameop = \"".$templates->get("usercp_nav_changename")."\";");
	}

	$changesigop = '';
	if($mybb->usergroup['canusesig'] == 1 && ($mybb->usergroup['canusesigxposts'] == 0 || $mybb->usergroup['canusesigxposts'] > 0 && $mybb->user['postnum'] > $mybb->usergroup['canusesigxposts']))
	{
		if($mybb->user['suspendsignature'] == 0 || $mybb->user['suspendsignature'] == 1 && $mybb->user['suspendsigtime'] > 0 && $mybb->user['suspendsigtime'] < TIME_NOW)
		{
			eval("\$changesigop = \"".$templates->get("usercp_nav_editsignature")."\";");
		}
	}

	if(!isset($collapsedimg['usercpprofile']))
	{
		$collapsedimg['usercpprofile'] = '';
	}

	if(!isset($collapsed['usercpprofile_e']))
	{
		$collapsed['usercpprofile_e'] = '';
	}

	eval("\$usercpmenu .= \"".$templates->get("usercp_nav_profile")."\";");
}
Reply
#4
You have to add a global variable (so $GLOBALS['changepasswordop']) to the usercp_nav_profile template, like this: https://github.com/Destroy666x/MyBB-Styl...k.php#L192
Reply
#5
(01-22-2015, 11:05 AM)Destroy666 Wrote: You have to add a global variable (so $GLOBALS['changepasswordop']) to the usercp_nav_profile template, like this: https://github.com/Destroy666x/MyBB-Styl...k.php#L192

THANK YOU!!!! THANK YOU!!!! THANK YOU!!!! THAAAAAAAANNNNKKKK YYYYOOOOUUUUU!!!!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)