MyBB Community Forums

Full Version: making 1st plugin - hooks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hiya so i decided to try make a plugin where a user is private messaged when they are quoted. I am very new to publishing plugins so apologies but what hooks would i need or how can i find out? Thanks Big Grin

~ David
Here's a list: http://wiki.mybb.com/index.php/MyBB_Plugin_Hooks

You'd probably use newreply_do_newreply_end.
(2011-12-18, 11:05 PM)pyridine Wrote: [ -> ]Here's a list: http://wiki.mybb.com/index.php/MyBB_Plugin_Hooks

You'd probably use newreply_do_newreply_end.

Thanks for the reply Smile
Would i just need that one hook like this:
$plugins->add_hook("newreply_do_newreply_end", "foo_functionname");
(what would the foo_functionname be?)
or:
$plugins->run_hooks("newreply_do_newreply_end");
Cheers, Smile

~ David

Yes, you'd add the hook with

$plugins->add_hook("newreply_do_newreply_end", "foo_functionname");

and foo_functionname would be changed to the name of your function, so you'd then do

function foo_functionname() {
// code here
}

and it'd call foo_functionname when the newreply_do_newreply_end hook is run.
The second parameter is just the function the hook is calling. It is usually the name of the plugin.

$plugins->add-hook("hook", "function_name");

function function_name() {
    //This is what happens with the function.
}
Hiya guys, thanks for all your replies Smile
This is my current code:
<?php
/**
 * PMQuote 1.0
 * 2011© PMQuote 1.0 Made by Vernier
 * http://www.habfab.com
 */
if(!defined("IN_MYBB"))
{
    die("You Cannot Access This File Directly");
}
$plugins->add_hook("newreply_do_newreply_end", "hello"); 
function pmquote_info()
{
return array(
        "name"  => "pmquote",
        "description"=> "Allows Private messages to be sent to users when they are quoted in posts",
        "website"        => "http://www.habfab.com",
        "author"        => "Vernier",
        "authorsite"    => "http://www.habfab.com",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "*"
    );
}
function pmquote_activate()
  {
    global $db;
    
   $setting_group = array(
        'gid'    => 'NULL',
        'name'  => 'pmquote',
        'title'      => 'pmquote',
        'description'    => 'Settings For YourPlugin',
        'disporder'    => "1",
        'isdefault'  => 'no',
    );
	$db->insert_query('settinggroups', $setting_group);
	$gid = $db->insert_id();
   
   $pmquote_setting = array(
        'sid'            => 'NULL',
        'name'        => 'enabled_pmquote',
        'title'            => 'Do you want YourPlugin Enabled',
        'description'    => 'If Yes People Can Use YourPlugin, If No People Cannot Use YourPlugin.',
        'optionscode'    => 'yesno',
        'value'        => '1',
        'disporder'        => 1,
        'gid'            => intval($gid),
    );
     $db->insert_query('settings', $pmquote_setting);
  rebuild_settings();
  }
  function pmquote_deactivate()
  {
  global $db;
 $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('enabled_yourplugin')");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='yourplugin'");
rebuild_settings();
 }
function hello(){
global $mybb;
if ($mybb->settings['enabled_yourplugin'] == 1){
echo "<center><h1>pmquote Works!</h1><br />Try To Disable The Plugin :) You'll See This Text Will Hide..";
}
}
?>

What else would I need to add? What hooks am I missing? Thanks so much! Big Grin

~ David

I'm guessing this hook would need to be added?
 213     parse_quoted_message                              $quoted_post

Cheers,

~ David
Sorry for bump but has anyone got any ideas on which hooks or coding i need to add, really want to get this plugin working! Big Grin

Thanks so much guys! Big Grin

~ David
You're missing a lot of code from the function. You've to check if the user has quoted any one or not, you also need to send a PM if the check is true.
Any idea what function or hooks that would be? Cheers Smile

~ David
See this plugin and know how he has utilized it: http://mods.mybb.com/view/tagging-plugin
Pages: 1 2