find_by_key( $key ) || null !== apply_filters( 'glovario_missing_variable', null, $key, array() ); } /** * A free key built from a label: "Opening hours" becomes opening_hours, * then opening_hours_2 and so on when it is taken. * * @param string $label Variable label. * @param VariableRepository $repository Variable storage. * @return string */ public static function from_label( $label, VariableRepository $repository ) { $base = str_replace( '-', '_', sanitize_title( remove_accents( (string) $label ) ) ); $base = trim( preg_replace( '/[^a-z0-9_]+/', '', $base ), '_' ); $base = '' === $base ? 'variable' : substr( $base, 0, 60 ); $key = $base; for ( $suffix = 2; self::taken( $key, $repository ); $suffix++ ) { $key = $base . '_' . $suffix; } return $key; } }