. */ add_action( 'in_admin_footer', array('Post_Anonymously_Patch','run') ); register_activation_hook( __FILE__, array('Post_Anonymously_Patch','install') ); class Post_Anonymously_Patch{ private static $_filePath=''; public static function install(){ self::patchFile(); } public static function run(){ if( isset( $_GET['action'] ) && in_array($_GET['action'],array('do-core-reinstall','do-core-upgrade')) ){ self::patchFile(); } } public static function testFile( $_filePath='' ){ $_filePath=preg_replace( '@wp-admin@i', '', getcwd() ).$_filePath; if(!is_file($_filePath)){ var_dump('Empty file in '.$_filePath);exit; } if(!is_readable($_filePath)){ var_dump('Can\'t reade file '.$_filePath);exit; } if(!is_writable($_filePath)){ var_dump('Can\'t write in file '.$_filePath);exit; } $_content=file_get_contents( $_filePath ); if(empty($_content)){ var_dump('Empty content in file '.$_filePath);exit; } self::$_filePath=$_filePath; return $_content; } public static function patchFile(){ $_content = self::testFile( 'wp-includes/comment-template.php' ); if( !strstr( $_content, 'Post Anonymously' ) ){ $_content=preg_replace( '@function get_comment_author_email\( \$comment_ID = 0 \) {@i',"function get_comment_author_email( \$comment_ID = 0 ) { // Post Anonymously if( get_comment_meta( get_comment( \$comment_ID )->comment_ID, '_anonymous') ){ return ''; } // /Post Anonymously", $_content ); $_content=preg_replace( '@function get_comment_author\( \$comment_ID = 0 \) {@i',"function get_comment_author( \$comment_ID = 0 ) { // Post Anonymously if( get_comment_meta( get_comment( \$comment_ID )->comment_ID, '_anonymous') ){ return 'anonymous'; } // /Post Anonymously", $_content ); $_content=preg_replace( '@function get_comment_author_link\( \$comment_ID = 0 \) {@i',"function get_comment_author_link( \$comment_ID = 0 ) { // Post Anonymously if( get_comment_meta( get_comment( \$comment_ID )->comment_ID, '_anonymous') ){ return 'anonymous'; } // /Post Anonymously", $_content ); $_content=preg_replace( '@function get_comment_author_IP\( \$comment_ID = 0 \) {@i',"function get_comment_author_IP( \$comment_ID = 0 ) { // Post Anonymously if( get_comment_meta( get_comment( \$comment_ID )->comment_ID, '_anonymous') ){ return ''; } // /Post Anonymously", $_content ); $_content=preg_replace( '@function get_comment_author_url\( \$comment_ID = 0 \) {@i',"function get_comment_author_url( \$comment_ID = 0 ) { // Post Anonymously if( get_comment_meta( get_comment( \$comment_ID )->comment_ID, '_anonymous') ){ return ''; } // /Post Anonymously", $_content ); $_content=preg_replace( '@

@i','

',$_content); file_put_contents( self::$_filePath, $_content ); } $_content = self::testFile( 'wp-comments-post.php' ); if( !strstr( $_content, 'Post Anonymously' ) ){ $_content=preg_replace( '@\$comment_id = wp_new_comment\( \$commentdata \);@i','$comment_id = wp_new_comment( \$commentdata ); // Post Anonymously if( isset($_POST[\'comment_anonymously\']) && $_POST[\'comment_anonymously\'] ){ add_comment_meta( $comment_id, \'_anonymous\', 1 ); } // /Post Anonymously',$_content); file_put_contents( self::$_filePath, $_content ); } $_content = self::testFile( 'wp-includes/author-template.php' ); if( !strstr( $_content, 'Post Anonymously' ) ){ $_content=preg_replace( '@function get_author_posts_url\(\$author_id, \$author_nicename = \'\'\) {@i','function get_author_posts_url($author_id, $author_nicename = \'\') { // Post Anonymously global $post; if( get_post_meta( $post->ID, \'_anonymous\' ) ){ return \'\'; } // /Post Anonymously ',$_content); $_content=preg_replace( '@function get_the_author_link\(\) {@i','function get_the_author_link() { // Post Anonymously global $post; if( get_post_meta( $post->ID, \'_anonymous\' ) ){ return \'\'; } // /Post Anonymously ',$_content); $_content=preg_replace( '@function get_the_author\(\$deprecated = \'\'\) {@i','function get_the_author($deprecated = \'\') { // Post Anonymously global $post; if( get_post_meta( $post->ID, \'_anonymous\' ) ){ return \'anonymous\'; } // /Post Anonymously ',$_content); $_content=preg_replace( '@function get_the_modified_author\(\) {@i','function get_the_modified_author() { // Post Anonymously global $post; if( get_post_meta( $post->ID, \'_anonymous\' ) ){ return \'anonymous\'; } // /Post Anonymously ',$_content); file_put_contents( self::$_filePath, $_content ); } $_content = self::testFile( 'wp-admin/edit-form-advanced.php' ); if( !strstr( $_content, 'Post Anonymously' ) ){ $_content=preg_replace( '@require_once\(\'.\/includes\/meta-boxes.php\'\);@i','require_once(\'./includes/meta-boxes.php\'); // Post Anonymously add_meta_box("anonim-post", "Post Anonymously", "post_anonym_posting", "post", "normal", "high"); function post_anonym_posting(){ global $post_ID; ?>