Advertisement
arie_cristianD

Make reading time support Ibrani language

Apr 1st, 2024
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. /* Make reading time support Ibrani language */
  2.  
  3. add_action(
  4.     'init',
  5.     function () {
  6.         remove_action( 'jnews_render_after_meta_left', array( \JNews\Single\SinglePost::getInstance(), 'reading_time_meta' ), 10 );
  7.         add_action( 'jnews_render_after_meta_left', 'new_reading_time_meta', 10 );
  8.     }
  9. );
  10.  
  11.  
  12. function new_reading_time_meta() {
  13.  
  14.     if ( new_show_reading_time_meta() ) {
  15.  
  16.         $output = '';
  17.  
  18.         if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  19.             $wpm = (int) vp_metabox( 'jnews_single_post.override.0.post_reading_time_wpm' );
  20.         } else {
  21.             $wpm = (int) get_theme_mod( 'jnews_single_reading_time_wpm', 300 );
  22.         }
  23.  
  24.         $content = get_post_field( 'post_content', get_the_ID() );
  25.         if ( $content && $wpm ) {
  26.             $content    = strip_shortcodes( $content );
  27.             $word_count = substr_count( $content, ' ' ) + 1;
  28.             error_log( $word_count );
  29.             $word_count   = ceil( $word_count / $wpm );
  30.             $reading_time = jnews_return_translation( 'Reading Time: ', 'jnews', 'reading_time' );
  31.             if ( defined( 'JNEWS_FRONT_TRANSLATION' ) ) {
  32.                 $reading_time .= sprintf( _n( jnews_return_translation( '%d min read', 'jnews', 'min_read_s' ), jnews_return_translation( '%d mins read', 'jnews', 'min_read_p', 'jnews' ), $word_count ), $word_count );
  33.             } else {
  34.                 $reading_time .= sprintf( _n( '%d min read', '%d mins read', $word_count, 'jnews' ), $word_count );
  35.             }
  36.  
  37.             if ( $word_count ) {
  38.                 $output =
  39.                     '<div class="jeg_meta_reading_time">
  40.                     <span>
  41.                         ' . $reading_time . '
  42.                     </span>
  43.                 </div>';
  44.             }
  45.         }
  46.  
  47.         echo jnews_sanitize_by_pass( $output );
  48.     }
  49. }
  50.  
  51. function new_show_reading_time_meta() {
  52.     if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
  53.         $flag = vp_metabox( 'jnews_single_post.override.0.show_post_reading_time' );
  54.     } else {
  55.         $flag = get_theme_mod( 'jnews_single_reading_time', false );
  56.     }
  57.  
  58.     return apply_filters( 'jnews_single_show_reading_time', $flag, get_the_ID() );
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement