MyBB Community Forums

Full Version: Why wont my plugin work?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm trying to make this into a plugin and idk what im doing wrong

if(!defined("IN_MYBB")) die();

$plugins->add_hook("postbit","coinurlposts_postbit");

function coinurlposts_getCoinUrl($url) {
    $uuid = "518d8d0ee1ee5172488964"; // Change this
           
    $url = rawurlencode($url);
    
    $result = file_get_contents("http://coinurl.com/api.php?uuid={$uuid}&url={$url}");
    
    if($result == 'error')
        return 'href="#"';
    else
        return 'href="'.$result.'"';
}

function coinurlposts_postbit($post) {
    global $mybb;
    $post['message'] = preg_replace('/href\=\"([^\s"]+)\"/e', 'coinurlposts_getCoinUrl("$1")', $post['message']);
    
    return $post;
} 
<snip>
Sad I just came to look at your post and you snipped it -_-
You can't modify the $post array unless you get the argument by reference, because the postbit hook is placed inside a function.

function coinurlposts_postbit(&$post) {
    // do stuff
} 

The hook by reference should be used whenever a hook is placed inside a function and therefore its scope isn't the global one.