admin管理员组文章数量:1297116
Redirect first comment (Thanks for comment) with show Author name and beginning of the comment
Sample:
Open custom page (Why custom page? There will be some more information) with text comment
Hi, Anderson. Thanks for your comment « Text comment... »
...
...
some more information
Sorry for my English
Redirect first comment (Thanks for comment) with show Author name and beginning of the comment
Sample:
Open custom page (Why custom page? There will be some more information) with text comment
Hi, Anderson. Thanks for your comment « Text comment... »
...
...
some more information
Sorry for my English
Share Improve this question asked Apr 2, 2021 at 7:18 UserUser-nameUserUser-name 577 bronze badges1 Answer
Reset to default 1You should be able to do something like this:
add_filter( 'comment_post_redirect', 'custom_comments_redirect', 10, 2 );
function custom_comments_redirect( $location, $comment ) {
$comment_id = $comment->comment_ID;
$custom_url = 'https://example/thank-you/?comment=' . $comment_id;
return $custom_url;
}
And on the "Thank you" page, you can get the comment info like this:
// Make sure you sanitize the GET input
$comment_id = (int) filter_input( INPUT_GET, 'comment', FILTER_SANITIZE_NUMBER_INT );
if ( ! empty( $comment_id ) ) {
// Fetch comment if the ID is not 0
$comment = get_comment( $comment_id );
if ( ! empty( $comment ) ) {
$comment_author = $comment->comment_author;
$comment_content = get_comment_excerpt( $comment_id );
echo sprintf( __( 'Hi %s. Thank you for your comment "%s"...' ), $comment_author, $comment_content );
// Do your thing here...
}
}
The default length of the comment excerpt is 20 words, but you can tweak that with a filter as well:
// Set the comments excerpt length (number of words)
add_filter( 'comment_excerpt_length', 'custom_comments_excerpt_length' );
function custom_comments_excerpt_length() {
return 8;
}
本文标签: phpRedirect first comment (Thanks for comment) with show Autor name and beginning of the comment
版权声明:本文标题:php - Redirect first comment (Thanks for comment) with show Autor name and beginning of the comment 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741639727a2389844.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论