File containing variables and functions

Discussion in 'WordPress' started by lelkoun, Apr 2, 2011.

  1. #1
    I need to store variables and functions that are used in the main plugin's file and plugin's options file in one file for easier future editing. The problem is, that PHP does not allow it (redeclaration error). What should I do to fix it? Thanks.

    Main plugin's file:

    
    include("sb-common-declarations.php"); //load multiple used declarations
    
    //some code
    //...
    
    function spammer_blocker_options(){ //load options page
    
    	include("sb-common-declarations.php"); //load multiple used declarations
    
    	include("sb-options.php");
    
    }
    
    function spammer_blocker(){ //add a link to menu
    
    	add_options_page('Spammer Blocker', 'Spammer Blocker', administrator, 'spammer-blocker', 'spammer_blocker_options');
    
    }
    
    
    
    	add_action('admin_menu', 'spammer_blocker');
    PHP:
     
    Last edited: Apr 2, 2011
    lelkoun, Apr 2, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The file is being included more than once. Try using include_once("sb-common-declarations.php");
     
    Cash Nebula, Apr 2, 2011 IP