734 posts
  • Beta Tester
  • 3 Years of Membership
  • Author Level 6
  • Affiliate Level 1
+2 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

1368 posts
  • Weekly Top Seller
  • 5 Years of Membership
  • Author Level 6
  • Beta Tester
+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…

734 posts
  • Beta Tester
  • 3 Years of Membership
  • Author Level 6
  • Affiliate Level 1
+2 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
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • 4 Years of Membership
+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

734 posts
  • Beta Tester
  • 3 Years of Membership
  • Author Level 6
  • Affiliate Level 1
+2 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 :)

337 posts
  • 2 Years of Membership
  • Affiliate Level 2
  • Author Level 6
  • Exclusive Author
+2 more
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?

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 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 :)

337 posts
  • 2 Years of Membership
  • Affiliate Level 2
  • Author Level 6
  • Exclusive Author
+2 more
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.

2 posts
  • Indonesia
adiperdana
says

Hello Syamil, i have some question of SMOF

When i activate the SMOF on my custom wordpress theme, why i see this message :

“Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\smof\wp-content\themes\twentyfifteen\admin\functions\functions.filters.php on line 23”

And when I replace it with my own Options Panel, SMOF not work properly.

Please Reply This Message. Thanks a lot.

734 posts
  • Beta Tester
  • 3 Years of Membership
  • Author Level 6
  • Affiliate Level 1
+2 more
billyf
says

Hello Syamil, i have some question of SMOF

When i activate the SMOF on my custom wordpress theme, why i see this message :

“Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\smof\wp-content\themes\twentyfifteen\admin\functions\functions.filters.php on line 23”

And when I replace it with my own Options Panel, SMOF not work properly.

Please Reply This Message. Thanks a lot.

Hi, you might want to switch to Redux Framework since the development on SMOF has ceased after it’s joined with Redux.

by
by
by
by
by
by