MyBB Community Forums

Full Version: Core Edit! NewThread & EditPost
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi how can I manually set min tittle and message length in newthread.php and editpost.php?
I don't recommend you to do core edits, that's just extra trouble for when you want to update your platform, make use of hooks instead.

<?php
// Hooks
$plugins->add_hook('datahandler_post_validate_thread', 'FancyPlugin_content');
$plugins->add_hook('datahandler_post_validate_post', 'FancyPlugin_content');

function FancyPlugin_info(){
    return array(
        "name"            => "Your fancy plug-in",
        "description"    => "Let's check some lengths",
        "website"        => "http://mybb.com",
        "author"        => "marcus",
        "authorsite"    => "http://mybb.com",
        "guid" => "",
        "version" => "1.0",
        "compatibility" => "16*"
    );
}

function FancyPlugin_content($data) {
	global $mybb, $db;
	
	// $data contains post/thread info
	
	$data->set_error(print_r($data, true));
	
	// $data->set_error('Error message')
	
	return $data;
}
?>

(Make sure to save it as FancyPlugin.php)

I guess this can be a good starting point. You can figure out the variable names in $data and set an error if required. I just took this code from a plug-in of mine and changed function names, I haven't personally tested it and I don't recommend using this on a live website before you make sure that it really works.

Edit: I just realized that there is a Minimum Message Length configuration variable as well. You can use the plugin approach to have custom value per usergroup I guess.
Thanks buddy but the issue is

$plugins->add_hook('datahandler_post_validate_post', 'FancyPlugin_content');

will also check replies but I only want editpost and newthread

Thanks for your code
$_SERVER['SCRIPT_FILENAME'] will do the trick, combined with basename.

<?php
// Hooks
$plugins->add_hook('datahandler_post_validate_thread', 'FancyPlugin_content');
$plugins->add_hook('datahandler_post_validate_post', 'FancyPlugin_content');

function FancyPlugin_info(){
    return array(
        "name"            => "Your fancy plug-in",
        "description"    => "Let's check some lengths",
        "website"        => "http://mybb.com",
        "author"        => "marcus",
        "authorsite"    => "http://mybb.com",
        "guid" => "",
        "version" => "1.0",
        "compatibility" => "16*"
    );
}

function FancyPlugin_content($data) {
	$script = basename($_SERVER["SCRIPT_FILENAME"]);
	if ($script == 'editpost.php' || $script == 'newthread.php') {
		if (strlen($data->data['message']) < 30) {
			$data->set_error('Your message must be at least 30 characters long');
		}
	}
}
?>
OMG buddy thank you so much I can't thank you enough for this code nobody seemed to know how to do that +1 from me and +100 thanks Smile
(2014-01-10, 03:12 PM)marcus123 Wrote: [ -> ]OMG buddy thank you so much I can't thank you enough for this code nobody seemed to know how to do that +1 from me and +100 thanks Smile

You're welcome, Marcus.