$type, 'value' => $value, 'label' => $this->get_label( $type ), 'preview' => $this->get_preview( $value, $type ), ); } /** * Return a human-readable label for a rule type. * * @param string $type One of the TYPE_* constants. * @return string * @since 1.4.0 */ public function get_label( $type ) { $labels = array( self::TYPE_DOMAIN => __( 'Domain rule', 'advanced-email-domain-restriction' ), self::TYPE_TLD => __( 'TLD rule', 'advanced-email-domain-restriction' ), self::TYPE_EMAIL => __( 'Exact email rule', 'advanced-email-domain-restriction' ), self::TYPE_WILDCARD => __( 'Wildcard rule', 'advanced-email-domain-restriction' ), self::TYPE_UNKNOWN => __( 'Unknown format', 'advanced-email-domain-restriction' ), ); return isset( $labels[ $type ] ) ? $labels[ $type ] : ''; } /** * Return a preview string showing what the rule will match. * * @param string $value Normalised rule value. * @param string $type One of the TYPE_* constants. * @return string * @since 1.4.0 */ public function get_preview( $value, $type ) { $prefix = __( 'Allowed:', 'advanced-email-domain-restriction' ); switch ( $type ) { case self::TYPE_DOMAIN: return $prefix . ' user@' . $value; case self::TYPE_TLD: return $prefix . ' user@school' . $value; case self::TYPE_WILDCARD: return $prefix . ' user@sub.' . substr( $value, 2 ); case self::TYPE_EMAIL: return $prefix . ' ' . $value; default: return ''; } } } }