Marios, the stripslashes did not solve it.
All of us continued to have the textarea in the displayed “Settings” shown as one line. This was difficult to update.
After lots of experimentation, I came up with something that works.
The only change is to the “settings_page” function, in the admin.php file.
Here is the patch:
$optstr = "";
//newly defined
if ( isset($_POST['update']) ) {
// check user is authorised
if ( function_exists( 'current_user_can' ) && !current_user_can( 'manage_options' ) )
die( 'Sorry, not allowed...' );
check_admin_referer( 'pc_robotstxt_settings' );
$options['user_agents'] = trim( $_POST['user_agents'] );
//Changes below: treat lines of post data as an array
$options['user_agents'] = explode(PHP_EOL, $options['user_agents']);
$options['user_agents'] = array_filter($options['user_agents'], 'trim');
// remove any extra \r characters left behind
foreach ($options['user_agents'] as $line) {
$optstr .= $line . "";
//blank text at end of line prevents run-on text
}
$options['user_agents'] = $optstr;
//reassign
isset( $_POST['remove_settings'] ) ? $options['remove_settings'] = true : $options['remove_settings'] = false;
update_option( 'pc_robotstxt', $options );
echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
}
else {
$options['user_agents'] = explode(PHP_EOL, $options['user_agents']);
$options['user_agents'] = array_filter($options['user_agents'], 'trim');
// remove any extra \r characters left behind
foreach ($options['user_agents'] as $line) {
$optstr .= $line . "";
//blank text at end of line prevents run-on text
}
$options['user_agents'] = $optstr;
//reassign
}
Essentially and oddly, the important change here is to separate the $options[‘user_agent’] lines into an array, and add nothing more than a double quoted empty text to the end of each line:
$optstr .= $line . "";
A double quoted newline does not work; nor does an escaped newline work; nor does nl2br function work. However anything a blank text added works. Don’t ask me why.
I had to add the else-block, because whether the result of a Post or a pull of the current Robots file, the effect was the same—a single line of text displayed on the textarea. Thus Post results and pull results are treated equally.
Perhaps it is only Macs that ever had this problem? I don’t know. But if so, it’s fixed with this patch, even with stripslashes left in.
Thanks, Marios. I like your plugin very much. Now it’s perfect and convenient.
–Fran Corpier