• Resolved zehrgut

    (@zehrgut)


    Hello!
    First of all thanks a lot for the great plugin!

    Could you please show an example of using callbacks?
    I’m interested to check some comment custom field before posting comment to database. And if something is wrong then to show my error message.

    I tried to assign ‘OnBeforeSubmitComment‘ callback to check_my_custom_field.

    Then in function.php declare

    function check_my_custom_field() {
     return true;//false - all without success
    }

    When I post a comment then I see a message “Posting your comment. Please wait”for a few minutes.

    It would be nice if you add some actions to your plugin in future.

    Please help.
    Thanks in advance!

    http://wordpress.org/plugins/wp-ajaxify-comments/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi ZherGut,

    thanks for your comment. The plugin’s callbacks (like “OnBeforeSubmitComment”) are JavaScript callbacks, i.e. they are executed on the client side.
    To execute some custom PHP code/function you need to use the WordPress API that offers various hook points (see here and here). I try to make the more clear in one of the next releases.

    Hope this helps. Please free to reopen this thread if you need further assistance.

    Jan

    Thread Starter zehrgut

    (@zehrgut)

    Hi janjonas!

    Thanks a lot for the response!
    Thanks for explanation about callback. It’s clear now.
    I know about WordPress hooks, actions and filters. But could you give me a rough example on how to check custom fields with your plugin?

    I mean this. Usually I can do any ckecking by this:

    add_action('comment_post','my_add_comment');
    function my_add_comment($comment_id) {
    	...
    	$ccode = $_POST['ccode'];
    	if (isset($ccode)) {
    		update_comment_meta($comment_id, 'ccode', $ccode);
    		return true;
    	} else {
    	...
    		// error! custom field's value is wrong
    		return false;
    	}
    }

    1. But how to check it with your AJAX plugin?
    2. How to send an error message if something is wrong?

    Thanks in advance!

    Hi ZherGut,

    my plugin does not change the way how comments are posted/validated and how the error message is returned to the client in any way.

    Support of custom WordPress development is beyond the (free) plugin support I can offer here.

    Summarized: If your custom validation fails you have to return the error in the same way like WordPress returns the “ERROR: please type a comment.” error if one submits an empty comment.

    Please contact me here (http://blog.janjonas.net/contact) if you need further assistance and we will see if we find a way to solve your problems.

    Hope this helps…

    Thread Starter zehrgut

    (@zehrgut)

    Hi Jan!

    Thanks for the explanation!
    It really helped to know that I should do any custom validations as usual.

    Thanks for the support!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Please example of callbacks’ is closed to new replies.