I got this error too when Adding a New “custom post” like Portfolio, Testimonials, etc.
I believe, in the end, this doesn’t hinder the Plugins functionality nor is the htaccess file actually un-readable or un-writable.
The solution for now is to just input a Title for your Portfolio (or other custom post type) and then Save as Draft. Once you have a slug (created from title), the error goes away.
I think I’ve narrowed the issue down to either this part of code:
private function add_rules_htaccess() {
global $wp_post_types;
$suffix = get_option('uwt_permalink_customtype_suffix');
$write = array();
$htaccess_filename = site_url(). '/.htaccess';
if (is_readable($htaccess_filename)) {
$htaccess = fopen($htaccess_filename, 'r');
$content = fread($htaccess, filesize($htaccess_filename));
foreach ($wp_post_types as $type=>$custom_post) {
$rewrite_rule = (!empty($suffix))
? "RewriteRule ^{$custom_post->query_var}/(.+)/\$ /\$1\.{$suffix} [R=301,l]"
: "RewriteRule ^{$custom_post->query_var}/(.+)/\$ /\$1 [R=301,L]";
if (strpos($content, $rewrite_rule) == false && $custom_post->_builtin == false)
$write[] = $rewrite_rule;
}
fclose($htaccess);
}
else {
add_action('admin_notices', array(&$this, 'compatibility_notice'));
return;
}
Specifically: “if (is_readable($htaccess_filename))” and either the path to htaccess is wrong (you can see I changed my code to use site_url instead of the ABSPATH in case of an issue there, but that didn’t help)
OR it’s to due with the next part of code and either the $write variable is empty or the htaccess isn’t writable. I suppose it’s possible that is_writable would return false if there was some sort of restriction with your host and using this PHP function.
I’m not sure.
if (!empty($write) && is_writable($htaccess_filename)) {
$new_rules = '# BEGIN ' . $this->htaccess_tag . PHP_EOL;
$new_rules .= str_replace('$', '\\$', implode(PHP_EOL, $write)) . PHP_EOL;
$new_rules .= '# END ' . $this->htaccess_tag;
if (strpos($content, "# BEGIN {$this->htaccess_tag}") === false) {
file_put_contents($htaccess_filename, $new_rules . PHP_EOL . PHP_EOL . $content);
}
else {
$pattern = "/# BEGIN {$this->htaccess_tag}.*?# END {$this->htaccess_tag}/ims";
$content = preg_replace($pattern, $new_rules, $content);
file_put_contents($htaccess_filename, $content);
}
}
else
add_action('admin_notices', array(&$this, 'compatibility_notice'));
}
If anyone has any other insight, I’ve love to get rid of this ugly red error for my clients when they add new Custom Post types and use this plugin.
So Chime in. ??