357 posts
  • Has been part of the Envato Community for over 2 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Sells items exclusively on Envato Market
+1 more
billyf says

Hello,

I wonder how can I retrieve my settings in my theme’s functions.php file? Normally, I would just need to use the codes below to get my settings:
global $data
$something = $data['something'];
However, when I do that in my functions.php file, it will not work. Has anyone discovered any way to obtain the settings set by SMOF in that file so that I can use it in my post edit page?

Thanks for helping and have a great day!

PS : Here is the link to the framework https://github.com/sy4mil/Options-Framework

1136 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
Smartik says

Not tested!

Try to create a new php file custom_functions.php (for example) and add the scripts here and include this file in functions.php

Hope this works…

357 posts
  • Has been part of the Envato Community for over 2 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Sells items exclusively on Envato Market
+1 more
billyf says

Not tested!

Try to create a new php file custom_functions.php (for example) and add the scripts here and include this file in functions.php

Hope this works…
Thanks for the suggestion. Unfortunately, it didn’t work.

Anyone has any other ideas? Thanks for helping.

316 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
+2 more
SyamilMJ says

The $data variable is set somewhere in the admin-interface file, so if you try to use $data before they were queued in functions.php (and therefore not defined yet) then you won’t be getting any values.

You have two ways to solve this:

1 – queue SMOF at the very top of your functions.php, or at least before where you to start be able to use $data

2 – define a new var e.g $my_data = get_options(‘my-options-name’);

The caveat for the second method is that it will always get the “old” data from the table, instead of the newer one the options were updated. Therefore I’d recommend #1 as it’s also a lot easier too.

Cheers

357 posts
  • Has been part of the Envato Community for over 2 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Sells items exclusively on Envato Market
+1 more
billyf says

Hi Syamil,

Thanks for your reply. Unfortunately, the first method didn’t work for me. So, I am now using get_option to retrieve the settings from SMOF (in an array) and it seems to update correctly to the latest settings.

Thanks for helping :)

173 posts
  • Has been part of the Envato Community for over 1 year
  • Has sold $10,000+ on Envato Market
  • Located in Europe
  • Sells items exclusively on Envato Market
subsolar says

I know this is one year old thread but none of the two methods seem to work with the new $smof_data variable.

1 – When I put the global declaration at the top of the functions.php it cannot be reached from a the function.

2 – Gives me “Call to undefined function get_options()”.

I’m trying to fire up a function useing the hook ‘wp_enqueue_scripts’. Can someone help?

576 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
Gareth_Gillman says

the following code works for me:

// Admin panel options become usable
 global $data; 
 // Options Panel
 require_once ('admin/index.php');

they are the first lines in the functions.php (after the <? php )

Now for the enqueue I do the following:

function scripts() {
 global $data;
 $slider = $data['home_slider'];
 if ( !is_admin() && $slider=='FlexSlider') {
  wp_register_script('flex',  get_template_directory_uri() . '/js/sliders/flexslider.js', false);
  wp_enqueue_script('flex');
 }

I had to add the $data into each function or I got the same error as you do.

Hopefully that works for you :)

173 posts
  • Has been part of the Envato Community for over 1 year
  • Has sold $10,000+ on Envato Market
  • Located in Europe
  • Sells items exclusively on Envato Market
subsolar says

Hey, thanks for replying!

I tried your code, but it didn’t worked. I did a ‘print_r’ just after the require part and it seems that the array is not full with all the keys and values. It fills itself completely just after I click on “Options Reset” – but I have to do this on every new installation of the theme :(

A function like this (written in functions.php)
function my_register_googlefonts() {

global $smof_data;

    if( $smof_data['body_google_checkbox'] ) {
        ....
    }
} 
... gives me “Undefined index: body_google_checkbox” :/

I’ve also declared the global variable in header.php and footer.php, because I’m using it in some functions there.

by
by
by
by
by
by