Support » Plugins » How do I get_option when not logged in?

  • macgamer


    Here’s a snippet from my plugin class:

    public function __construct() {
    		register_activation_hook(__FILE__,array(__CLASS__, 'install' ));
    		register_uninstall_hook(__FILE__,array( __CLASS__, 'uninstall' ));
    		add_action('init', array( $this, 'init' ));
    		add_action('admin_init', array( $this, 'admin_init' ));
    		add_action('admin_menu', array($this,'pluginSettings'));
    public function admin_init() {
    	    register_setting('safaripush', 'safaripush', array($this, 'validateOptions'));
    	    add_settings_section('default-safaripush', 'Default Settings', array($this, 'initDefaultSettings'), 'safaripush');
    	    add_settings_field('safaripush-web-service-url', 'Web Service URL', array($this, 'webServiceURLInput'), 'safaripush', 'default-safaripush');
    	    add_settings_field('safaripush-website-push-id', 'Website Push ID', array($this, 'websitePushIDInput'), 'safaripush', 'default-safaripush');
    public function init() {
    		add_action('wp_enqueue_scripts', array($this, 'enqueuescripts'));

    This is all working fine, except when I try to retrieve the settings:

    function enqueuescripts() {
    		$options = get_option('safaripush');
    			plugins_url( '/js/safari-push.js' , __FILE__ ),
    			array( 'jquery' )
    		$params = array(
    			'token' => "",
    			'id' => "",
    			'webServiceURL' => $options['web-service-url'],
    			'websitePushID' => $options['website-push-id'],
    			'userInfo' => ""
    		wp_localize_script( 'safaripush', 'SafariPushParams', $params );

    This works when I am logged in, but when I’m not, the $options returns null.

  • The topic ‘How do I get_option when not logged in?’ is closed to new replies.