Wrox Programmer Forums
BOOK: Professional WordPress Plugin Development
This is the forum to discuss the Wrox book Professional WordPress Plugin Development by Brad Williams, Ozh Richard, Justin Tadlock; ISBN: 978-0-470-91622-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional WordPress Plugin Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 26th, 2011, 05:06 AM
Registered User
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't Get Test Plugin To Save Updates...

I copied this pretty much straight from the book and adapted it. It has a simple widget option, but I can't get the setting to save and I've been all through chapter four trying to figure out where I went wrong and I don't see it.

I tried to keep it very simple for my first attempt. The widget works in all ways except it does not have a selected option, the default argument is not passing to the variable, but even when I set it manually with if (!$size)... there is still no option selected. Also after selecting and saving, the options unset on reload.

Does anyone see my error?

$inm_ccd_file = "catalyst-certified-developer-plugin.php";

register_activation_hook( plugin_dir_path($inm_ccd_file), 'inm_ccd_install' );

function inm_ccd_install() {
    if ( version_compare( get_bloginfo( 'version' ), '3.1', '<' ) ) {
        deactivate_plugins( basename( plugin_dir_path($inm_ccd_file) ) ); // Deactivate our plugin

register_deactivation_hook( $inm_ccd_file_path, "inm_ccd_uninstall" );

function inm_ccd_uninstall() {

// use widgets_init action hook to execute custom function
add_action( 'widgets_init', 'inm_ccd_image_display_widget_register_widgets' );

 //register our widget
function inm_ccd_image_display_widget_register_widgets() {
    register_widget( 'inm_ccd_image_display_widget' );

// include 'includes/inm-ccd-widget.php';

//inm_ccd_image_display_widget class
class inm_ccd_image_display_widget extends WP_Widget {

    //process the new widget
    function inm_ccd_image_display_widget() {
        $widget_ops = array( 
			'classname' => 'inm_ccd_image_display_widget_class', 
			'description' => 'Display a Catalyst Certified Developer badge.' 
        $this->WP_Widget( 'inm_ccd_image_display_widget', 'Catalyst | Cert. Dev. Badge', $widget_ops );
     //build the widget settings form
    function form($instance) {
		$image_url = " [path to my images] ";
        $defaults = array( 
			'size' => 'catalyst-certified-70.png'
        $instance = wp_parse_args( (array) $instance, $defaults );
		$size = $instance['size'];
		if(!$size) $size = "catalyst-certified-30.png";
            <div align="center" style="text-align: left;"><img width="20%" height="20%" src="<?php echo $image_url . $size; ?>" /><br /><br />
			&nbsp;&nbsp;&nbsp;<input type="radio" name="size" value="<?php echo $image_url; ?>catalyst-certified-30.png" <?php selected($size, 'catalyst-certified-30.png') ?> > Small (136 x 67)<br />
			&nbsp;&nbsp;&nbsp;<input type="radio" name="size" value="<?php echo $image_url; ?>catalyst-certified-70.png" <?php selected($size, 'catalyst-certified-70.png') ?> > Large (316 x 155)<br />
    //save the widget settings
    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        $instance['size'] = strip_tags($new_instance['size']);
		return $instance;
    //display the widget
    function widget($args, $instance) {
		$inm_ccd_pre_image = '<img src="';
		$inm_ccd_post_image = '" />';
        echo $before_widget;
		$size = empty( $instance['size'] ) ? ' [path to my images] ' : $instance['size'];
        echo $inm_ccd_pre_image.$size.$inm_ccd_post_image;
		echo $after_widget;

Last edited by surfjam; April 26th, 2011 at 02:39 PM..

Similar Threads
Thread Thread Starter Forum Replies Last Post
Servoy Plugin elizas MySQL 1 January 27th, 2010 09:23 AM
Audio Plugin itHighway Classic ASP Basics 1 December 12th, 2005 02:53 PM
Creating Struts Plugin crystal123 BOOK: Professional Jakarta Struts 1 November 21st, 2005 05:58 PM
Audio Plugin itHighway Classic ASP Components 1 January 31st, 2005 01:20 PM
getdatasource in plugin ashok BOOK: Professional Jakarta Struts 0 July 1st, 2004 03:32 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.