• Resolved rich06

    (@rich06)


    Is it possible to add another hook in the function ajax_save_comment() at the very end after the comment content filters have all been executed and before the JSON is sent back to the jQuery function?

    The reason is it would be the most efficient way to trigger another plugin which runs in client side JS to apply its changes to the edited returned comment mark up.

    See below for where I would like the new hook..

    — simple-comment-editing.php around line 610

    $comment_content_to_return = $this->get_comment_content( $comment_to_return );
    
    /*** New hook here ***/
    do_action('sce_save_final',$comment_content_to_return,$post_id,$comment_id);
    /*** End new hook ***/
    
    //Ajax response
    $return[ 'comment_text' ] = $comment_content_to_return;

    TIA
    Rich

    https://ww.wp.xz.cn/plugins/simple-comment-editing/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter rich06

    (@rich06)

    Oops .. the example hook code above should be:-

    /*** New hook here ***/
    $comment_content_to_return = do_action('sce_save_final',$comment_content_to_return,$post_id,$comment_id);
    /*** End new hook ***/

    Thx
    Rich

    Plugin Author Ronald Huereca

    (@ronalfy)

    Do you want an action or a filter?

    do_action doesn’t return anything, but apply_filters does.

    Are you also willing to test out the changes before I commit them to .org?

    Thread Starter rich06

    (@rich06)

    Hey Ronald

    Thanks for the quick reply — I need to manipulate the comment content just before it gets returned as JSON so I guess a filter rather than an action is needed.

    Yes I will definitely test this as I am trying to resolve a problem on the site I am working on without changing any of your plugin code so they have a clean upgrade path.

    Thanks
    Rich

    Plugin Author Ronald Huereca

    (@ronalfy)

    I ended up calling the filter sce_return_comment_text

    You can find the filter here: https://github.com/ronalfy/simple-comment-editing/blob/master/simple-comment-editing.php#L626

    Can you download this version and try it out? https://github.com/ronalfy/simple-comment-editing

    Here’s some sample code:

    add_filter( 'sce_return_comment_text', function( $comment_text, $comment_object, $post_id, $comment_id ) {
    	return 'love';
    }, 10, 4 );
    Thread Starter rich06

    (@rich06)

    Seems to work OK – thanks – one more question 🙂 what is the easiest way to have embedded image links being converted to images (via oEmbed) on the edited comment being returned via the Ajax call?

    Thanks again
    Rich

    Plugin Author Ronald Huereca

    (@ronalfy)

    Use the_content.

    Like:
    return apply_filters( 'the_content', 'love' );

    Thread Starter rich06

    (@rich06)

    Thanks for your reply and for adding the new hook – works good!

    Rich

    Plugin Author Ronald Huereca

    (@ronalfy)

    Awesome. If you could please consider leaving a rating, that would be very much appreciated.

    Thread Starter rich06

    (@rich06)

    Done – 5 star review just added! 🙂 Thanks again!

    Thread Starter rich06

    (@rich06)

    The new hook was removed when I upgraded the plugin to v2.1.0 which broke the functionality on my site — can this be fixed included with all new upgrades asap!

    Thanks
    Rich

    Plugin Author Ronald Huereca

    (@ronalfy)

    Sorry about that Rich. 2.1.1 has added it back in. I’m not sure how it got deleted.

    Ronald

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Additional hook request’ is closed to new replies.