What did I do wrong? Second variable is not saving or displaying
-
I am attempting my first custom plugin for a project and it seems to be about 90% working (somehow). I am able to save the title but not the URL for the second variable (event url) to save or work. I used a sample plugin for a template but all the examples I am seeing only have 1 variable to save. Can someone look at my code and tell me why the event_url doesnt work.
<?php /* Plugin Name: College of Engineering Events Widget Plugin URI: http://creative.umich.edu Description: Plugin created to display the events from the college of engineering sites Version: 1.0 Author: Michigan Creative, Wally Kolcz Author URI: http://creative.umich.edu License: GPL2 */ class CoE_Events extends WP_Widget { function CoE_Events(){ $widget_ops = array('classname' => 'CoE_Events', 'description' => 'Plugin created to display the events from the college of engineering sites' ); $this->WP_Widget('CoE_Events', 'CoE Events', $widget_ops); } function form($instance){ $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'event_url'=>'' ) ); $title = $instance['title']; $url = $instance['event_url']; ?> <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p> <p><label for="<?php echo $this->get_field_id('event_url'); ?>">Events Feed URL: <input class="widefat" id="<?php echo $this->get_field_id('event_url'); ?>" name="<?php echo $this->get_field_name('event_url'); ?>" type="text" value="<?php echo attribute_escape($event_url); ?>" /></label></p> <?php } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = $new_instance['title']; $instance['event_url'] = $new_instance['event_url']; return $instance; } function widget($args, $instance){ extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); $event_url = empty($instance['event_url']) ? ' ' : apply_filters('widget_event_url', $instance['event_url']); if (empty($title)){ $title = 'Events'; } if (empty($event_url)){ $event_url = 'http://www.engin.umich.edu/college/about/cal/event-calendar'; } $json = event_url.'/futurejson'; //Get the feed from the url the user provided $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $feeds = curl_exec($ch); curl_close($ch); //decode the data for php $data = json_decode($feeds,true); //var_dump($data); //Check to see if there are any errors in the feed. If yes, output error as result, if not, then start the process of creating block if (json_last_error() === JSON_ERROR_NONE) { //Is the json an array? if (is_array($data)) { //Start the CSS wrapper $events = '<div class="promo promoHolderEvents"><a class="promoEvents" href="'.$event_url.'"><h3>'.$title.'</h3><h4>'.getDatesHeaders($data['events'][0]['month'], $data['events'][1]['month']).'</h4>'; //Loop over results to get the information and create the posts for ($i = 0; $i < 2; $i++) { $events.='<div class="pDateItem"><p class="pDate">'.addOrdinalNumberSuffix($data['events'][$i]['day']).'</p><p class="pDate_Info">'.$data['events'][$i]['title'].'</p></div>'; } //End the wrapper'.$url.' $events.='<span class="linkCtA">see all</span></a></div>'; } } else { switch (json_last_error()) { case JSON_ERROR_DEPTH: echo ' - Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: echo ' - Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: echo ' - Unexpected control character found'; break; case JSON_ERROR_SYNTAX: echo ' - Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: echo ' - Unknown error'; break; }; } echo $events; echo $after_widget; } function getDatesHeaders($m1, $m2){ if($m1 != $m2){ $months = date('M', strtotime('2013-'.$m1.'-01')).'/'.date('M', strtotime($m2.'-01-2013')); }else{ $months = date('M', strtotime('2013-'.$m1.'-01')); } return $months; } function addOrdinalNumberSuffix($num) { if (!in_array(($num % 100),array(11,12,13))){ switch ($num % 10) { // Handle 1st, 2nd, 3rd case 1: return $num.'st'; case 2: return $num.'nd'; case 3: return $num.'rd'; } } return $num.'th'; } } add_action( 'widgets_init', create_function('', 'return register_widget("CoE_Events");') ); ?>
Viewing 1 replies (of 1 total)
-
Just a guess: Instead of
<?php echo attribute_escape($event_url); ?>
try
<?php echo attribute_escape($url); ?>
Viewing 1 replies (of 1 total)
The topic ‘What did I do wrong? Second variable is not saving or displaying’ is closed to new replies.