320 posts
  • Exclusive Author
  • Has been a member for 2-3 years
  • Malaysia
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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

883 posts
  • Author had a Free File of the Month
  • Microlancer Beta Tester
  • Has been a member for 3-4 years
  • Exclusive Author
  • Europe
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Referred between 50 and 99 users
  • Sold between 10 000 and 50 000 dollars
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…

320 posts
  • Exclusive Author
  • Has been a member for 2-3 years
  • Malaysia
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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.

308 posts
  • Attended a Community Meetup
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
  • Bought between 10 and 49 items
  • Has been a member for 2-3 years
  • Referred between 10 and 49 users
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

320 posts
  • Exclusive Author
  • Has been a member for 2-3 years
  • Malaysia
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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 :)

96 posts
  • Europe
  • Exclusive Author
  • Has been a member for 1-2 years
  • Sold between 10 000 and 50 000 dollars
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?

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
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 :)

96 posts
  • Europe
  • Exclusive Author
  • Has been a member for 1-2 years
  • Sold between 10 000 and 50 000 dollars
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