Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

Minimum characters Message and Title - MYBB

Ads
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#1
Support Team
Hi guys after seeing so many people trying to implement a function in MYBB forum script that will block any post if the message or title doesn't meet the requirements set by the Admin. We are going to create a plugin that will require a user to input a number of characters no less than specified when creating new topic/thread.

MYBB has a function to limit the MAX number of characters and function for minimum amount of characters but it affects all posts and doesn't really work with subject/title.

The way this plugin works is it stops any attempt to post or edit new topic or thread if the message or title is less than minimum characters required.

Save this file as minchar.php and upload it to: ./inc/plugins then go to your Admin Control Panel >> Plugins and activate it.

PHP Code:
<?php

// Disallow direct access to this file for security reasons DO NOT REMOVE
if(!defined("IN_MYBB"))
{
    die(
"Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("datahandler_post_validate_post""minchar");
$plugins->add_hook("datahandler_post_validate_thread""minchar");



function 
minchar_info()
{
    return array(
        
"name"            => "Min characters new topic",
        
"description"    => "Sets thread minimum subject & message lenght",
        
"website"        => "http://letsforum.com",
        
"author"        => "Victor Dub",
        
"authorsite"    => "http://letsforum.com",
        
"version"        => "1.0",
        
"guid"             => "",
        
"compatibility" => "16*"
    
);
}


function 
minchar(&$post)
{
    global 
$mybb$db;
   
     
$script basename($_SERVER["SCRIPT_FILENAME"]);
     
$msgcount message_countchars($post->data['message']);
     
$msgcountsubject message_countchars_subject($post->data['subject']);

     if (
$script == 'editpost.php' || $script == 'xmlhttp.php') {
        
$query $db->simple_select("threads""*""`firstpost`=".intval($_GET['pid'])); 

        
$thepost $db->fetch_array($query);

       if (!empty(
$thepost)) {
            
$firstpost true;
       }
    }
    if ((
$script == 'editpost.php' && $firstpost) || $script == 'newthread.php') {
        if (
$msgcount 200) {
            
$post->set_error('Your message must be at least "200" characters long.');
        }
        if (
$msgcountsubject 10) {
           
$post->set_error('Your subject must be at least "10" characters long.');
            }
    } 
    if ((
$script == 'xmlhttp.php' && $firstpost)) {
        if (
$msgcount 200) {
            
$post->set_error('Your message must be at least "200" characters long.');
        }
    }

}

?>

To change subject/title minimum character length edit this code:
PHP Code:
if ($msgcountsubject 10) {
           
$post->set_error('Your subject must be at least "10" characters long.');
            } 

To change message minimum character length edit these codes:
PHP Code:
if (($script == 'editpost.php' && $firstpost) || $script == 'newthread.php') {
        if (
$msgcount 200) {
            
$post->set_error('Your message must be at least "200" characters long.'); 

And:
PHP Code:
if (($script == 'xmlhttp.php' && $firstpost)) {
        if (
$msgcount 200) {
            
$post->set_error('Your message must be at least "200" characters long.'); 

That is it ladies if you have further questions please feel free to ask.
hellboy Offline referral

Posts: 92
Joined: May 2014
Reputation: 0

#2
Member
Thanks, could you please explain how MYBB plugin works?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#3
Support Team
(05-22-2014 06:31 PM)hellboy Wrote:  Thanks, could you please explain how MYBB plugin works?

Plugin is just an extension of core file. You hook to a core file and make code that is in the plugin part of the core file without actually modifying it.
antony Offline referral

Posts: 478
Joined: Jul 2013
Reputation: 5

#4
Senior Member
Thanks Marcus I will give it a try. Many say that for SEO purposes post has to be min 300 characters long.





User(s) browsing this thread: 1 Guest(s)