Created
April 18, 2014 07:06
-
-
Save miziomon/11028618 to your computer and use it in GitHub Desktop.
WordPress qTranslate comment form error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* first relase | |
* fix to get and translate comment error message | |
* | |
*/ | |
add_action("pre_comment_on_post", function( $comment_post_ID) { | |
$comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null; | |
$comment_author_email = ( isset($_POST['email']) ) ? trim($_POST['email']) : null; | |
$comment_author_url = ( isset($_POST['url']) ) ? trim($_POST['url']) : null; | |
$comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null; | |
global $q_config, $locale , $l10n; | |
$q_config['language'] = ( isset($_POST['lang']) ) ? trim(strip_tags($_POST['lang'])) : null; | |
$locale = $q_config['language']; | |
unload_textdomain( "default" ); | |
load_default_textdomain(); | |
$comment_error = false; | |
$user = wp_get_current_user(); | |
if (get_option('require_name_email') && !$user->exists()) { | |
if (6 > strlen($comment_author_email) || '' == $comment_author) | |
$comment_error = __('<strong>ERROR</strong>: please fill the required fields (name, email).'); | |
elseif (!is_email($comment_author_email)) | |
$comment_error = __('<strong>ERROR</strong>: please enter a valid email address.'); | |
} | |
if ('' == $comment_content) { | |
$comment_error = __('<strong>ERROR</strong>: please type a comment.'); | |
} | |
if ($comment_error) { | |
$location = get_permalink( $comment_post_ID ) . "?lang=" . qtrans_getLanguage() . "&e=" . urlencode($comment_error) . "#error_message"; | |
wp_safe_redirect($location); | |
exit; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment