";
}
/**
* Action attached to comment_form hook. Displays the PlayThru before the
* comment form submit button
*/
function ayah_comment_form() {
$options = ayah_get_options();
// Do not show if the user is logged and it is not enabled for logged in users
if (is_user_logged_in() && 1 == $options['hide_registered_users']) {
return;
}
// Display the PlayThru
$ayah = ayah_load_library();
$html = $ayah->getPublisherHTML();
echo "
";
echo ayah_rearrange_elements($options['submit_id']);
}
/**
* Moves the submit button to the bottom and moves the PlayThru above the
* comment form if necessary
*
* TODO: It might be a good idea to use wp_enqueue_script instead, but there
* might be issues with dynamically inserting the button
*/
function ayah_rearrange_elements($button_id = 'submit') {
if ($button_id == '') {
$button_id = 'submit';
}
$script = "";
// Return the script.
return $script;
}
/**
* Action attached to preprocess_comment. Validates PlayThru result.
*/
function ayah_comment_post($comment) {
$options = ayah_get_options();
// Do not show if the user is logged and it is not enabled for logged in users
if ( is_user_logged_in() && 1 == $options['hide_registered_users'] ) {
return $comment;
}
// Skip for comment replies from the admin menu
if ( isset( $_POST['action'] ) && $_POST['action'] == 'replyto-comment' &&
( check_ajax_referer( 'replyto-comment', '_ajax_nonce', false ) ||
check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment', false ) ) ) {
return $comment;
}
// Skip for trackback or pingback
if ( $comment['comment_type'] != '' && $comment['comment_type'] != 'comment' ) {
return $comment;
}
$ayah = ayah_load_library();
// Score the game
if ( $ayah->scoreResult() ) {
return $comment;
} else {
global $AYAH_ERROR_MESSAGE;
wp_die( __($AYAH_ERROR_MESSAGE, 'ayah'));
}
}
/**
* Attached to register_form. Displays the PlayThru during new user registration.
*/
function ayah_register_form() {
$ayah = ayah_load_library();
echo $ayah->getPublisherHTML();
return true;
}
/**
* Attached to register_post. Validates PlayThru result.
* This function receives three parameters; we only need the WP_Error $errors variable, which we pass to a common
* function responsible for checking the score and appending an error.
*
* @param string $foo (unused)
* @param string $bar (unused)
* @param WP_Error $errors The WP_Error object to which we will append an error if the PlayThru did not succeed.
*/
function ayah_register_post($foo, $bar, $errors) {
ayah_score_playthru_and_append_error($errors);
}
/**
* Attached to wpmu_validate_user_signup (WP multi-site only). Validates PlayThru result.
* Receives one parameter which looks like this:
* $result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email,
* 'errors' => $errors);
* We only care about the WP_Error object $errors, so we pull it out and use a common function to perform the score
* check and append an error if necessary.
*
* @param array $result
*
* @return array The $result array.
*/
function ayah_wpmu_validate_user_signup($result) {
// Skip this for the 'blog' step
global $stage;
if($stage == "validate-blog-signup") return $result;
/** @var WP_Error $errors */
$errors = $result['errors'];
ayah_score_playthru_and_append_error($errors, 'generic');
return $result;
}
/**
* This function checks the PlayThru score and, if unsuccessful, appends an error message to the list of errors.
*
* @param WP_Error $errors
* @param string $error_code (optional) error code to assign
*/
function ayah_score_playthru_and_append_error($errors, $error_code = 'playthru_wrong'){
// Load the Are You A Human library
$ayah = ayah_load_library();
// Check the score result
if ($ayah->scoreResult()) {
return;
} else {
global $AYAH_ERROR_ON_FORMS;
$errors->add($error_code, '' . __('ERROR', 'ayah') . ': ' . __($AYAH_ERROR_ON_FORMS, 'ayah'));
}
}
/**
* Attached to lostpassword_form. Displays the PlayThru on the lost password form
*/
function ayah_lost_password_form() {
// Same as the register form
ayah_register_form();
}
/**
* Attached to lostpassword_post. Validates PlayThru result.
*/
function ayah_lost_password_post() {
$ayah = ayah_load_library();
if ( $ayah->scoreResult() ) {
return;
} else {
global $AYAH_ERROR_MESSAGE;
wp_die(__($AYAH_ERROR_MESSAGE,'ayah'));
}
}