Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Allow a theme to call a plugin's functions
#1
I am making a theme and have a plugin to add additional settings. The theme works without the plugin, the plugin just adds additional capabilities. I would rather not place plugin related functions inside the theme functions location. How can I call functions inside of the plugin/NAME/common_functions.php file inside of the Theme template.php? Sorry if there is an obvious answer, I thought I would find something in hooks but I didn't (new to developing for GetSimple).
Thanks!
Reply
#2
once the plugin is activated and the common_functions.php file has been included as part of the plugin, all the functions are available to your theme.
My Github Repos: Github
Website: DigiMute
Reply
#3
n00dles101 Wrote:once the plugin is activated and the common_functions.php file has been included as part of the plugin, all the functions are available to your theme.

I believe that is the case but it is not working. Do I need to do anything other than just putting the common_functions.php in the folder? Link it in NAME.php?

-NAME.php
-NAME/common_functions.php

UPDATE: Actually the problem may lie in the layout of common_functions.php, this is the skeleton of what I have:

Code:
<?php
/*
Plugin Name:
Description:
Version:
Author:
Author URI:
*/

/**
* FunctionName
*/

function function_name() { return true; }

/**
* Another Function
*
*
* @return int
*/
function another_function($value) {

return $value * 1000;
}
?>
Reply
#4
Shouldn't they always be available ? I thought the template system wasn't initialized until after plugins are loaded.

You should be able to just call them.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
in NAME.php make your you include the common_functions.php file. like this:

Code:
include GSPLUGINPATH.'/NAME/common_functions.php';
My Github Repos: Github
Website: DigiMute
Reply
#6
n00dles101 Wrote:in NAME.php make your you include the common_functions.php file. like this:

Code:
include GSPLUGINPATH.'/NAME/common_functions.php';

That's what I was thinking, however adding that gives me a "HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request". (The common_functions.php file is in plugins/NAME/common_functions.php) The permissions on it are rw-r--r-- (644). Changing to 755 didn't help.

UPDATE: I found that when outputting that include statement in the template.php file I got the following: /home/username/URL.com/plugins/NAME/common_functions.php. Removing the /home/username part removed the 500 error. But this now hard codes the location in. Also the template.php file still cannot call code inside common_functions.php

Update #3: Fixed it! Yay! Here is the published theme's forum post: http://get-simple.info/forum/post/31057/
Reply




Users browsing this thread: 1 Guest(s)