MyBB Community Forums

Full Version: How to sort all users then delete them by MySQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Absolutely no need to do it that way. See here and here.
(2018-10-23, 08:32 PM)Wires Wrote: [ -> ]Absolutely no need to do it that way. See here and here.

But how you make who can access the page?
I don't want anyone to just go into misc and erase database xD
There's multiple ways to make the page only accessible to you. You can tailor it to your UID, superadmins or the admin group. For example, to only allow access to your forum UID you would add the following near the top of the page:

if(!$mybb->user['uid'] == 1) {
error_no_permission();
}

This will display an error if a user who's UID is not 1 tries to access the page. You'd use the same method to check the user's usergroup. To check if they're a superadmin you'd need to use the is_super_admin function.

Something like this is probably dangerous to have on the front-end. Why not put it in the ACP instead?
$plugins->add_hook('misc_start', 'my_action');

// In the body of your plugin
function my_action()
{
    global $mybb, $templates, $lang, $header, $headerinclude, $footer;

    if($mybb->get_input('action') == 'myaction')
    {
        // Do something, for example I'll create a page using the hello_world_template

        // Add a breadcrumb
        add_breadcrumb('My Action', "misc.php?action=myaction");

if(isset($mybb->input['submit']) && $mybb->request_method == "post")
{
$uids = (int) $mybb->get_input('uids');
$lastact = (int) $mybb->get_input('lastact');

$db->delete_query("users", "uid < '".$uids."' AND newpoints=0 AND postnum=0 AND threadnum=0 AND lastvisit <= '".$lastact."' ");
} 

        // Using the misc_help template for the page wrapper
        eval("\$page = \"".$templates->get("misc_help")."\";");
        output_page($page);
    }
}

a miscphp page 
  <form method="post">
    <label>
      <p>
      USER ID to query <input type="number"  name="uids" />
      </p>
    <p>
    Last visit query <input type="number" name="lastact" />
    </p>
    </label>

    <p>
    <input type="submit" value="Delete" class="confirm"/>
    </p>
  </form>
  

would this work?

I don't know how to put it in acp i'm really newbie in this. Started learning one week ago.
You should consider using delete_user(). It also removes data from other tables referencing the user.
(2018-10-24, 03:29 PM)StefanT Wrote: [ -> ]You should consider using delete_user(). It also removes data from other tables referencing the user.

I'm not there yet Big Grin

I am currently learning the simplest things to do.
Pages: 1 2