admin notice help
-
i am working on a plugin and it needs to modify the .htaccess on the server. if the file is not writable, i want to show a ‘temporary’ admin notice. i’m doing this all wrong and this isn’t working at all so if anyone could help me get on the right track with this i would appreciate it very much.
here’s the code
function update_htaccess() { $writable = false; if ( (!file_exists(ABSPATH.'.htaccess') && is_writable(ABSPATH)) || is_writable(ABSPATH.'.htaccess') ) $writable = true; if ( !$writable ) add_action( 'admin_notices', 'bans_notice' ); $h = fopen( ABSPATH . ".htaccess", "r" ); $htcontent = fread( $h, filesize( ABSPATH . ".htaccess" ) ); fclose( $h ); if( !preg_match( "/# begin bans-post.*# end bans-post/si", $htcontent ) ) { preg_match( "/^RewriteBase (.+?)$/sim", $htcontent, $m ); if ( $m[1] == "/" ) $m[1] = ""; $h = fopen( ABSPATH . ".htaccess", "w+" ); $htcontent = "# BEGIN BANS-Post\n<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteRule ^item/([^/]+)?$\t".$m[1]."store/item.php?i=$1 [QSA,L]\n</IfModule>\n\n# END BANS-Post\n\n".$htcontent; fwrite( $h, $htcontent ); fclose( $h ); } } function install_bans_post() { update_htaccess(); //clean_xmlphp(); global $bans_version, $bans_db_version; //add_action( 'admin_notices', 'bans_notice' ); } function bans_notice() { echo "<div id='Bans-Notice' class='updated fade'><p>Your .htaccess is not writable. please add the following to it: <pre>\n\n# BEGIN BANS-Post\n<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteRule ^item/([^/]+)?$\t".$m[1]."store/item.php?i=$1 [QSA,L]\n</IfModule>\n\n# END BANS-Post\n\n</pre></p></div>"; } // hooks register_activation_hook( __FILE__, 'install_bans_post' ); add_action( 'wp_head', 'loadCss' ); add_filter( 'the_content', 'bans_post' );
for a prettier version with syntax highlighting go here https://pastebin.ws/917403980
any help appreciated. thanks.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘admin notice help’ is closed to new replies.