label. * * @return array */ public static function all() { $defaults = Settings::defaults(); if ( (string) Settings::get( 'reasons' ) === $defaults['reasons'] ) { // Untouched defaults: show them in the site language. $labels = self::default_labels(); $keys = array_map( array( __CLASS__, 'key' ), explode( "\n", $defaults['reasons'] ) ); $out = array_combine( $keys, $labels ); } else { $out = array(); foreach ( Settings::lines( 'reasons' ) as $label ) { $out[ self::key( $label ) ] = $label; } } /** * Filters the return reasons offered to customers. * * @param array $reasons key => label. */ return (array) apply_filters( 'rtkt_reasons', $out ); } /** * The default reasons in the site language. * * @return string[] */ public static function default_labels() { return array( __( 'Wrong size or fit', 'returnkit' ), __( 'Damaged or defective', 'returnkit' ), __( 'Not as described', 'returnkit' ), __( 'Wrong item sent', 'returnkit' ), __( 'Changed my mind', 'returnkit' ), __( 'Arrived too late', 'returnkit' ), __( 'Other', 'returnkit' ), ); } /** * Key for a reason label. * * @param string $label Label. * @return string */ public static function key( $label ) { $key = sanitize_title( (string) $label ); return '' !== $key ? substr( $key, 0, 100 ) : 'reason-' . substr( md5( (string) $label ), 0, 8 ); } /** * Label for a stored reason key (falls back to the key itself). * * @param string $key Key. * @return string */ public static function label( $key ) { if ( '' === (string) $key ) { return ''; } if ( 'withdrawal' === $key ) { return __( 'Withdrawal (no reason needed)', 'returnkit' ); } $all = self::all(); return isset( $all[ $key ] ) ? $all[ $key ] : ucfirst( str_replace( '-', ' ', (string) $key ) ); } }