carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

carbon_get_theme_option() doesn't allways retrieve datas

Open sebastienserre opened this issue 7 years ago • 4 comments

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

  1. 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

sebastienserre avatar Dec 19 '18 06:12 sebastienserre

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?

vvasilev- avatar Dec 19 '18 12:12 vvasilev-

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?

sebastienserre avatar Dec 19 '18 15:12 sebastienserre

I succed to get the value by using get_option(_wpgc_gestsup_db)

sebastienserre avatar Dec 20 '18 07:12 sebastienserre

I succed to get the value by using get_option(_wpgc_gestsup_db)

Thank Mate, This Technic really work !

coder618 avatar Sep 09 '20 08:09 coder618