MyBB Community Forums

Full Version: MyBB Plugin Code help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Introduction:
Hey guys, Sorry to bother you all but by asking questions you learn. I've been learning PHP and I've needed to make my own MyBB plugin as the only ones I found I need are either paid for or don't work how I want them to.

What I need:
I need a plugin that stops people creating a new thread in a certain forum if they have less than X posts and are in a certain Group. I coded what I thought would work based off another persons plugin to stop viewing certain threads if you don't have X posts and are in a certain Group. However, my version won't work, I think it could be the function at fault or I have the wrong hook, so i need somebody to help me out.

The code:

It's based off the "Posts required to access threads" plugin as said, so it will look similar.
 <?php
     
    /********************************************************************************
     *
     *  Posts required to post in forums
     *  Author: SirGravzy
     *  Copyright: © 2013 SirGravzy
     *  Sourced based on: PRAT by Pratik Unadkat (crazy4cs)
     *  
     *  Website: http://www.youtubelers.com
     *  License: license.txt
     *
     *  Requires specified post count set by admin to post threads in specific forums.
     *
     ********************************************************************************/
     
    if(!defined("IN_MYBB"))
            die("This file cannot be accessed directly.");
     
    $plugins->add_hook("newthread_do_newthread_start", "ptct");
     
     
    function ptct_info()
    {
            return array(
                    "name"                  => "Posts to create threads.",
                    "description"   => "Allows admin to set the number of posts required to post a thread in a forum.",
                    "website"               => "http://www.youtubelers.com",
                    "version"               => "1.0",
                    "author"                => "SirGravzy",
                    "authorsite"    => "http://www.youtubelers.com",
                    "compatibility"  => "16*",
                    'guid'        => "aa56c67f00f9013e92e625f2181416k5"
            );
    }
    function ptct_activate()
    {
            global $db;
           
    $settings_group = array(
                    'name' => 'ptct',
                    'title' => 'Posts to create threads.',
                    'description' => 'Settings for posts to create new thread plugin.',
                    'disporder' => '1',
                    'isdefault' => 'no'
            );
            $db->insert_query('settinggroups',$settings_group);
            $gid = $db->insert_id();
           
            $setting1 = array(
                    'name' => 'Plugin_enabled',
                    'title' => 'Want to enable this plugin?',
                    'description' => 'By enabling this, the plugin settings will take effect.',
                    'optionscode' => 'yesno',
                    'value' => '0',
                    'disporder' => '2',
                    'gid' => intval($gid)
            );
            $db->insert_query('settings',$setting1);
     
            $ptct_posts = array(
                    "name" => "ptct_posts",
                    "title" => "Required posts to create new thread.",
                    "description" => "Enter how much posts are needed to create a new thread.",
                    "optionscode" => "text",
                    "value" => "",
                    "disporder" => "3",
                    "gid" => intval($gid),
                    );
            $db->insert_query("settings", $ptct_posts);
     
         $ptct_gid = array(
                    "name" => "ptct_gid",
                    "title" => "Group IDs to restrict.",
                    "description" => "Enter which GIDs (Group IDs) are restricted by this plugin, separate each gid with a comma.",
                    "optionscode" => "text",
                    "value" => "",
                    "disporder" => "4",
                    "gid" => intval($gid),
                    );
            $db->insert_query("settings", $ptct_gid);
           
            $ptct_fid = array(
                    "name" => "ptct_fid",
                    "title" => "Active Forums.",
                    "description" => "Enter the forum id(s) of the forums you would the plugin to act on until the user has reached the required post count. Separate each tid with a comma>.",
                    "optionscode" => "text",
                    "value" => "",
                    "disporder" => "5",
                    "gid" => intval($gid),
                    );
            $db->insert_query("settings", $ptct_fid);
           
    rebuild_settings();
    }
     
    function ptct_deactivate()
    {
            global $db;
     
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='ptct'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='ptct_enabled'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='ptct_posts'");            
    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='ptct_gid'");      
    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='ptct_fid'");
     
    rebuild_settings();
    }
           
     
    function ptct()
    {
    global $fid, $mybb, $db;       
     
    $groups = explode(',', $mybb->settings['ptct_gid']);
    $posts = explode(',', $mybb->settings['ptct_posts']);
    $forums = explode(',', $mybb->settings['ptct_fid']);
    $require = $mybb->settings['ptct_posts'] - $mybb->user['postnum'];
           
    if($mybb->settings['ptct_enabled'] == 1)
    {
     
    if($mybb->user['postnum'] < $mybb->settings['ptct_posts'] && in_array($fid, $forums) && in_array($mybb->user['usergroup'] , $groups))
    {
            error("To post a new thread in this forum you must have <strong>{$mybb->settings['ptct_posts']}</strong> already, you however only have <strong>{$mybb->user['postnum']}</strong> posts, so you need at least <strong>{$require}</strong> posts before you can post a new thread in this forum.");
    }
     
    }
    }
           
    ?>

I need it to take effect and stop anybody under the specified post count from posting a thread when the click the "New Thread" button in the forum.

Any help would be much appreciated Smile