integrations
7 years ago
class-strong-form.php
7 years ago
class-strong-log.php
7 years ago
class-strong-mail.php
7 years ago
class-strong-templates.php
7 years ago
class-strong-testimonials-order.php
7 years ago
class-strong-testimonials-privacy.php
7 years ago
class-strong-testimonials-render.php
7 years ago
class-strong-testimonials-shortcode-average.php
7 years ago
class-strong-testimonials-shortcode-count.php
7 years ago
class-strong-testimonials-shortcode.php
7 years ago
class-strong-view-display.php
7 years ago
class-strong-view-form.php
7 years ago
class-strong-view-slideshow.php
7 years ago
class-strong-view.php
7 years ago
class-walker-strong-category-checklist-front.php
7 years ago
deprecated.php
7 years ago
filters.php
7 years ago
functions-activation.php
7 years ago
functions-content.php
7 years ago
functions-image.php
7 years ago
functions-rating.php
7 years ago
functions-template-form.php
7 years ago
functions-template.php
7 years ago
functions-views.php
7 years ago
functions.php
7 years ago
l10n-polylang.php
7 years ago
l10n-wpml.php
7 years ago
post-types.php
7 years ago
retro.php
7 years ago
scripts.php
7 years ago
widget2.php
7 years ago
functions-content.php
253 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Content functions. |
| 4 | */ |
| 5 | |
| 6 | /** |
| 7 | * Based on the_content(). |
| 8 | * |
| 9 | * @param null $more_link_text |
| 10 | * @param bool $strip_teaser |
| 11 | * |
| 12 | * @return string |
| 13 | */ |
| 14 | function wpmtst_the_content_filtered( $more_link_text = null, $strip_teaser = false) { |
| 15 | $content = get_the_content( $more_link_text, $strip_teaser ); |
| 16 | $content = apply_filters( 'wpmtst_the_content', $content ); |
| 17 | $content = str_replace( ']]>', ']]>', $content ); |
| 18 | return $content; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Based on the_excerpt(). |
| 23 | * |
| 24 | * @since 2.26.0 |
| 25 | */ |
| 26 | function wpmtst_the_excerpt_filtered() { |
| 27 | return apply_filters( 'wpmtst_the_excerpt', wpmtst_get_the_excerpt() ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Based on get_the_excerpt(). |
| 32 | * |
| 33 | * @since 2.26.0 |
| 34 | * @param null $post |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | function wpmtst_get_the_excerpt( $post = null ) { |
| 39 | $post = get_post( $post ); |
| 40 | if ( empty( $post ) ) { |
| 41 | return ''; |
| 42 | } |
| 43 | |
| 44 | if ( post_password_required( $post ) ) { |
| 45 | return __( 'There is no excerpt because this is a protected post.', 'strong-testimonials' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Filters the retrieved post excerpt. |
| 50 | * |
| 51 | * @param string $post_excerpt The post excerpt. |
| 52 | * @param WP_Post $post Post object. |
| 53 | */ |
| 54 | return apply_filters( 'wpmtst_get_the_excerpt', $post->post_excerpt, $post ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Force bypass of the manual excerpt. |
| 59 | * |
| 60 | * @since 2.26.0 |
| 61 | * @param $text |
| 62 | * |
| 63 | * @return string |
| 64 | */ |
| 65 | function wpmtst_bypass_excerpt( $text ) { |
| 66 | return ''; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Based on wp_trim_excerpt(). On wpmtst_get_the_excerpt hook. |
| 71 | * |
| 72 | * @since 2.26.0 |
| 73 | * @param string $excerpt The manual excerpt. |
| 74 | * |
| 75 | * @return string |
| 76 | */ |
| 77 | function wpmtst_trim_excerpt( $excerpt = '' ) { |
| 78 | $raw_excerpt = $excerpt; |
| 79 | |
| 80 | /** |
| 81 | * Filter hybrid value here to allow individual overrides. |
| 82 | */ |
| 83 | $hybrid = apply_filters( 'wpmtst_is_hybrid_content', false ); |
| 84 | |
| 85 | if ( '' == $excerpt ) { |
| 86 | |
| 87 | $text = wpmtst_get_the_prepared_text(); |
| 88 | |
| 89 | // Create excerpt if post has no manual excerpt. |
| 90 | $excerpt_length = apply_filters( 'excerpt_length', 55 ); |
| 91 | $excerpt_more = apply_filters( 'excerpt_more', ' […]' ); |
| 92 | $excerpt = wpmtst_trim_words( $text, $excerpt_length, $excerpt_more, $hybrid ); |
| 93 | |
| 94 | } elseif ( $hybrid ) { |
| 95 | |
| 96 | $text = wpmtst_get_the_prepared_text( true ); |
| 97 | |
| 98 | // Append hybrid content as hidden span to the manual excerpt. |
| 99 | $excerpt .= wpmtst_trim_words( $text, 0, '', true ); |
| 100 | |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Filters the trimmed excerpt string. |
| 105 | * |
| 106 | * @param string $text The trimmed text. |
| 107 | * @param string $raw_excerpt The text prior to trimming. |
| 108 | */ |
| 109 | return apply_filters( 'wpmtst_trim_excerpt', $excerpt, $raw_excerpt ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Prepare the post content. |
| 114 | * |
| 115 | * @param bool $hybrid |
| 116 | * @since 2.33.0 |
| 117 | * |
| 118 | * @return string |
| 119 | */ |
| 120 | function wpmtst_get_the_prepared_text( $hybrid = false ) { |
| 121 | $text = get_the_content( '' ); |
| 122 | if ( ! $hybrid ) { |
| 123 | $text = strip_shortcodes( $text ); |
| 124 | } |
| 125 | $text = apply_filters( 'wpmtst_the_content', $text ); |
| 126 | $text = str_replace( ']]>', ']]>', $text ); |
| 127 | |
| 128 | return $text; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Construct the "Read more" link (both automatic and manual). |
| 133 | * |
| 134 | * @since 2.27.0 Filters on URL and full link. |
| 135 | * |
| 136 | * @return string |
| 137 | */ |
| 138 | function wpmtst_get_excerpt_more_link() { |
| 139 | $url = apply_filters( 'wpmtst_read_more_post_url', get_permalink(), WPMST()->atts() ); |
| 140 | |
| 141 | $link_text = sprintf( '%s<span class="screen-reader-text"> "%s"</span>', |
| 142 | apply_filters( 'wpmtst_read_more_post_link_text', WPMST()->atts( 'more_post_text' ), WPMST()->atts() ), get_the_title() |
| 143 | ); |
| 144 | |
| 145 | $link_class = apply_filters( 'wpmtst_read_more_post_link_class', 'readmore' ); |
| 146 | |
| 147 | if ( apply_filters( 'wpmtst_is_hybrid_content', false ) ) { |
| 148 | // no href |
| 149 | $link = sprintf( '<a aria-expanded="false" aria-controls="more-%1$d" class="%2s readmore-toggle"><span class="readmore-text" data-more-text="%4$s" data-less-text="%5$s">%3$s</span></a>', |
| 150 | get_the_ID(), // 1 |
| 151 | $link_class, // 2 |
| 152 | $link_text, // 3 |
| 153 | WPMST()->atts( 'more_post_text' ), // 4 |
| 154 | WPMST()->atts( 'less_post_text' ) // 5 |
| 155 | ); |
| 156 | } else { |
| 157 | $link = sprintf( '<a href="%s" class="%s">%s</a>', esc_url( $url ), $link_class, $link_text ); |
| 158 | } |
| 159 | |
| 160 | return apply_filters( 'wpmtst_read_more_post_link', $link ); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Based on wp_trim_words(). |
| 165 | * |
| 166 | * @param $text |
| 167 | * @param int $num_words |
| 168 | * @param null $more |
| 169 | * @param bool $hybrid |
| 170 | * |
| 171 | * @return string |
| 172 | */ |
| 173 | function wpmtst_trim_words( $text, $num_words = 55, $more = null, $hybrid = false ) { |
| 174 | if ( null === $more ) { |
| 175 | $more = __( '…', 'strong-testimonials' ); |
| 176 | } |
| 177 | |
| 178 | $text = wp_strip_all_tags( $text ); |
| 179 | |
| 180 | /* |
| 181 | * translators: If your word count is based on single characters (e.g. East Asian characters), |
| 182 | * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. |
| 183 | * Do not translate into your own language. |
| 184 | */ |
| 185 | if ( strpos( _x( 'words', 'Word count type. Do not translate!', 'strong-testimonials' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { |
| 186 | $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); |
| 187 | preg_match_all( '/./u', $text, $words_array ); |
| 188 | $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); |
| 189 | $sep = ''; |
| 190 | } else { |
| 191 | $offset = $hybrid ? 0 : $num_words + 1; |
| 192 | $words_array = preg_split( "/[\n\r\t ]+/", $text, $offset, PREG_SPLIT_NO_EMPTY ); |
| 193 | $sep = ' '; |
| 194 | } |
| 195 | |
| 196 | if ( count( $words_array ) > $num_words ) { |
| 197 | if ( $hybrid ) { |
| 198 | $text = wpmtst_assemble_hybrid( $words_array, $num_words, $sep, $more ); |
| 199 | } else { |
| 200 | $text = wpmtst_assemble_excerpt( $words_array, $sep, $more ); |
| 201 | } |
| 202 | } else { |
| 203 | $text = implode( $sep, $words_array ); |
| 204 | } |
| 205 | |
| 206 | return $text; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Assemble excerpt from trimmed array. |
| 211 | * |
| 212 | * @param $words_array |
| 213 | * @param $sep |
| 214 | * @param $more |
| 215 | * @since 2.33.0 |
| 216 | * |
| 217 | * @return string |
| 218 | */ |
| 219 | function wpmtst_assemble_excerpt( $words_array, $sep, $more ) { |
| 220 | array_pop( $words_array ); |
| 221 | $text = implode( $sep, $words_array ); |
| 222 | |
| 223 | return $text . $more; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Assemble excerpt + rest of content in hidden span. |
| 228 | * |
| 229 | * @param $words_array |
| 230 | * @param $num_words |
| 231 | * @param $sep |
| 232 | * @param $more |
| 233 | * @since 2.33.0 |
| 234 | * |
| 235 | * @return string |
| 236 | */ |
| 237 | function wpmtst_assemble_hybrid( $words_array, $num_words, $sep, $more ) { |
| 238 | $ellipsis = wpmtst_ellipsis(); |
| 239 | if ( $ellipsis ) { |
| 240 | $ellipsis = '<span class="ellipsis">' . $ellipsis . ' </span>'; |
| 241 | /* ! This space is important: ^ */ |
| 242 | } |
| 243 | |
| 244 | $first_half = implode( $sep, array_slice( $words_array, 0, $num_words ) ); |
| 245 | $second_half = implode( $sep, array_slice( $words_array, $num_words ) ); |
| 246 | |
| 247 | $wrap_open = '<span class="readmore-content animated" id="more-' . get_the_ID() . '" hidden> '; |
| 248 | $wrap_close = ' </span>'; |
| 249 | |
| 250 | return $first_half . $ellipsis . ' ' . $wrap_open . $second_half . $wrap_close . $more; |
| 251 | /* ! This space is important: ^ */ |
| 252 | } |
| 253 |