Im struggling a bit, i can’t pass variable between functions. many examples show the code as i tested but it won’t work for me for some reason.
Im building theme for wordpress and i need options panel for a theme.
For options panel i have a function that is called options_theme() and that function should display options page.
But as i want dynamic fields i have build 2 more functions theme_options() which is an array of fields, and another is theme_fields() which display fields based on theme_options() array. This is not a problem because this works, but im just explaining what are those functions.
Problem is that i want dynamic fields which can be reusable many times and for that i just need to switch calling theme_options on each function separately.
This is the code i have for now: this is admin/index.php page which holds function that display fields with their options
function options_theme() {
require_once( THEMEPATH . 'admin/fields.php' );
global $settings, $options;
$settings = get_option($option_name);
$options =& _theme_options();
<-- Here goes some html for options page -->
now display fields
theme_fields()
}
The function above should set options name in $settings and get an array of theme options in $options than finally display fields in theme_fields.
Problem is that i get an error that $options and $settings are not set.
This is how functions theme_fields() works
function theme_fields() {
global $settings, $options;
foreach( $options as $field) {
display fields
}
}
To be able to use theme_fields() on different pages i need to be able to set $options and $settings per page, for that i need to set $options and $settings outside of theme_fields() like in example i posted above. but it doesn’t work.
If i set it like this
function theme_fields() {
$settings = get_option($option_name);
$options =& _theme_options();
foreach( $options as $field) {
display fields
}
}
it works.
How do i set values of $settings and $options outside theme_fields() so i can use it multiple times on different pages like this.
function options_theme() {
require_once( THEMEPATH . 'admin/fields.php' );
global $settings, $options;
$settings = get_option($option_name);
$options =& _theme_options();
<-- Here goes some html for options page -->
now display fields
theme_fields()
}
function options_widgets() {
require_once( THEMEPATH . 'admin/fields.php' );
global $settings, $options;
$settings = get_option($option_name);
$options =& _theme_widgets();
<-- Here goes some html for options page -->
now display fields
theme_fields()
}