wpcf7_init_captcha()CF7 1.0

CAPTCHA functions

Хуков нет.

Возвращает

null. Ничего (null).

Использование

wpcf7_init_captcha();

Код wpcf7_init_captcha() CF7 5.9.3

function wpcf7_init_captcha() {
	static $captcha = null;

	if ( $captcha ) {
		return $captcha;
	}

	if ( class_exists( 'ReallySimpleCaptcha' ) ) {
		$captcha = new ReallySimpleCaptcha();
	} else {
		return false;
	}

	$dir = trailingslashit( wpcf7_captcha_tmp_dir() );

	$captcha->tmp_dir = $dir;

	if ( is_callable( array( $captcha, 'make_tmp_dir' ) ) ) {
		$result = $captcha->make_tmp_dir();

		if ( ! $result ) {
			return false;
		}

		return $captcha;
	}

	$result = wp_mkdir_p( $dir );

	if ( ! $result ) {
		return false;
	}

	$htaccess_file = path_join( $dir, '.htaccess' );

	if ( file_exists( $htaccess_file ) ) {
		list( $first_line_comment ) = (array) file(
			$htaccess_file,
			FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
		);

		if ( '# Apache 2.4+' === $first_line_comment ) {
			return $captcha;
		}
	}

	if ( $handle = @fopen( $htaccess_file, 'w' ) ) {
		fwrite( $handle, "# Apache 2.4+\n" );
		fwrite( $handle, "<IfModule authz_core_module>\n" );
		fwrite( $handle, "    Require all denied\n" );
		fwrite( $handle, '    <FilesMatch "^\w+\.(jpe?g|gif|png)$">' . "\n" );
		fwrite( $handle, "        Require all granted\n" );
		fwrite( $handle, "    </FilesMatch>\n" );
		fwrite( $handle, "</IfModule>\n" );
		fwrite( $handle, "\n" );
		fwrite( $handle, "# Apache 2.2\n" );
		fwrite( $handle, "<IfModule !authz_core_module>\n" );
		fwrite( $handle, "    Order deny,allow\n" );
		fwrite( $handle, "    Deny from all\n" );
		fwrite( $handle, '    <FilesMatch "^\w+\.(jpe?g|gif|png)$">' . "\n" );
		fwrite( $handle, "        Allow from all\n" );
		fwrite( $handle, "    </FilesMatch>\n" );
		fwrite( $handle, "</IfModule>\n" );

		fclose( $handle );
	}

	return $captcha;
}