/** * Check whether current page should load theme compatibility file or not * @return bool */ function has_theme_compat() { $post_id = get_the_ID(); // in dashboard and preview, always load theme-compat file $is_using_pagebuilder = is_admin() || is_et_pb_preview() ? true : isset($post_id) && et_pb_is_pagebuilder_used($post_id); // Check whether: 1) current page uses Divi builder or 2) current theme has compatibility file if ($is_using_pagebuilder && in_array($this->get_theme_name(), $this->theme_list())) { return true; } return false; }
/** * Added specific body classes for builder related situation * This enables theme to adjust its case independently * @return array */ function et_builder_body_classes($classes) { if (is_et_pb_preview()) { $classes[] = 'et-pb-preview'; } return $classes; }
function add_builder_content_wrapper($content) { if (!et_pb_is_pagebuilder_used(get_the_ID()) && !is_et_pb_preview()) { return $content; } // Divi builder layout should only be used in singular template if (!is_singular()) { // get_the_excerpt() for excerpt retrieval causes infinite loop; thus we're using excerpt from global $post variable global $post; $read_more = sprintf(' <a href="%1$s" title="%2$s" class="more-link">%3$s</a>', esc_url(get_permalink()), sprintf(esc_attr__('Read more on %1%s', 'et_builder'), esc_html(get_the_title())), esc_html__('read more', 'et_builder')); // Use post excerpt if there's any. If there is no excerpt defined, // Generate from post content by stripping all shortcode first if (!empty($post->post_excerpt)) { return wpautop($post->post_excerpt . $read_more); } else { $shortcodeless_content = preg_replace('/\\[[^\\]]+\\]/', '', $content); return wpautop(et_wp_trim_words($shortcodeless_content, 270, $read_more)); } } $outer_class = apply_filters('et_builder_outer_content_class', array('et_builder_outer_content')); $outer_classes = implode(' ', $outer_class); $outer_id = apply_filters("et_builder_outer_content_id", "et_builder_outer_content"); $inner_class = apply_filters('et_builder_inner_content_class', array('et_builder_inner_content')); $inner_classes = implode(' ', $inner_class); $content = sprintf('<div class="%2$s" id="%4$s"> <div class="%3$s"> %1$s </div> </div>', $content, esc_attr($outer_classes), esc_attr($inner_classes), esc_attr($outer_id)); return $content; }
/** * Hook methods to WordPress * @return void */ function init_hooks() { $theme = wp_get_theme(); $version = isset($theme['Version']) ? $theme['Version'] : false; // Bail if no theme version found if (!$version) { return; } // Fixing Virtue v2.5.6 below compatibility issue // @todo once this issue is fixed in future version, run version_compare() to limit the scope of this fix // Remove Virtue's template wrapper on preview screen if (is_et_pb_preview()) { remove_filter('template_include', array('Kadence_Wrapping', 'wrap'), 101); } }
/** * Modify comment count for preview screen. Somehow WordPress' get_comments_number() doesn't get correct $post_id * param and doesn't have proper fallback to global $post if $post_id variable isn't found. This causes incorrect * comment count in preview screen * @see get_comments_number() * @see get_comments_number_text() * @see comments_number() * @return string */ function et_pb_preview_comment_count($count, $post_id) { if (is_et_pb_preview()) { global $post; $count = isset($post->comment_count) ? $post->comment_count : $count; } return $count; }
function extra_body_classes($classes) { $classes[] = 'et_extra'; if (extra_layout_used() || is_et_pb_preview() && isset($_GET['is_extra_layout'])) { $classes[] = 'et_extra_layout'; } if (et_pb_is_pagebuilder_used(get_the_ID())) { $classes[] = 'et_pb_pagebuilder_layout'; } if (true === et_get_option('primary_nav_fullwidth', false)) { $classes[] = 'et_fullwidth_nav'; } if (true === et_get_option('secondary_nav_fullwidth', false)) { $classes[] = 'et_fullwidth_secondary_nav'; } if ('on' === et_get_option('extra_fixed_nav', 'on')) { $classes[] = 'et_fixed_nav'; if (et_get_option('hide_nav_until_scroll', false)) { $classes[] = 'et_hide_nav'; } if (et_get_option('fixed_nav_hide_logo_image', false)) { $classes[] = 'et_fixed_nav_hide_logo_image'; } } else { if ('on' !== et_get_option('extra_fixed_nav', 'on')) { $classes[] = 'et_non_fixed_nav'; } } if (is_page_template('page-template-fullwidth.php')) { $classes[] = 'et_pb_pagebuilder_fullwidth'; } $classes = array_merge($classes, (array) extra_customizer_selector_classes('body')); return $classes; }
function shortcode_callback($atts, $content = null, $function_name) { $module_id = $this->shortcode_atts['module_id']; $module_class = $this->shortcode_atts['module_class']; $title = $this->shortcode_atts['title']; $meta = $this->shortcode_atts['meta']; $author = $this->shortcode_atts['author']; $date = $this->shortcode_atts['date']; $date_format = $this->shortcode_atts['date_format']; $categories = $this->shortcode_atts['categories']; $comments = $this->shortcode_atts['comments']; $featured_image = $this->shortcode_atts['featured_image']; $featured_placement = $this->shortcode_atts['featured_placement']; $parallax_effect = $this->shortcode_atts['parallax_effect']; $parallax_method = $this->shortcode_atts['parallax_method']; $text_orientation = $this->shortcode_atts['text_orientation']; $text_color = $this->shortcode_atts['text_color']; $text_background = $this->shortcode_atts['text_background']; $text_bg_color = $this->shortcode_atts['text_bg_color']; $module_bg_color = $this->shortcode_atts['module_bg_color']; // display the shortcode only on singlular pages if (!is_singular()) { return; } $module_class = ET_Builder_Element::add_module_order_class($module_class, $function_name); $output = ''; $featured_image_output = ''; $parallax_background_contaier = ''; if ('on' === $featured_image && ('above' === $featured_placement || 'below' === $featured_placement)) { $featured_image_output = sprintf('<div class="et_pb_title_featured_container">%1$s</div>', get_the_post_thumbnail(get_the_ID(), 'large')); } if ('on' === $title) { if (is_et_pb_preview() && isset($_POST['post_title']) && wp_verify_nonce($_POST['et_pb_preview_nonce'], 'et_pb_preview_nonce')) { $post_title = sanitize_text_field(wp_unslash($_POST['post_title'])); } else { $post_title = get_the_title(); } $output .= sprintf('<h1>%s</h1>', $post_title); } if ('on' === $meta) { $meta_array = array(); foreach (array('author', 'date', 'categories', 'comments') as $single_meta) { if ('on' === ${$single_meta} && ('categories' !== $single_meta || 'categories' === $single_meta && is_singular('post'))) { $meta_array[] = $single_meta; } } $output .= sprintf('<p class="et_pb_title_meta_container">%1$s</p>', et_pb_postinfo_meta($meta_array, $date_format, esc_html__('0 comments', 'et_builder'), esc_html__('1 comment', 'et_builder'), '% ' . esc_html__('comments', 'et_builder'))); } if ('on' === $featured_image && 'background' === $featured_placement) { $featured_image_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full'); ET_Builder_Element::set_style($function_name, array('selector' => sprintf('%%order_class%% %1$s', 'on' === $parallax_effect ? '.et_parallax_bg' : ''), 'declaration' => sprintf('background-image: url("%1$s");', esc_url($featured_image_src[0])))); if ('on' === $parallax_effect) { $parallax_background_contaier = sprintf('<div class="et_parallax_bg%1$s"></div>', 'on' === $parallax_method ? ' et_pb_parallax_css' : ''); } } if ('on' === $text_background) { ET_Builder_Element::set_style($function_name, array('selector' => '%%order_class%% .et_pb_title_container', 'declaration' => sprintf('background-color: %1$s; padding: 1em 1.5em;', esc_html($text_bg_color)))); } ET_Builder_Element::set_style($function_name, array('selector' => '%%order_class%%', 'declaration' => sprintf('text-align: %1$s;', esc_html($text_orientation)))); $background_layout = 'dark' === $text_color ? 'light' : 'dark'; $module_class .= ' et_pb_bg_layout_' . $background_layout; $module_class .= 'above' === $featured_placement ? ' et_pb_image_above' : ''; $module_class .= 'below' === $featured_placement ? ' et_pb_image_below' : ''; ET_Builder_Element::set_style($function_name, array('selector' => '%%order_class%%', 'declaration' => sprintf('background-color: %1$s;', esc_html($module_bg_color)))); $output = sprintf('<div%3$s class="et_pb_module et_pb_post_title %2$s%4$s"> %5$s %6$s <div class="et_pb_title_container"> %1$s </div> %7$s </div>', $output, '' !== $module_class ? sprintf(' %1$s', esc_attr($module_class)) : '', '' !== $module_id ? sprintf(' id="%1$s"', esc_attr($module_id)) : '', 'on' === $featured_image && 'background' === $featured_placement ? ' et_pb_featured_bg' : '', $parallax_background_contaier, 'on' === $featured_image && 'above' === $featured_placement ? $featured_image_output : '', 'on' === $featured_image && 'below' === $featured_placement ? $featured_image_output : ''); return $output; }