MyBB Community Forums

Full Version: How to make a Template Conditional or PHP statement for this?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,

I would like to make either a Template Conditional or PHP statement that goes as follows, but I have no idea for the actual code to use:

If a mybb user has less than 10 posts, do not allow them to modify their profile usercp.php?action=profile (an error message appears), only allow them to change their sex [fid3].

Does anyone know what the syntax for this is in PHP or as a Template Conditional?
You need to create a plugin and hook it to usercp.php or to user.php that is the only way.
You can do it with a template conditional. This is untested, but should give you what you want.

<if $mybb->user['posts'] < 10 then>
Message explaining why a user can only edit their sex.
Dropdown for their sex (You'll need to hard code this. Best way is to view the source of the profile and just copy/paste the HTML for the dropdown)
<else />
All the regular profile information.
</if>

Edit: The one potential issue with this is that if you have other fields (not the sex field) that are required, the user won't be able to fill them out and they will get errors when trying to submit their updated profile. So if you have other fields that are required for users to fill out, you'll need to add the code for them as well.
Moved to Plugin Support.
Template conditional will only remove the link from the template you need to edit code file or hook to it and check if the user that is trying to access function meats the requirements easy task really.

Open usercp.php and find:

if($mybb->input['action'] == "do_profile" && $mybb->request_method == "post")
{

Add below:

if($mybb->user['postnum'] <= 10 && !in_array($mybb->user['usergroup'], array('3','4','6'))) {
error("Your error message");
}
Template Conditionals shouldn't be trusted for this kind of modifications. Users will still be able to edit their profile I'd they have the permission to do so, even if you hide the HTML content.
I'd be curious to know how the average user would be able to edit their profile information if they can't see the HTML content for that information.

It would be more secure to make core file changes, but this is easily done using template conditionals, considering most users aren't going to have any idea how to change something if they can't even see it on the page. That seems to be the goal of the OP.

Martec, your code doesn't accomplish the task the OP wanted. It shows an error message if they have less than 10 posts and are not in the specified usergroups (not sure why you included those), but it doesn't give the user the ability to still edit their gender field.
@Jshort think of it like it in php:

if(condition1 != 2)
.. content

else
everyone can see

It basically hides it.
I know? That was the point.

What I'm saying is that the average user isn't going to realize that.
(2014-06-19, 01:32 AM)jshort Wrote: [ -> ]I'd be curious to know how the average user would be able to edit their profile information if they can't see the HTML content for that information.

It would be more secure to make core file changes, but this is easily done using template conditionals, considering most users aren't going to have any idea how to change something if they can't even see it on the page. That seems to be the goal of the OP.

Martec, your code doesn't accomplish the task the OP wanted. It shows an error message if they have less than 10 posts and are not in the specified usergroups (not sure why you included those), but it doesn't give the user the ability to still edit their gender field.

Because I can just enter directly into the browser Smile LOL
usercp.php?action=profile

Don't be lazy and do stuff the right way. Have you though about spambots?????????????
Pages: 1 2