Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Odai Athamneh on "Widget Options Saved, But Not Displaying On Site"

$
0
0

I'm fairly new to WordPress development. I created a simple plugin that displays author info as a sidebar widget when viewing a single post.

I've been working on an update, trying to add options to the widget. Here's the code (sorry for length):

<?php
;/*
Plugin Name: Odai Author Widget
Plugin URI: http://odai.me/author-widget/
Description: Widget that displays the current post author's Gravatar photo, name, website, and biography.
Version: 1.0.0
Author: Odai
Author URI: http://odai.me
License: GPLv2
*/

//establish the widget
add_action( 'widgets_init', 'odai_author_widget_register' );

function odai_author_widget_register() {
	return register_widget( 'OdaiAuthorWidget' );
	}

class OdaiAuthorWidget extends WP_Widget {

	function __construct() {
		parent::__construct('odai_author_widget_', 'Odai Author Widget', array('description' => __( "Displays post author's Gravatar photo and biographical info", 'text_domain' ),) );
	}

	function widget () {
		$title = get_option('odai_aw_title', 'About the Author');
		$odai_aw_pic_size = 96;

		if(is_single()) {
		?>
		<aside id="odai-author-widget" class="widget">
		<h3 class="widget-title"><?php echo $title; ?></h3>
		<?php get_avatar(get_the_author_meta('user_email'), $odai_aw_pic_size); ?>
		<br />Name:&nbsp;<?php get_the_author_meta('display_name'); ?>
		<br />Website:&nbsp;<a href="<?php get_the_author_meta('user_url'); ?>"><?php get_the_author_meta('user_url'); ?></a>
		<p><?php get_the_author_meta('description'); ?></p>
		</aside>
		<?php
		}
	}

	function update($newinstance,$oldinstance) {
		$instance =  $oldinstance;
    		$instance['odai_aw_title'] =  $newinstance['odai_aw_title'];
    		return $instance;
	}

	function form ($config) {
		?>
    		<label for='<?php echo $this->get_field_id("title");  ?>'>
    		<p>Title: <input type="text"  value="<?php echo $config['title']; ?>" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title') ?>"></p>
    		</label>
		<?php
	}
}

//adding options to the database
register_activation_hook( __FILE__, 'odai_aw_add_options' );
register_deactivation_hook( __FILE__, 'odai_aw_remove_options' );

function odai_aw_add_options () {
		update_option('title', 'About the Author');
	}

function odai_aw_remove_options () {
		delete_option('title');
	}

So right now, I'm just trying to get the title option working. The form is there, I can save a new title (changes in the widget admin area), but on the website itself, it continues to display the default "About the Author" text. What am I doing wrong?

Also, feel free to suggest improvements to any aspect of the code - I'm sure it's far from perfect, as I've been learning as I go.


Viewing all articles
Browse latest Browse all 8245

Trending Articles