Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Tristan Perry on September 11, 2004, 09:56:11 AM

Title: Disable deletion of yourself
Post by: Tristan Perry on September 11, 2004, 09:56:11 AM
Hello all,
  If you're like me, and very paranoid then this may help you  :P. It stops people [With the correct permissions] from deleting your account on your forums. To do this find:

function deleteMembers($users)
{
global $db_prefix, $sourcedir, $modSettings, $ID_MEMBER;

In Sources/ManageMembers.php (/Sources/Subs-members.php in SMF 1.1)

and replace it with:

function deleteMembers($users)
{
global $db_prefix, $sourcedir, $modSettings, $ID_MEMBER;

        // Protect the person who started the forum

       if ($users == 1 or @in_array(1, $users))
              fatal_error('You\'re not allowed to delete the administrator.');


This stops people from deleting your account either through your profile, or through the view/delete members page in the admin panel.
If you're ID isn't 1, but you still want to protect yourself, then just change the 2 numbers in this part:
if ($users == 1 || (is_array($users) && in_array(1, $users)))
to whatever your member ID is.

If you want this to not extend to more than one user, you can do so by doing what JohnyB (http://www.simplemachines.org/community/index.php?action=profile;u=67763) suggested:

// Protect the person who started the forum

if ($users == 1 or $users == 2 or @in_array(1, $users) or @in_array(2, $users))
     fatal_error('You\'re not allowed to delete the administrator.');


I hope this helps someone.
TauOnline.Org (http://tauonline.org)
Title: Re: Disable deletion of yourself.
Post by: Amacythe on September 11, 2004, 10:23:49 AM
Keep in mind this only works if the Admin is member number one.  In my case, (an upgraded board that had a 'dummy' admin set up as member number one) I need to change it slightly.
Title: Re: Disable deletion of yourself.
Post by: Tristan Perry on September 11, 2004, 10:26:14 AM
Quote from: Amacythe on September 11, 2004, 10:23:49 AM
Keep in mind this only works if the Admin is member number one.  In my case, (an upgraded board that had a 'dummy' admin set up as member number one) I need to change it slightly.
Yeah it's easy to change though  :) I'll edit my post just to show how to do it if people don't know.
Title: Re: Disable deletion of yourself.
Post by: [Unknown] on September 11, 2004, 03:28:08 PM
Quote from: Tau Online on September 11, 2004, 09:56:11 AM
if ($users == 1 xor in_array(1, $users) )

Just wondering; is there a particular reason you're using xor here?  It's different from or in that it means one OR the other, but not BOTH.  In this case, it really *couldn't* be both, but or (||) should work too....

-[Unknown]
Title: Re: Disable deletion of yourself.
Post by: Tristan Perry on September 11, 2004, 04:12:51 PM
Quote from: [Unknown] on September 11, 2004, 03:28:08 PM
Quote from: Tau Online on September 11, 2004, 09:56:11 AM
if ($users == 1 xor in_array(1, $users) )

Just wondering; is there a particular reason you're using xor here?  It's different from or in that it means one OR the other, but not BOTH.  In this case, it really *couldn't* be both, but or (||) should work too....

-[Unknown]
Your right! Thanks, I'll change it now  :) It wouldn't make a difference though would it? (I mean whether xor or || is used?)
Title: Re: Disable deletion of yourself.
Post by: [Unknown] on September 11, 2004, 04:23:57 PM
Nope, none really in this case.... although, I prefer "||" over the word form "or".... then again I like C/C++ ;).

-[Unknown]
Title: Re: Disable deletion of yourself.
Post by: double_d on January 25, 2005, 05:40:46 PM
Dont' want to be a pain, but is there a way to keep users from deleting their own accounts?  I hate when people do that.
Title: Re: Disable deletion of yourself.
Post by: [Unknown] on January 25, 2005, 06:45:40 PM
It's a permission.  Simply disallow it.

-[Unknown]
Title: Re: Disable deletion of yourself.
Post by: Sol on January 27, 2005, 11:56:38 AM
This doesn't seem to work with SMF 1.0.1 Final :'(

I get this error :
2: in_array(): Wrong datatype for second argument
File: /home/sol/public_html/forum/Sources/ManageMembers.php
Line: 984

Line 984 :
if ($users == 1 || in_array(1, $users) )

I've used this trick twice before with RC2 and it's worked fine. I've copied everything exactly right.
Title: Re: Disable deletion of yourself.
Post by: Tristan Perry on January 27, 2005, 12:19:23 PM
Quote from: Sol on January 27, 2005, 11:56:38 AM
This doesn't seem to work with SMF 1.0.1 Final :'(

I get this error :
2: in_array(): Wrong datatype for second argument
File: /home/sol/public_html/forum/Sources/ManageMembers.php
Line: 984

Line 984 :
if ($users == 1 || in_array(1, $users) )

I've used this trick twice before with RC2 and it's worked fine. I've copied everything exactly right.
It's not updated to work with SMF 1.0(.1) I'll update it sometime  :)
Title: Re: Disable deletion of yourself.
Post by: Sol on January 27, 2005, 03:45:44 PM
As soon as possible please :P
Title: Re: Disable deletion of yourself.
Post by: azuregenesis on May 24, 2005, 11:58:02 PM
working fix for 1.03 (tested) just quoted TauOnline and edited it :)

find in Sources/ManageMembers.php
function deleteMembers($users)
{
global $db_prefix, $sourcedir, $modSettings, $ID_MEMBER;

In Sources/ManageMembers.php

and replace it with:


function deleteMembers($users)
{
global $db_prefix, $sourcedir, $modSettings, $ID_MEMBER;

        // Protect the person who started the forum
if ($users == 1)
{
           fatal_error('You\'re not allowed to delete the administrator.');
           exit();
}


This stops people from deleting your account either through your profile, or through the view/delete members page in the admin panel.
If you're ID isn't 1, but you still want to protect yourself, then just change the number.
Title: Re: Disable deletion of yourself.
Post by: Jako on June 26, 2005, 04:59:20 AM
Am I the only one that's scared to test this mod out? >>
Title: Re: Disable deletion of yourself
Post by: Tristan Perry on June 26, 2005, 05:37:49 AM
I've updated my first post so this now works with updated versions (Tested with 1.1 Beta 3 and 1.0.5)

Credit goes to [Unknown] for this update, he posted an updated/working version of this hack in one of the threads in the Announcements board.

Quote from: Jako on June 26, 2005, 04:59:20 AM
Am I the only one that's scared to test this mod out? >>
:P I was at first. Either backup your database or run SMF on a test server.. It should work though.
Title: Re: Disable deletion of yourself.
Post by: azuregenesis on June 26, 2005, 08:18:04 AM
Quote from: Jako on June 26, 2005, 04:59:20 AM
Am I the only one that's scared to test this mod out? >>

you can do what TAU said above or you can also change the user number in the code above. :)

instead of "1" (whcih is the admin) change it to another one, like a member that you're about to remove.
Title: Re: Disable deletion of yourself
Post by: Metal_GunBlade on July 10, 2005, 12:34:42 PM
Dude, I have SMF 1.1 Beta 3 but I can't find the code...
Is there something I'm missing???
Title: Re: Disable deletion of yourself
Post by: [Unknown] on July 10, 2005, 07:43:45 PM
It's in Subs-Members.php.

-[Unknown]
Title: Re: Disable deletion of yourself
Post by: rojamaia on August 27, 2005, 08:05:21 AM

how about if i want to protect two or more accounts?

can i just add comma to the number like if ($users == 1,2 xor in_array(1,2 $users) )

by the way, which one of the two codes would work for 1.0.5?  could you please label those codes with the versions that it would work with?

thank you!  :D
Title: Re: Disable deletion of yourself
Post by: [Unknown] on August 27, 2005, 01:17:58 PM
No, you can't just add commas like that.  Instead:

if ($users == 1 or $users == 2 or @in_array(1, $users) or @in_array(2, $users))

Would probably be best.

-[Unknown]
Title: Re: Disable deletion of yourself
Post by: rojamaia on August 27, 2005, 01:28:31 PM
so if it's three users, i just add more "or"s?


something like this?
if ($users == 1 or $users == 2 or $users == 36 or @in_array(1, $users) or @in_array(2, $users) or @in_array(3, $users))
Title: Re: Disable deletion of yourself
Post by: Tristan Perry on August 27, 2005, 01:40:07 PM
Quote from: malinaobenny on August 27, 2005, 01:28:31 PM
so if it's three users, i just add more "or"s?


something like this?
if ($users == 1 or $users == 2 or $users == 36 or @in_array(1, $users) or @in_array(2, $users) or @in_array(3, $users))
That would be correct, yes.
Title: Re: Disable deletion of yourself
Post by: Anakin_holland on August 27, 2005, 02:23:07 PM
Quote from: malinaobenny on August 27, 2005, 01:28:31 PM
so if it's three users, i just add more "or"s?


something like this?
if ($users == 1 or $users == 2 or $users == 36 or @in_array(1, $users) or @in_array(2, $users) or @in_array(3, $users))

Shouldn't that be:

if ($users == 1 or $users == 2 or $users == 36 or @in_array(1, $users) or @in_array(2, $users) or @in_array(36, $users))

?? Don't know myself, just curious?

Greetz!
Title: Re: Disable deletion of yourself
Post by: Tristan Perry on August 27, 2005, 02:46:43 PM
Quote from: Anakin_holland on August 27, 2005, 02:23:07 PM
Shouldn't that be:

if ($users == 1 or $users == 2 or $users == 36 or @in_array(1, $users) or @in_array(2, $users) or @in_array(36, $users))

?? Don't know myself, just curious?

Greetz!
Yeah, I presumed the original "3" was just a typo.
Title: Re: Disable deletion of yourself
Post by: DemonicInfluence on November 08, 2005, 09:58:47 PM
I have a question. Couldn't they just ban you? It would end in the same effect. Could someone make it so they can't ban or demote u?
Title: Re: Disable deletion of yourself
Post by: Anakin_holland on November 09, 2005, 02:23:12 PM
Quote from: Libo on November 08, 2005, 09:58:47 PM
I have a question. Couldn't they just ban you? It would end in the same effect. Could someone make it so they can't ban or demote u?

True, but a ban or demotion is reversable... ;) and the effect isn't exactly the same, because the messages will still be attached to that banned or demoted user?

Greetz!
Title: Re: Disable deletion of yourself
Post by: Elmacik on November 09, 2005, 06:00:37 PM
Support me here: Super admin (http://www.simplemachines.org/community/index.php?topic=53498.0) ;)
Maybe if much people asks for it, they give :P
Pepsi! Ask for more! LOL
Title: Re: Disable deletion of yourself
Post by: DemonicInfluence on November 09, 2005, 06:49:04 PM
okay, cool
Title: Re: Disable deletion of yourself
Post by: SleePy on November 12, 2005, 07:19:05 PM
couldnt you just check if the user is administrator and then disable deletion?
Title: Re: Disable deletion of yourself.
Post by: alphacaveman on January 02, 2006, 07:38:12 PM
Quote from: [Unknown] on January 25, 2005, 06:45:40 PM
It's a permission.  Simply disallow it.

-[Unknown]

As far as removing the ability of a member to delete their account, I can't find it in the permissions to disallow. Where is it?
Title: Re: Disable deletion of yourself.
Post by: azuregenesis on January 04, 2006, 10:14:00 AM
Quote from: leesw on January 02, 2006, 07:38:12 PM
Quote from: [Unknown] on January 25, 2005, 06:45:40 PM
It's a permission.  Simply disallow it.

-[Unknown]

As far as removing the ability of a member to delete their account, I can't find it in the permissions to disallow. Where is it?

using 1.1?
- admin>permissions>modify>uncheck delete account:own account

1.05?
- admin>edit permissions>modify>uncheck delete account:own account
Title: Re: Disable deletion of yourself
Post by: alphacaveman on January 07, 2006, 12:45:54 AM
Thank you azuregenesis!
Title: Re: Disable deletion of yourself
Post by: Dexy on January 16, 2006, 05:26:47 AM
What is code for SMF 1.0.5. ?
Title: Re: Disable deletion of yourself
Post by: sbarnes on May 30, 2006, 05:34:27 PM
Hi there,
I was about to add this to my site.
Just wanted to ask, is this till valid for version 1.1 RC2? or does that version already have this kind of feature?

I can find the code no problem but just wondered if this was a needed mod to add.
function deleteMembers($users)
{
global $db_prefix, $sourcedir, $modSettings, $ID_MEMBER;
Title: Re: Disable deletion of yourself
Post by: PrizeLive.com on June 16, 2006, 03:25:06 PM
What's the code for version 1.1 RC2?
Title: Re: Disable deletion of yourself
Post by: DemonicInfluence on June 18, 2006, 06:49:39 PM
The one for smf 1.1...
Title: Re: Disable deletion of yourself
Post by: Skipdawg on June 18, 2006, 08:32:43 PM
Glad this came back up. I had forgotten to had it back after updating to 1.1 RC2  ;D ;)
Title: Re: Disable deletion of yourself
Post by: PrizeLive.com on June 21, 2006, 11:28:52 AM
Quote from: DemonicInfluence on June 18, 2006, 06:49:39 PM
The one for smf 1.1...

So the code for smf 1.1 is compatible if you use 1.1 RC2? Are you sure?
Title: Re: Disable deletion of yourself
Post by: DemonicInfluence on June 26, 2006, 07:03:26 PM
yes..
Title: Re: Disable deletion of yourself
Post by: PrizeLive.com on June 29, 2006, 09:15:32 AM
Quote from: DemonicInfluence on June 26, 2006, 07:03:26 PM
yes..

Thanks!
Title: Re: Disable deletion of yourself
Post by: Stuart on July 08, 2006, 08:17:53 PM
This works great, thanks!
Title: Re: Disable deletion of yourself
Post by: ShadowStriker on July 19, 2006, 10:25:41 AM
Im member #1, but I have a spy that I use on the forum and act like a regular member, just to see ways people act and stuff. How would I make both undeleteable?
Title: Re: Disable deletion of yourself
Post by: Thurnok on August 03, 2006, 04:55:33 AM
[EDIT]

Removed all the code from here.  I have packaged this as a mod now and should be available shortly (once approved) here at SMF as "Admin Deletion Protect" mod.

In the interim, if you want this right away, you can find it at my TP Blocks (http://www.tpblocks.com) site available for download.  Downloading requires registration however.
Title: Re: Disable deletion of yourself
Post by: Stuart on December 21, 2006, 11:14:14 AM
Quote from: Stuart on July 08, 2006, 08:17:53 PM
This works great, thanks!

It's no longer working with SMF 1.1.1 though  :'(
Title: Re: Disable deletion of yourself
Post by: Shadow Queen on February 15, 2007, 08:43:39 PM
I can't found the code what i am looking for in the file.  I am running with 1.1.1 with TP.
Title: Re: Disable deletion of yourself
Post by: Yellowrose on March 04, 2007, 03:12:28 PM
I would also like to make use of this code edit.

SMF 1.1.2 w/Tiny Portal 0.9.7.1
Title: Re: Disable deletion of yourself
Post by: Skipdawg on March 04, 2007, 06:06:24 PM
Yes would be nice to have this updated for 1.1.2  ;)
Would be nicer to have this as a fixed option of enable or disabled in SMF Admin panel  ;D
Title: Re: Disable deletion of yourself
Post by: Thurnok on April 29, 2007, 07:41:22 AM
I updated the hack.  You can find a working version, including the fix for the Profile page to prevent removing from the Admin group, at my TP Blocks site (http://www.tpblocks.com).  The post is located here (http://www.tpblocks.com/index.php?topic=67.msg182#msg182) and is accessable to guests as well.
Title: Re: Disable deletion of yourself
Post by: DrDom on April 30, 2007, 10:49:30 AM
Quote from: Thurnok on April 29, 2007, 07:41:22 AM
I updated the hack.  You can find a working version, including the fix for the Profile page to prevent removing from the Admin group, at my TP Blocks site (http://tpblocks.ccs-net.com).  The post is located here (http://tpblocks.ccs-net.com/index.php?topic=67.msg182#msg182) and is accessable to guests as well.

It appears that guest access is not available, when I clicked the link it presents me with a registration box. :(
Title: Re: Disable deletion of yourself
Post by: Thurnok on April 30, 2007, 10:06:17 PM
Sorry, caught me in the middle of moving my site as well.  Try going to the new site (updated in my original post) and you should now be able to access it.
Title: Re: Disable deletion of yourself
Post by: DrDom on May 01, 2007, 06:38:49 AM
Quote from: Thurnok on April 30, 2007, 10:06:17 PM
Sorry, caught me in the middle of moving my site as well.  Try going to the new site (updated in my original post) and you should now be able to access it.
hi,
I noticed that the site was under maintenance later last night, thanks for the reply, i'll try again now.

Regards
Title: Re: Disable deletion of yourself
Post by: Thurnok on May 05, 2007, 05:47:43 PM
I've packaged this up as a Mod and it has now been submitted to SMF, just waiting approval.
Title: Re: Disable deletion of yourself
Post by: DrDom on May 06, 2007, 07:03:37 AM
I applied the mods from your site on may 1st, it works very well indeed.
But pleased to see you have made a package.

Regards
Title: Re: Disable deletion of yourself
Post by: Bulakbol on June 29, 2007, 07:47:38 PM
Quote from: Thurnok on May 05, 2007, 05:47:43 PM
I've packaged this up as a Mod and it has now been submitted to SMF, just waiting approval.

Is this mod not available for downloading yet?  It will be nice if it will work with SMF 1.1.3   ;)
Title: Re: Disable deletion of yourself
Post by: Bulakbol on July 04, 2007, 12:12:03 PM
Ok, tested with SMF 1.1.3 and it works. It won't delete user #5 and #6. Then I deleted #9 and it deleted it.  Thank you.


// Protect the person who started the forum

if ($users == 5 or $users == 6 or @in_array(5, $users) or @in_array(6, $users))
     fatal_error('You\'re not allowed to delete the administrator.');
Title: Re: Disable deletion of yourself
Post by: chrishicks on December 11, 2007, 09:45:09 AM
is anyone using this on 1.1.4?
Title: Re: Disable deletion of yourself
Post by: SleePy on December 11, 2007, 01:31:26 PM
The same method JohnyB has posted above would work for 1.1.4.
You will find little differences between 1.1.3 and 1.1.4 as once we released the 1.1 line it was only bug patches and security fixes we are doing :)
Title: Re: Disable deletion of yourself
Post by: theboogymaster on January 15, 2008, 04:46:35 PM
nice thks a lot
Title: Re: Disable deletion of yourself
Post by: MisticJeff on March 02, 2008, 06:07:30 PM
Anyone have any further info on this working with 1.1 RC3??  I tried inserting the code into Subs-Members.php and then tried deleting the named admin and it allowed me to...
Title: Re: Disable deletion of yourself
Post by: Stuart on March 09, 2008, 10:53:46 AM
Quote from: chrishicks on December 11, 2007, 09:45:09 AM
is anyone using this on 1.1.4?

Yes, and it works great!
Title: Re: Disable deletion of yourself
Post by: Tristan Perry on March 24, 2008, 07:25:09 AM
I've updated my first post to reflect JohnyB's suggested code change :)
Title: Re: Disable deletion of yourself
Post by: brianjw on July 02, 2008, 07:40:28 PM
A couple other questions, is it possible to disable ban of yourself and disable admin membergroup remove of yourself?
Title: Re: Disable deletion of yourself
Post by: assam_siddibapa on July 09, 2008, 10:55:48 AM
Wat about smf 1.1.5
Title: Re: Disable deletion of yourself
Post by: Bulakbol on July 09, 2008, 09:12:20 PM
It should work.
Title: Re: Disable deletion of yourself
Post by: assam_siddibapa on July 10, 2008, 08:14:57 AM
Can some one give me the exact code for smf 1.1.5

As i didnt find what  i need to change
Title: Re: Disable deletion of yourself
Post by: bros on July 11, 2008, 03:01:14 PM
Quote from: brianjw on July 02, 2008, 07:40:28 PM
A couple other questions, is it possible to disable ban of yourself and disable admin membergroup remove of yourself?

That feature would be quite useful
Title: Re: Disable deletion of yourself
Post by: Mr. Khan on July 12, 2008, 07:48:56 AM
Quote from: double_d on January 25, 2005, 05:40:46 PM
Dont' want to be a pain, but is there a way to keep users from deleting their own accounts?  I hate when people do that.
Totally agree :P
Title: Re: Disable deletion of yourself
Post by: Whimsical on January 22, 2009, 04:19:03 PM
Does this work for SMF 1.1.7??

Am curious, as I was going to use it but I am not finding any of the quoted code from the first post, in the stated files.

Any help appreciated :):)

Thanks :)
Title: Re: Disable deletion of yourself
Post by: Antechinus on January 22, 2009, 05:02:58 PM
I use it with 1.1.7.  Look on Line 113 of Sources/Subs-Members.php (note that this assumes the file has not been altered since installation).
Title: Re: Disable deletion of yourself
Post by: Whimsical on January 22, 2009, 07:49:41 PM
thank you so much!!

found it right where you said to look

no idea why it wasnt showing up when i did a search for it in the actual php file  ???

anywho.. thank you for the help, appreciate it :):)
Title: Re: Disable deletion of yourself
Post by: drvanitus on February 02, 2011, 08:32:08 PM
Anybody know what to do for 2.0 RC4?  I'm sure it can be done but I'm not qualified to mess around with it.  I could really use this.
Title: Re: Disable deletion of yourself
Post by: dougiefresh on February 26, 2011, 11:08:09 AM
Thanks for the information!

I assume 2.0 RC4 is similar to RC5.   :-[  I looked in Sources/Subs-Members.php and replace this line:
function deleteMembers($users, $check_not_admin = false)
{
global $sourcedir, $modSettings, $user_info, $smcFunc;

with the following:
function deleteMembers($users, $check_not_admin = false)
{
global $sourcedir, $modSettings, $user_info, $smcFunc;

  // Protect the person who started the forum
  if ($users == 1 or @in_array(1, $users))
    fatal_error('You\'re not allowed to delete the administrator.');

Once the code was installed, I tried to delete myself (after making a backup of the database  ;) ).  The "not allowed" message came up....  I hope this helps.
Title: Re: Disable deletion of yourself
Post by: H3lioz on October 06, 2011, 10:35:57 AM
Anyone knows how to do this on 2.0?
Title: Re: Disable deletion of yourself
Post by: Robert. on October 06, 2011, 10:56:21 AM
Check the post above yours..
Title: Re: Disable deletion of yourself
Post by: H3lioz on October 06, 2011, 11:18:56 AM
function deleteMembers($users, $check_not_admin = false)
{
   global $sourcedir, $modSettings, $user_info, $smcFunc;

Is nowhere in subs-members.php
Title: Re: Disable deletion of yourself
Post by: Robert. on October 06, 2011, 02:45:09 PM
It is for me.. o_O Check +/- line 85
Title: Re: Disable deletion of yourself
Post by: H3lioz on October 06, 2011, 03:50:25 PM
Oh now i found it ;D Thanks
Title: Re: Disable deletion of yourself
Post by: Chalky on March 19, 2012, 07:54:55 PM
Thanks, I just made the edits given in post #70.  Now how do I test it without deleting myself if it doesn't work?  Would my bco-admin be able to reinstate me and reassign me all my posts etc?

Edit: Doh!  I made an additional admin account, changed the numbers and tested by deleting that second admin account.  I found out this mod works great, as long as you don't use it in conjunction with the quick ban on delete mod - it doesn't seem to protect me from being banned  :P
Title: Re: Disable deletion of yourself
Post by: matricrsult on April 24, 2012, 03:04:20 AM
Great tip thanks for sharing