WordPress.org

Ready to get started?Download WordPress

Forums

How do I get_option when not logged in? (1 post)

  1. macgamer
    Member
    Posted 10 months ago #

    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');
    		wp_enqueue_script(
    			'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.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.