* * * @param string Should be empty. * @param string Name of the column. * @param string Term id. Integer represented as string. * @return string Shortend taxonomy description. Empty if no description * * @author Michael Fields * @since 2010-05-31 * @alter 2011-02-25 */ function taxonomy_short_description_rows( $string, $column_name, $term ) { if ( 'mfields_short_description' == $column_name ) { global $taxonomy; $string = term_description( $term, $taxonomy ); $string = taxonomy_short_description_shorten( $string, apply_filters( 'mfields_taxonomy_short_description_length', 40 ) ); } return $string; } /** * Shorten. * * Shorten a string to a given length. * * @param string The string to shorten. * @param int Number of characters allowed in $string. Default value is 23. * @param string Text to append to the shortened string. * @return string Shortened string. * * @author Michael Fields * @author Thomas Scholz * @since 2010-05-31 * @alter 2011-03-01 */ function taxonomy_short_description_shorten( $string, $max_length = 23, $append = '…', $encoding = 'utf8' ) { /* Sanitize $string. */ $string = strip_tags( $string ); $string = trim( $string ); $string = html_entity_decode( $string, ENT_QUOTES, 'UTF-8' ); $string = rtrim( $string, '-' ); /* Sanitize $max_length */ if ( 0 == abs( (int) $max_length ) ) { $max_length = 23; } /* Return early if the php "mbstring" extension is not installed. */ if ( ! function_exists( 'mb_substr' ) ) { $length = strlen( $string ); if ( $length > $max_length ) { return substr_replace( $string, $append, $max_length ); } return $string; } /* Count how many characters are in the string. */ $length = strlen( utf8_decode( $string ) ); /* String is longer than max-length. It needs to be shortened. */ if ( $length > $max_length ) { /* Shorten the string to max-length */ $short = mb_substr( $string, 0, $max_length, $encoding ); /* * A word has been cut in half during shortening. * If the shortened string contains more than one word * the last word in the string will be removed. */ if ( 0 !== mb_strpos( $string, $short . ' ', 0, $encoding ) ) { $pos = mb_strrpos( $short, ' ', $encoding ); if ( false !== $pos ) { $short = mb_substr( $short, 0, $pos, $encoding ); } } /* Append shortened string with the value of $append preceeded by a non-breaking space. */ $string = $short . ' ' . $append; } return $string; } Fade Ogunro | Haute Fashion Africa
Follow Me on Pinterest