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

  1. if ( !function_exists( 'yit_plugin_content' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-wishlist/plugin-fw/yit-functions.php'; 
  3.  
  4. // The what. 
  5. $what = 'content'; 
  6.  
  7. // The limit. 
  8. $limit = 25; 
  9.  
  10. // The more text. 
  11. $more_text = ''; 
  12.  
  13. // The split. 
  14. $split = '[...]'; 
  15.  
  16. // The in paragraph. 
  17. $in_paragraph = 'true'; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = yit_plugin_content($what, $limit, $more_text, $split, $in_paragraph); 
  21.  

Defined (1)

The function is defined in the following location(s).

/plugin-fw/yit-functions.php  
  1. function yit_plugin_content ( $what = 'content', $limit = 25, $more_text = '', $split = '[...]', $in_paragraph = 'true' ) { 
  2. if ( $what == 'content' ) { 
  3. $content = get_the_content ( $more_text ); 
  4. } else { 
  5. if ( $what == 'excerpt' ) { 
  6. $content = get_the_excerpt (); 
  7. } else { 
  8. $content = $what; 
  9.  
  10. if ( $limit == 0 ) { 
  11. if ( $what == 'excerpt' ) { 
  12. $content = apply_filters ( 'the_excerpt', $content ); 
  13. } else { 
  14. $content = preg_replace ( '/<img[^>]+./', '', $content ); //remove images 
  15. $content = apply_filters ( 'the_content', $content ); 
  16. $content = str_replace ( ']]>', ']]>', $content ); 
  17.  
  18. return $content; 
  19.  
  20. // remove the tag more from the content 
  21. if ( preg_match ( "/<(a)[^>]*class\s*=\s*(['\"])more-link\\2[^>]*>(.*?)<\/\\1>/", $content, $matches ) ) { 
  22.  
  23. if ( strpos ( $matches[ 0 ], '[button' ) ) { 
  24. $more_link = str_replace ( 'href="#"', 'href="' . get_permalink () . '"', do_shortcode ( $matches[ 3 ] ) ); 
  25. } else { 
  26. $more_link = $matches[ 0 ]; 
  27.  
  28. $content = str_replace ( $more_link, '', $content ); 
  29. $split = ''; 
  30.  
  31. if ( empty( $content ) ) { 
  32. return; 
  33. $content = explode ( ' ', $content ); 
  34.  
  35. if ( ! empty( $more_text ) && ! isset( $more_link ) ) { 
  36. //array_pop( $content ); 
  37. $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>'; 
  38. $split = ''; 
  39. } elseif ( ! isset( $more_link ) ) { 
  40. $more_link = ''; 
  41.  
  42. // split 
  43. if ( count ( $content ) >= $limit ) { 
  44. $split_content = ''; 
  45. for ( $i = 0; $i < $limit; $i ++ ) { 
  46. $split_content .= $content[ $i ] . ' '; 
  47.  
  48. $content = $split_content . $split; 
  49. } else { 
  50. $content = implode ( " ", $content ); 
  51.  
  52. // TAGS UNCLOSED 
  53. $tags = array (); 
  54. // get all tags opened 
  55. preg_match_all ( "/(<([\w]+)[^>]*>)/", $content, $tags_opened, PREG_SET_ORDER ); 
  56. foreach ( $tags_opened as $tag ) { 
  57. $tags[] = $tag[ 2 ]; 
  58.  
  59. // get all tags closed and remove it from the tags opened.. the rest will be closed at the end of the content 
  60. preg_match_all ( "/(<\/([\w]+)[^>]*>)/", $content, $tags_closed, PREG_SET_ORDER ); 
  61. foreach ( $tags_closed as $tag ) { 
  62. unset( $tags[ array_search ( $tag[ 2 ], $tags ) ] ); 
  63.  
  64. // close the tags 
  65. if ( ! empty( $tags ) ) { 
  66. foreach ( $tags as $tag ) { 
  67. $content .= "</$tag>"; 
  68.  
  69. //$content = preg_replace( '/\[.+\]/', '', $content ); 
  70. if ( $in_paragraph == true ): $content .= $more_link; endif; 
  71. $content = preg_replace ( '/<img[^>]+./', '', $content ); //remove images 
  72. $content = apply_filters ( 'the_content', $content ); 
  73. $content = str_replace ( ']]>', ']]>', $content ); // echo str_replace( array( '<', '>' ), array( '<', '>' ), $content ); 
  74. if ( $in_paragraph == false ): $content .= $more_link; endif; 
  75.  
  76. return $content;