WordPress.org

Ready to get started?Download WordPress

Forums

Publish problem after activating plugin (2 posts)

  1. MaartenN
    Member
    Posted 6 years ago #

    Hi,

    I am using WordPress as a kind of CMS for my website, I use the comment function not as a comment-system but I use it as a guestbook.
    For this purpose I want to change the mail that is being send when someone leaves a comment, so in my case a new entry to the guestbook.
    I want to change the text and I want it to be send to another mail-address then the mail address of the admin.

    After a little search I found out that this mail-function is implemented in the file pluggable.php in the function wp_notify_postauthor. I found out that you can override pluggable functions with a plugin, so I thaught it would be the best solution to write my own simple plugin for this.

    I never wrote a plugin before, but with some help from several websites I thaught I managed. I wrote the next plugin to override the wp_notify_postauthor function:

    <?php
    /*
    Plugin Name: Guestbook Notifier
    Description: this plugin changes the mail that is being sent when someone writes something in the guestbook
    Version: 0.5
    Author: MaartenN
    */
    ?>
    
    <?php
    
    if ( !function_exists('wp_notify_postauthor') ) :
    function wp_notify_postauthor($comment_id, $comment_type='') {
    
    	$guestbooksender	=	'blah@blah.com';	//the address that will be seen as the sender of the mail
    	$guestbookreceiver 	= 	'blah@blah.com';	//the address where the mail will be send to
    
    	$comment = get_comment($comment_id);
    
    	$from = "From: \"".get_option('blogname')." Guestbook\" <$guestbooksender>";
    	$reply_to = "Reply-To: $comment->comment_author_email";
    	$subject 		 = sprintf( __('New message in your guestbook'));
    	$message_headers = "MIME-Version: 1.0\n". "$from\n"."Content-Type: text/plain; charset=\"" .get_option('blog_charset')."\"\n";
    	$notify_message  = sprintf( __('New message in your guestbook')) . "\r\n";
    	$notify_message .= sprintf( __('Author : %1$s'), $comment->comment_author) . "\r\n";
    	//and here are some more lines added, but to keep it readable in this forum, I deleted them.
    	//the lines I deleted are the same as the above line; they add a line to the text that is being mailed
    
    	$notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
    	$subject = apply_filters('comment_notification_subject', $subject, $comment_id);
    	$message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id);
    
    	@wp_mail($guestbookreceiver, $subject, $notify_message, $message_headers);
    
    	return true;
    }
    endif;
    ?>

    But when I activate this plugin, it does what I expected it to do; the mail-text is changed and it is being send to the specified mail-address in the plugin, but I'm not able to publish new posts anymore. When I write a new post, and I press the publish-button, WordPress tells me that my attempt to edit the post failed.

    Do you know a solution for my problem?
    Or do you know another solution to change the text and the recipient of these mails?

    Thank you very much!

    MaartenN

  2. nonviamest
    Member
    Posted 6 years ago #

    I have almost the same problem:
    I wrote a plugin to change the looks of the login-screen, this works, but I am also not able to publish new posts, I get the same error-message as MaartenN and the posts are stored as not published.

    does anyone know how this is possible, and more important, how we can solve this?

Topic Closed

This topic has been closed to new replies.

About this Topic