yit_plugin_content
Return post content with read more link (if needed).
Description
(string) yit_plugin_content( (string) $what = 'content', (int) $limit = 25, (string) $more_text = '', (string) $split = '[...]', (string) $in_paragraph = 'true' );
Returns (string)
Parameters (5)
- 0. $what — Optional. (string) =>
'content'
- The what.
- 1. $limit — Optional. (int) =>
25
- The limit.
- 2. $more_text — Optional. (string) =>
''
- The more text.
- 3. $split — Optional. (string) =>
'[...]'
- The split.
- 4. $in_paragraph — Optional. (string) =>
'true'
- The in paragraph.
Usage
if ( !function_exists( 'yit_plugin_content' ) ) { require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-wishlist/plugin-fw/yit-functions.php'; } // The what. $what = 'content'; // The limit. $limit = 25; // The more text. $more_text = ''; // The split. $split = '[...]'; // The in paragraph. $in_paragraph = 'true'; // NOTICE! Understand what this does before running. $result = yit_plugin_content($what, $limit, $more_text, $split, $in_paragraph);
Defined (1)
The function is defined in the following location(s).
- /plugin-fw/yit-functions.php
- function yit_plugin_content ( $what = 'content', $limit = 25, $more_text = '', $split = '[...]', $in_paragraph = 'true' ) {
- if ( $what == 'content' ) {
- $content = get_the_content ( $more_text );
- } else {
- if ( $what == 'excerpt' ) {
- $content = get_the_excerpt ();
- } else {
- $content = $what;
- }
- }
- if ( $limit == 0 ) {
- if ( $what == 'excerpt' ) {
- $content = apply_filters ( 'the_excerpt', $content );
- } else {
- $content = preg_replace ( '/<img[^>]+./', '', $content ); //remove images
- $content = apply_filters ( 'the_content', $content );
- $content = str_replace ( ']]>', ']]>', $content );
- }
- return $content;
- }
- // remove the tag more from the content
- if ( preg_match ( "/<(a)[^>]*class\s*=\s*(['\"])more-link\\2[^>]*>(.*?)<\/\\1>/", $content, $matches ) ) {
- if ( strpos ( $matches[ 0 ], '[button' ) ) {
- $more_link = str_replace ( 'href="#"', 'href="' . get_permalink () . '"', do_shortcode ( $matches[ 3 ] ) );
- } else {
- $more_link = $matches[ 0 ];
- }
- $content = str_replace ( $more_link, '', $content );
- $split = '';
- }
- if ( empty( $content ) ) {
- return;
- }
- $content = explode ( ' ', $content );
- if ( ! empty( $more_text ) && ! isset( $more_link ) ) {
- //array_pop( $content );
- $more_link = strpos ( $more_text, '<a class="btn"' ) ? $more_text : '<a class="read-more' . apply_filters ( 'yit_simple_read_more_classes', ' ' ) . '" href="' . get_permalink () . '">' . $more_text . '</a>';
- $split = '';
- } elseif ( ! isset( $more_link ) ) {
- $more_link = '';
- }
- // split
- if ( count ( $content ) >= $limit ) {
- $split_content = '';
- for ( $i = 0; $i < $limit; $i ++ ) {
- $split_content .= $content[ $i ] . ' ';
- }
- $content = $split_content . $split;
- } else {
- $content = implode ( " ", $content );
- }
- // TAGS UNCLOSED
- $tags = array ();
- // get all tags opened
- preg_match_all ( "/(<([\w]+)[^>]*>)/", $content, $tags_opened, PREG_SET_ORDER );
- foreach ( $tags_opened as $tag ) {
- $tags[] = $tag[ 2 ];
- }
- // get all tags closed and remove it from the tags opened.. the rest will be closed at the end of the content
- preg_match_all ( "/(<\/([\w]+)[^>]*>)/", $content, $tags_closed, PREG_SET_ORDER );
- foreach ( $tags_closed as $tag ) {
- unset( $tags[ array_search ( $tag[ 2 ], $tags ) ] );
- }
- // close the tags
- if ( ! empty( $tags ) ) {
- foreach ( $tags as $tag ) {
- $content .= "</$tag>";
- }
- }
- //$content = preg_replace( '/\[.+\]/', '', $content );
- if ( $in_paragraph == true ): $content .= $more_link; endif;
- $content = preg_replace ( '/<img[^>]+./', '', $content ); //remove images
- $content = apply_filters ( 'the_content', $content );
- $content = str_replace ( ']]>', ']]>', $content ); // echo str_replace( array( '<', '>' ), array( '<', '>' ), $content );
- if ( $in_paragraph == false ): $content .= $more_link; endif;
- return $content;
- }