carbon_get_theme_option() doesn't allways retrieve datas
Version
- Carbon Fields: 3.0
- WordPress: 5.0.1
- PHP: 7.2
Expected Behavior
Get Data stored
Actual Behavior
return Null on separate class
Container definition
Container::make( 'theme_options', __( 'Gestsup Connector' ) )
->set_page_parent( 'options-general.php' )
->add_tab( __( 'GestSup Database', 'wp-gestsup-connector' ),
array(
Field::make( 'text', 'wpgc_gestsup_host', __( 'Host', 'wp-gestsup-connector' ) ),
Field::make( 'text', 'wpgc_gestsup_db', __( 'Database', 'wp-gestsup-connector' ) ),
Field::make( 'text', 'wpgc_gestsup_username', __( 'Username', 'wp-gestsup-connector' ) ),
Field::make( 'text', 'wpgc_gestsup_passwd', __( 'password', 'wp-gestsup-connector' ) ),
)
);
Steps to Reproduce the Problem
- create another class to create a connexion to thnis external db.
$server = carbon_get_theme_option( 'wpgc_gestsup_host' );
$db = carbon_get_theme_option( 'wpgc_gestsup_db' );
$user = carbon_get_theme_option( 'wpgc_gestsup_username' );
$password = carbon_get_theme_option( 'wpgc_gestsup_passwd' );
return null
Hi @sebastienserre,
Perhaps you're trying to get the data too early. Can you tell us when you're creating the instance of your class?
Hello @vvasilev- I'm trying to carbon_get_theme_option() on the admin_init hook. I'm loading the options class where the theme option page is created then I'm loading the second one which should get the data
I'm using the option in the WP Admin area... maybe I need to add some info?
I succed to get the value by using get_option(_wpgc_gestsup_db)
I succed to get the value by using
get_option(_wpgc_gestsup_db)
Thank Mate, This Technic really work !