Quick Fix needed with functions.php

Discussion in 'PHP' started by duanehaas, Jan 22, 2010.

  1. #1
    I am wanting to add this
    // Ondemand function to generate dynamic bit.ly urls
    function getBitlyUrl($url) {
        // fill up this 2 lines below with your login and api key
        $bitlylogin = 'mylogin';
        $bitlyapikey= 'myapi ';
    
        // you dont need to change below this line
        $bitlyurl = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitlylogin."&apiKey=".$bitlyapikey);  
    
        $bitlycontent = json_decode($bitlyurl,true);
    
        $bitlyerror = $bitlycontent["errorCode"];
    
        if ($bitlyerror == 0){
            $bitlyurl = $bitlycontent["results"][$url]["shortUrl"];
        }
        else $bitlyurl = $url;
    
        return $bitlyurl;
    }	
    Code (markup):
    To my functions.php file which contains this -

    <?php
    require_once(TEMPLATEPATH . '/controlpanel.php'); 
    if ( function_exists('register_sidebars') )
        register_sidebars(2);
    	 
    		register_sidebar(array('name'=>'Sidebar 3',
    		'before_widget' => '',
    		'after_widget' => '</li></ul></div>',
    		'before_title' => '<div class="sidebar3"><h2>',
    		'after_title' => '</h2><ul><li>',
    	)); 
    	 
    ?>
    PHP:
    But anywhere I add it, my admin panel messes up when I activate a plugin or empty my cache. Any help on exactly where in this file I should place this would help. Thanks!
     
    duanehaas, Jan 22, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Did you add it like this and it didn't work? What error showed?

    
    <?php
    require_once(TEMPLATEPATH . '/controlpanel.php'); 
    if ( function_exists('register_sidebars') )
        register_sidebars(2);
         
            register_sidebar(array('name'=>'Sidebar 3',
            'before_widget' => '',
            'after_widget' => '</li></ul></div>',
            'before_title' => '<div class="sidebar3"><h2>',
            'after_title' => '</h2><ul><li>',
        )); 
    
    // Ondemand function to generate dynamic bit.ly urls
    function getBitlyUrl($url) {
        // fill up this 2 lines below with your login and api key
        $bitlylogin = 'mylogin';
        $bitlyapikey= 'myapi ';
    
        // you dont need to change below this line
        $bitlyurl = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitlylogin."&apiKey=".$bitlyapikey);  
    
        $bitlycontent = json_decode($bitlyurl,true);
    
        $bitlyerror = $bitlycontent["errorCode"];
    
        if ($bitlyerror == 0){
            $bitlyurl = $bitlycontent["results"][$url]["shortUrl"];
        }
        else $bitlyurl = $url;
    
        return $bitlyurl;
    }     
    ?>
    
    Code (markup):
     
    s_ruben, Jan 23, 2010 IP
  3. duanehaas

    duanehaas Active Member

    Messages:
    153
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #3
    lol disregard... I have no clue what went wrong but it works now... maybe I just had to sleep on it
     
    duanehaas, Jan 23, 2010 IP