Hello There, Guest! › Register

MySubscriptions 2.2 released.
Looking for a custom plugin for your site? Ask here for a quote.

Hooks
#1

I guess I am confused about hooks.... I assumed if you hooked in to someone elses code, it would run yours.

PHP Code:
<?php
//the hook in the newpoints menu
$plugins->add_hook("newpoints_default_menu""add_menu");

// The information that shows up on the plugin manager
function buynewpoints_info(){
    return array(
        
"name" => "Buy NewPoints",
        
"description" => "The ability to buy NewPoints with paypal.",
        
"website" => "http://x3dev.com/",
        
"author" => "coreyman",
        
"authorsite" => "http://x3dev.com/",
        
"version" => "0.0.1",
        
"guid"             => "",
        
"compatibility"    => "*"
    
);
}

// This function runs when the plugin is activated.
function buynewpoints_activate(){
    require 
"../inc/adminfunctions_templates.php";
    global 
$db$mybb;
    
//check if newpoints is installed before we do any of this.
    
if(! $db->table_exists("newpoints_settings")){
        
//tell them NewPoints is not installed
        
flash_message('NewPoints is not installed.''error');
        
admin_redirect('index.php?module=config/plugins');
        exit;
    }

    
$BUYNEWPOINTS_MAINSETTINGS_group = array(
        
"gid" => "NULL",
        
"name" => "MainSettings",
        
"title" => "Buy NewPoints",
        
"description" => "Main settings for Buy NewPoints.",
        
"disporder" => "100",
        
"isdefault" => "no",
);

    
$db->insert_query("settinggroups"$BUYNEWPOINTS_MAINSETTINGS_group);
    
$gid $db->insert_id();

    
$BUYNEWPOINTS_setting_1 = array(
        
"sid" => "NULL",
        
"name" => "Button_Id",
        
"title" => "Button Id",
        
"description" => "The id of your paypal buy now button.",
        
"optionscode" => "text",
        
//Plugin types are "yesno"(radio button), "text"(single line), and "textarea".
        
"value" => "",
        
"disporder" => "1",
        
"gid" => intval($gid),
    );

    
$db->insert_query("settings"$BUYNEWPOINTS_setting_1);

}

// This function runs when the plugin is deactivated.
function buynewpoints_deactivate(){
    require 
'../inc/adminfunctions_templates.php';
    global 
$db;
    
//for some weird reason we have to include TABLE_PREFIX here and not in the insert_query
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='Button_Id'");
    
$db->query("DELETE FROM  ".TABLE_PREFIX."settinggroups WHERE name='MainSettings'");
}

//the function to add the option to buy to the menu
function add_menu(){
$menu[3] = '<a href="#">Buy NewPoints</a>';
}

?>

newpoints.php
PHP Code:
// build the menu

$menu = array();
// default menu options
$menu[0] = '<a href="'.$mybb->settings['bburl'].'/newpoints.php">'.$lang->newpoints_home.'</a>';
if (
$mybb->settings['newpoints_main_statsvisible'] == 1)
    
$menu[1] = '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=stats">'.$lang->newpoints_statistics.'</a>';
if (
$mybb->settings['newpoints_main_donationsenabled'] == 1)
    
$menu[2] = '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=donate">'.$lang->newpoints_donate.'</a>';

    
$plugins->run_hooks("newpoints_default_menu"); 

I want to hook in right there and add a menu option Sad
#2

globalize $menu and add it Smile (add global $menu; before $menu[3] = '<a href="#">Buy NewPoints</a>'; )
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.
#3

(11-23-2009, 08:18 AM)Pirata Nervo Wrote: globalize $menu and add it Smile (add global $menu; before $menu[3] = '<a href="#">Buy NewPoints</a>'; )

I figured it would just plug the code in the function in and not mess with scope.
#4

What do you mean?
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.
#5

Yea I don't even know what I was thinking... Tongue
If I wanted to hook some javascript into the header, how would I go about doing that?

I searched the hooks list for header and I only found admin header.

Maybe what I'm trying to do isn't even hooking but modifying a template, if so.... how do I modify a template?
#6

You must modify the headerinclude template, take a look at a plugin which edits templates. I believe the hello world plugin does it
To download our paid plugins and receive support you must be a paid subscriber. Click here for more information.




Users browsing this thread: 1 Guest(s)