198 PART III • Using Plugins with WordPress
<p>Example: <strong>http://aff.com/client/1234/out?=</strong>
<em>http://product.com/9876</em><strong>&%stringafter</strong></p>
<p>The bold parts of the link are controlled from here, the italic part is
the product link which you provide on a per post basis.</p>
<form method="post" action="options.php">
<?php settings_fields( 'addaff_options' ); ?>
<?php $options = get_option( 'addaff_option' ); ?>
<table class="form-table">
<tr valign="top"><th scope="row">URL string to go <strong>before
</strong> the product link:</th>
<td>
<input type="text" name="addaff_option[urlbefore]"
value="<?php echo $options['urlbefore']; ?>"
class="regular-text code" />
</td>
</tr>
<tr valign="top"><th scope="row">String to go <strong>after
</strong> the product link:</th>
<td>
<input type="text" name="addaff_option[urlafter]"
value="<?php echo $options['urlafter']; ?>"
class="regular-text code" />
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary"
value="<?php _e( 'Save Changes' ) ?>" />
</p>
</form>
</div>
<?php }
Remember, what you want with this page is to be able to input a global string that goes before
the unique product links and a string that will be included after them. As soon as you’ve saved
whatever will be stored in the two input fields, you’ll have this data in an array in addaff_
option, which is to say that it is stored in the database.
Wrap up the settings page by sanitizing the data, making sure that nothing nasty gets through
your simple text strings:
// Sanitize and validate input in an array.
function addaff_validate($input) {
// Don't allow HTML in the input fields
$input['urlbefore'] = wp_filter_nohtml_kses($input['urlbefore']);
$input['urlafter'] = wp_filter_nohtml_kses($input['urlafter']);
return $input;
}