1. Home
  2. Snippets
  3. Change the captcha math for the Custom Captcha Addon

Change the captcha math for the Custom Captcha Addon

Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

For extra guidance, please see WPBeginner's tutorial on adding custom code.

Dismiss

The Custom Captcha addon can be setup to display a math captcha for users to solve. The settings of this type of captcha can be adjusted for easier math by using a filter.

There are 2 different ways this can be applied:

  • Change the maximum number used in a math captcha
  • Use only addition in math captcha

Change the maximum number used in a math captcha.

/**
 * Adjust math captcha settings.
 *
 * @params array $settings
 * @return array
 */
function wpf_dev_math_captcha_settings( $settings ) {
	
	/* Default settings
		array(
			'min' => 1,
			'max' => 15,
			'cal' => array( '+', '*' ),
		);
	 */

	// Change max number 4 for easier math
	$settings['max'] = 4;

	return $settings;
}
add_filter( 'wpforms_math_captcha', 'wpf_dev_math_captcha_settings' );

Use only addition in math captcha.

/**
 * Adjust math captcha settings.
 *
 * @params array $settings
 * @return array
 */
function wpf_dev_math_captcha_settings( $settings ) {
	
	/* Default settings
		array(
			'min' => 1,
			'max' => 15,
			'cal' => array( '+', '*' ),
		);
	 */

    // Use addition only for easier math
	$settings['cal'] = '+';

	return $settings;
}
add_filter( 'wpforms_math_captcha', 'wpf_dev_math_captcha_settings' );

Related

Updated on May 15, 2019

Was this article helpful?