Advertisement
fauzanjeg

functions.php at jnews-child

Jan 28th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.84 KB | None | 0 0
  1. function load_vc_page_custom_css( $id = null, $inline_css = true ) {
  2.     if ( defined( 'WPB_VC_VERSION' ) ) {
  3.         if ( $id === null && ( is_front_page() || is_home() ) ) {
  4.             $id = get_queried_object_id();
  5.         } elseif ( is_singular() ) {
  6.             if ( ! $id ) {
  7.                 $id = get_the_ID();
  8.             }
  9.         }
  10.  
  11.         if ( $id ) {
  12.             if ( 'true' === vc_get_param( 'preview' ) ) {
  13.                 $latest_revision = wp_get_post_revisions( $id );
  14.                 if ( ! empty( $latest_revision ) ) {
  15.                     $array_values = array_values( $latest_revision );
  16.                     $id           = $array_values[0]->ID;
  17.                 }
  18.             }
  19.             $post_custom_css = get_metadata( 'post', $id, '_wpb_post_custom_css', true );
  20.             if ( ! empty( $post_custom_css ) ) {
  21.                 $post_custom_css = wp_strip_all_tags( $post_custom_css );
  22.                 if ( false === $inline_css ) {
  23.                     return $post_custom_css;
  24.                 }
  25.                 echo '<style id="jeg_vc_custom_css" type="text/css" data-type="jeg_vc_custom-css">';
  26.                 echo jnews_sanitize_by_pass( $post_custom_css );
  27.                 echo '</style>';
  28.             }
  29.         }
  30.     } else {
  31.         return;
  32.     }
  33. }
  34.  
  35. function load_vc_shortcode_custom_css( $id = null, $inline_css = true ) {
  36.     if ( defined( 'WPB_VC_VERSION' ) ) {
  37.         // if ( ! is_singular() ) {
  38.         //  return;
  39.         // }
  40.  
  41.         if ( ! $id ) {
  42.             $id = get_the_ID();
  43.         }
  44.  
  45.         if ( $id ) {
  46.             if ( 'true' === vc_get_param( 'preview' ) ) {
  47.                 $latest_revision = wp_get_post_revisions( $id );
  48.                 if ( ! empty( $latest_revision ) ) {
  49.                     $array_values = array_values( $latest_revision );
  50.                     $id           = $array_values[0]->ID;
  51.                 }
  52.             }
  53.             $shortcodes_custom_css = get_metadata( 'post', $id, '_wpb_shortcodes_custom_css', true );
  54.             if ( ! empty( $shortcodes_custom_css ) ) {
  55.                 $shortcodes_custom_css = wp_strip_all_tags( $shortcodes_custom_css );
  56.                 if ( false === $inline_css ) {
  57.                     return $shortcodes_custom_css;
  58.                 }
  59.                 echo '<style id="jeg_vc_shortcodes_css" type="text/css" data-type="jeg_vc_shortcodes_custom-css">';
  60.                 echo jnews_sanitize_by_pass( $shortcodes_custom_css );
  61.                 echo '</style>';
  62.             }
  63.         }
  64.     } else {
  65.         return;
  66.     }
  67. }
  68.  
  69. function jeg_render_builder_content( $page_id ) {
  70.     if ( defined( 'ELEMENTOR_VERSION' ) && \Elementor\Plugin::$instance->db->is_built_with_elementor( $page_id ) ) {
  71.         $frontend = \Elementor\Plugin::$instance->frontend;
  72.  
  73.         add_action( 'wp_enqueue_scripts', array( $frontend, 'enqueue_styles' ) );
  74.         add_action( 'wp_head', array( $frontend, 'print_fonts_links' ) );
  75.         add_action( 'wp_footer', array( $frontend, 'wp_footer' ) );
  76.  
  77.         if ( method_exists( $frontend, 'add_menu_in_admin_bar' ) ) {
  78.             jnews_admin_topbar_menu( array( $frontend, 'add_menu_in_admin_bar' ), 200 );
  79.         }
  80.  
  81.         add_action( 'wp_enqueue_scripts', array( $frontend, 'register_scripts' ), 5 );
  82.         add_action( 'wp_enqueue_scripts', array( $frontend, 'register_styles' ), 5 );
  83.  
  84.         $html = $frontend->get_builder_content( $page_id );
  85.  
  86.         add_filter( 'get_the_excerpt', array( $frontend, 'start_excerpt_flag' ), 1 );
  87.         add_filter( 'get_the_excerpt', array( $frontend, 'end_excerpt_flag' ), 20 );
  88.     } else {
  89.         load_vc_page_custom_css($page_id);
  90.         load_vc_shortcode_custom_css($page_id);
  91.  
  92.         $page = get_post( $page_id );
  93.         $html = do_shortcode( $page->post_content );
  94.     }
  95.  
  96.     return apply_filters( 'jeg_render_builder_content', $html, $page_id );
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement