Hi I’m creating a simple plugin to add google maps but for some reason when i enter the iframe code in the widget and save it the iframe code is not complete, this is how the widget works.
function mapWidget()
{
$settings = get_option("widget_mapwidget");
$maptitle = $settings['title'];
$map_id = $settings['google_map_id'];
?>
<div class="sidebar-block">
<h4 class="title"><?php if($maptitle !== '') { echo $maptitle; } else{ echo "Find us in the map"; }?></h4>
<div class="map-holder">
<?php echo $map_id; ?>
</div>
</div>
<?php }
function mapWidgetAdmin() {
$settings = get_option("widget_mapwidget");
if (isset($_POST['update_map'])) {
$settings['title'] = strip_tags(stripslashes($_POST['map_title']));
$settings['map_id'] = stripslashes($_POST['google_map_id']);
update_option("widget_mapwidget",$settings);
}
echo '<?>
<label for="map_title">Widget Title:
<input name="map_title" class="widefat" id="map_title" value="'.$settings['title'].'" type="text" /></label>';
echo '<p>
<label for="google_map_id">Embed Map code:</label>
<textarea name="google_map_id" class="widefat" id="google_map_id" value="'.$settings['map_id'].'" type="text" rows="12" cols="40"></textarea></p>';
echo '<input name="update_map" id="update_map" value="1" type="hidden" />';
}
register_sidebar_widget('Exiria Google Map Widget', 'mapWidget');
register_widget_control('Exiria Google Map Widget', 'mapWidgetAdmin', 400, 200);
?>
I think the problem is with this code $settings[‘map_id’] = stripslashes($_POST[‘google_map_id’]);
For example if i add this code to the widget:http://pastebin.com/pL9cWUt4
And then save the widget i get this code: http://pastebin.com/Uhy31P7N
And if i save again the widget i get this code:See full size map\">">
And if i save again i get this code:
\">">
So every time i save the widget some part of the iframe code disappears.
I hope someone can help me
thank’s.
Why aren’t you using the Wordpress 2.9 Widget API , but easier that all that ‘register_sidebar_widget’, register_sidebar_control’ stuff
Developing Widgets
Developing Widgets on 2.8+
http://codex.wordpress.org/Widgets_API
About 1/2 down page
http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/
I’m new to wordpress widgets but that was a great solution, thank’s.
