forms = array(
'login_form' => __( 'login form', 'math-captcha' ),
'registration_form' => __( 'registration form', 'math-captcha' ),
'reset_password_form' => __( 'reset password form', 'math-captcha' ),
'comment_form' => __( 'comment form', 'math-captcha' ),
'bbpress' => __( 'bbpress', 'math-captcha' ),
'contact_form_7' => __( 'contact form 7', 'math-captcha' )
);
$this->mathematical_operations = array(
'addition' => __( 'addition (+)', 'math-captcha' ),
'subtraction' => __( 'subtraction (-)', 'math-captcha' ),
'multiplication' => __( 'multiplication (×)', 'math-captcha' ),
'division' => __( 'division (÷)', 'math-captcha' )
);
$this->groups = array(
'numbers' => __( 'numbers', 'math-captcha' ),
'words' => __( 'words', 'math-captcha' )
);
}
/**
* Add options menu.
*/
public function admin_menu_options() {
add_options_page(
__( 'Math Captcha', 'math-captcha' ), __( 'Math Captcha', 'math-captcha' ), 'manage_options', 'math-captcha', array( $this, 'options_page' )
);
}
/**
* Render options page.
*
* @return mixed
*/
public function options_page() {
echo '
' . __( 'Math Captcha', 'math-captcha' ) . '
' . __( 'Math Captcha', 'math-captcha' ) . ' ' . Math_Captcha()->defaults['version'] . '
' . __( 'Need support?', 'math-captcha' ) . '
' . __( 'If you are having problems with this plugin, please talk about them in the', 'math-captcha' ) . ' ' . __( 'Support forum', 'math-captcha' ) . '
' . __( 'Do you like this plugin?', 'math-captcha' ) . '
' . __( 'Rate it 5', 'math-captcha' ) . ' ' . __( 'on WordPress.org', 'math-captcha' ) . '
' .
__( 'Blog about it & link to the', 'math-captcha' ) . ' ' . __( 'plugin page', 'math-captcha' ) . '
' .
__( 'Check out our other', 'math-captcha' ) . ' ' . __( 'WordPress plugins', 'math-captcha' ) . '
Created by
';
}
/**
* Register settings.
*/
public function register_settings() {
// general settings
register_setting( 'math_captcha_options', 'math_captcha_options', array( $this, 'validate_settings' ) );
add_settings_section( 'math_captcha_settings', __( 'Math Captcha settings', 'math-captcha' ), '', 'math_captcha_options' );
add_settings_field( 'mc_general_enable_captcha_for', __( 'Enable Math Captcha for', 'math-captcha' ), array( $this, 'mc_general_enable_captcha_for' ), 'math_captcha_options', 'math_captcha_settings' );
add_settings_field( 'mc_general_hide_for_logged_users', __( 'Hide for logged in users', 'math-captcha' ), array( $this, 'mc_general_hide_for_logged_users' ), 'math_captcha_options', 'math_captcha_settings' );
add_settings_field( 'mc_general_mathematical_operations', __( 'Mathematical operations', 'math-captcha' ), array( $this, 'mc_general_mathematical_operations' ), 'math_captcha_options', 'math_captcha_settings' );
add_settings_field( 'mc_general_groups', __( 'Display captcha as', 'math-captcha' ), array( $this, 'mc_general_groups' ), 'math_captcha_options', 'math_captcha_settings' );
add_settings_field( 'mc_general_title', __( 'Captcha field title', 'math-captcha' ), array( $this, 'mc_general_title' ), 'math_captcha_options', 'math_captcha_settings' );
add_settings_field( 'mc_general_time', __( 'Captcha time', 'math-captcha' ), array( $this, 'mc_general_time' ), 'math_captcha_options', 'math_captcha_settings' );
add_settings_field( 'mc_general_block_direct_comments', __( 'Block Direct Comments', 'math-captcha' ), array( $this, 'mc_general_block_direct_comments' ), 'math_captcha_options', 'math_captcha_settings' );
add_settings_field( 'mc_general_deactivation_delete', __( 'Deactivation', 'math-captcha' ), array( $this, 'mc_general_deactivation_delete' ), 'math_captcha_options', 'math_captcha_settings' );
}
public function mc_general_enable_captcha_for() {
echo '
';
}
public function mc_general_hide_for_logged_users() {
echo '
';
}
public function mc_general_mathematical_operations() {
echo '
';
}
public function mc_general_groups() {
echo '
';
}
public function mc_general_title() {
echo '
';
}
public function mc_general_time() {
echo '
';
}
public function mc_general_block_direct_comments() {
echo '
';
}
public function mc_general_deactivation_delete() {
echo '
';
}
/**
* Validate settings.
*
* @param array $input
* @return array
*/
public function validate_settings( $input ) {
if ( isset( $_POST['save_mc_general'] ) ) {
// enable captcha forms
$enable_for = array();
if ( empty( $input['enable_for'] ) ) {
foreach ( Math_Captcha()->defaults['general']['enable_for'] as $enable => $bool ) {
$input['enable_for'][$enable] = false;
}
} else {
foreach ( $this->forms as $enable => $trans ) {
$enable_for[$enable] = (in_array( $enable, $input['enable_for'] ) ? true : false);
}
$input['enable_for'] = $enable_for;
}
if ( ! class_exists( 'WPCF7_ContactForm' ) && Math_Captcha()->options['general']['enable_for']['contact_form_7'] )
$input['enable_for']['contact_form_7'] = true;
if ( ! class_exists( 'bbPress' ) && Math_Captcha()->options['general']['enable_for']['bbpress'] )
$input['enable_for']['bbpress'] = true;
// enable mathematical operations
$mathematical_operations = array();
if ( empty( $input['mathematical_operations'] ) ) {
add_settings_error( 'empty-operations', 'settings_updated', __( 'You need to check at least one mathematical operation. Defaults settings of this option restored.', 'math-captcha' ), 'error' );
$input['mathematical_operations'] = Math_Captcha()->defaults['general']['mathematical_operations'];
} else {
foreach ( $this->mathematical_operations as $operation => $trans ) {
$mathematical_operations[$operation] = (in_array( $operation, $input['mathematical_operations'] ) ? true : false);
}
$input['mathematical_operations'] = $mathematical_operations;
}
// enable groups
$groups = array();
if ( empty( $input['groups'] ) ) {
add_settings_error( 'empty-groups', 'settings_updated', __( 'You need to check at least one group. Defaults settings of this option restored.', 'math-captcha' ), 'error' );
$input['groups'] = Math_Captcha()->defaults['general']['groups'];
} else {
foreach ( $this->groups as $group => $trans ) {
$groups[$group] = (in_array( $group, $input['groups'] ) ? true : false);
}
$input['groups'] = $groups;
}
// hide for logged in users
$input['hide_for_logged_users'] = isset( $input['hide_for_logged_users'] );
// block direct comments access
$input['block_direct_comments'] = isset( $input['block_direct_comments'] );
// deactivation delete
$input['deactivation_delete'] = isset( $input['deactivation_delete'] );
// captcha title
$input['title'] = trim( $input['title'] );
// captcha time
$time = (int) $input['time'];
$input['time'] = ($time < 0 ? Math_Captcha()->defaults['general']['time'] : $time);
// flush rules
$input['flush_rules'] = true;
} elseif ( isset( $_POST['reset_mc_general'] ) ) {
$input = Math_Captcha()->defaults['general'];
add_settings_error( 'settings', 'settings_reset', __( 'Settings restored to defaults.', 'math-captcha' ), 'updated' );
}
return $input;
}
}