WP_Site_Health::get_test_insecure_registrationpublicWP 7.0.0

Tests if registration is open to everyone and the default role is privileged.

Метод класса: WP_Site_Health{}

Хуков нет.

Возвращает

Массив. The test results.

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

$WP_Site_Health = new WP_Site_Health();
$WP_Site_Health->get_test_insecure_registration();

Список изменений

С версии 7.0.0 Введена.

Код WP_Site_Health::get_test_insecure_registration() WP 7.0

public function get_test_insecure_registration() {
	$users_can_register = get_option( 'users_can_register' );
	$default_role       = get_option( 'default_role' );

	$result = array(
		'label'       => __( 'Open Registration with privileged default role' ),
		'status'      => 'good',
		'badge'       => array(
			'label' => __( 'Security' ),
			'color' => 'blue',
		),
		'description' => '<p>' . __( 'The combination of open registration setting and the default user role may lead to security issues.' ) . '</p>',
		'actions'     => '',
		'test'        => 'insecure_registration',
	);

	if ( $users_can_register && in_array( $default_role, array( 'editor', 'administrator' ), true ) ) {
		$result['description'] = __( 'Registration is open to anyone, and the default role is set to a privileged role.' );
		$result['status']      = 'critical';
		$result['actions']     = sprintf(
			'<p><a href="%s">%s</a></p>',
			esc_url( admin_url( 'options-general.php' ) ),
			__( 'Change these settings' )
		);
	}

	return $result;
}