Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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?

Code:
$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 />
			</div>
        
		<?php
    }
 
    //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 = '" />';
        extract($args);
        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..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.