isPageEditable() ) { $apply = false; } } return $apply; } ); /** * Do not allow `the_content` TOC callback to run when editing a page in WPBakery Page Builder. * * @link https://wordpress.org/support/topic/correct-method-to-determine-if-using-frontend-editor/#post-12404679 * * @since 2.0 */ add_filter( 'ez_toc_maybe_apply_the_content_filter', function( $apply ) { if ( function_exists( 'vc_is_page_editable' ) ) { if ( vc_is_page_editable() ) { $apply = false; } } return $apply; } ); /** * Filter to remove WPBakery Page Builder related shortcodes from being processed as eligible TOC items. * * @since 2.0 */ add_filter( 'ez_toc_strip_shortcodes_tagnames', function( $tags_to_remove ) { $shortcodes = array ( 'vc_tta_section', ); $tags_to_remove = array_merge( $tags_to_remove, $shortcodes ); return $tags_to_remove; } ); /** * Exclude the TOC shortcodes from being processed in the admin in the Divi Theme by Elegant Themes. * * @since 2.0 */ add_action( 'et_pb_admin_excluded_shortcodes', function( $shortcodes ) { $shortcodes[] = 'ez-toc'; $shortcodes[] = apply_filters( 'ez_toc_shortcode', 'toc' ); return $shortcodes; } ); /** * Callback the for `et_builder_render_layout` filter. * * Attaches the ezTOC `the_content` filter callback to the Divi layout content filter so the in page anchors will be * added the post content. * * NOTE: Set priority 12 to run after Divi runs the `do_shortcode` filter on its layout content. * * @link https://wordpress.org/support/topic/anchor-links-not-being-added-with-divi/ * * @since 2.0 */ add_filter( 'et_builder_render_layout', array( 'ezTOC', 'the_content' ), 12, 1 ); /** * Add support for the Uncode Theme. * * @link http://www.undsgn.com/ * * @since 2.0.11 */ add_action( 'after_setup_theme', function() { if ( function_exists( 'uncode_setup' ) ) { add_filter( 'uncode_single_content_final_output', array( 'ezTOC', 'the_content' ), 10, 1 ); add_filter( 'ez_toc_apply_filter_status_manually', '__return_false' , 10, 1 ); } }, 11 ); /** * Remove the Starbox plugin node from the post content before extracting headings. * @link https://wordpress.org/plugins/starbox/ * @since 2.0 */ add_filter( 'ez_toc_exclude_by_selector', function( $selectors ) { $selectors['starbox'] = '.abh_box'; return $selectors; } ); /** * Remove the WordPress Related Posts plugin node from the post content before extracting headings. * @link * @since 2.0 */ add_filter( 'ez_toc_exclude_by_selector', function( $selectors ) { $selectors['wordpress-23-related-posts-plugin'] = '.wp_rp_content'; return $selectors; } ); /** * Remove the Atomic Blocks plugin node from the post content before extracting headings. * @link * @since 2.0 */ add_filter( 'ez_toc_exclude_by_selector', function( $selectors ) { $selectors['atomic-blocks-cta'] = '.ab-block-cta'; $selectors['atomic-blocks-testimonial'] = '.ab-block-testimonial'; return $selectors; } ); /** * Remove the Ultimate Addons for VC Composer node from the post content before extracting headings. * @link * @since 2.0 */ add_filter( 'ez_toc_exclude_by_selector', function( $selectors ) { $selectors['ultimate-addons-for-vc-composer'] = '.ult_tabs'; return $selectors; } ); /** * Remove the WP Product Review node from the post content before extracting headings. * @link * @since 2.0 */ add_filter( 'ez_toc_exclude_by_selector', function( $selectors ) { $selectors['wp-product-review'] = '.wppr-review-container'; return $selectors; } ); /** * Remove the Contextual Related Posts node from the post content before extracting headings. * * @link https://wordpress.org/plugins/contextual-related-posts/ * @since 2.0.9 */ add_filter( 'ez_toc_exclude_by_selector', function( $selectors ) { $selectors['contextual-related-posts'] = '.crp_related'; return $selectors; } ); class ezTOC_Elementor { /** * Whether the excerpt is being called. * * Used to determine whether the call to `the_content()` came from `get_the_excerpt()`. * * @since 2.0.2 * * @var bool Whether the excerpt is being used. Default is false. */ private $_is_excerpt = false; /** * ezTOC_Elementor constructor. * * @since 2.0.2 */ public function __construct() { // Hack to avoid enqueue post CSS while it's a `the_excerpt` call. add_filter( 'get_the_excerpt', array( $this, 'start_excerpt_flag' ), 1 ); add_filter( 'get_the_excerpt', array( $this, 'end_excerpt_flag' ), 20 ); add_filter( 'ez_toc_maybe_apply_the_content_filter', array( $this, 'maybe_apply_the_content_filter' ) ); add_filter( 'ez_toc_strip_shortcodes_tagnames', function( $tags_to_remove ) { $shortcodes = array ( 'elementor-template', ); $tags_to_remove = array_merge( $tags_to_remove, $shortcodes ); return $tags_to_remove; } ); } /** * Callback for the `elementor/init` action. * * Add the compatibility filters for Elementor. * * @since 2.0.2 */ public static function start() { new self(); } /** * Callback for the `get_the_excerpt` filter. * * Start excerpt flag. * * Flags when `the_excerpt` is called. Used to avoid enqueueing CSS in the excerpt. * * @since 2.0.2 * * @param string $excerpt The post excerpt. * * @return string The post excerpt. */ public function start_excerpt_flag( $excerpt ) { $this->_is_excerpt = true; return $excerpt; } /** * Callback for the `get_the_excerpt` filter. * * End excerpt flag. * * Flags when `the_excerpt` call ended. * * @since 2.0.2 * * @param string $excerpt The post excerpt. * * @return string The post excerpt. */ public function end_excerpt_flag( $excerpt ) { $this->_is_excerpt = false; return $excerpt; } /** * Callback for the `ez_toc_maybe_apply_the_content_filter` filter. * * If doing Elementor excerpt, which calls `the_content` filter, do not apply the ezTOC `the_content` filter. * * @since 2.0.2 * * @param bool $apply * * @return bool mixed */ public function maybe_apply_the_content_filter( $apply ) { if ( $this->_is_excerpt ) { $apply = false; } return $apply; } } add_action( 'elementor/init', array( 'ezTOC_Elementor', 'start' ) ); /** * Do not allow `the_content` TOC callback to run when on WooCommerce pages. * * @link https://docs.woocommerce.com/document/conditional-tags/ * @link https://wordpress.stackexchange.com/a/246525/59053 * * @since 2.0.11 */ add_filter( 'ez_toc_maybe_apply_the_content_filter', function( $apply ) { $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); // Just in case an array is not returned. if ( ! is_array( $active_plugins ) ) { $active_plugins = array(); } $string = implode( '|', $active_plugins ); if ( class_exists( 'WooCommerce' ) && FALSE !== stripos( $string, 'woocommerce.php' ) ) { /** @noinspection PhpUndefinedFunctionInspection */ if ( is_shop() || is_product_tag() || is_cart() || is_checkout() || is_account_page() || is_wc_endpoint_url() ) { $apply = false; } } return $apply; } ); /** * Beaver Builder Plugin Customization * for remove excluding heading contents * @since 2.0.34 */ add_filter( 'fl_builder_layout_data', 'ez_toc_flbuilder_layout_data', 12, 1 ); function ez_toc_flbuilder_layout_data( $data ) { if( has_action( 'the_content' ) ) { if(!empty($data)){ foreach( $data as $nodeKey => $node ){ $data[$nodeKey] = $node; } } } return $data; } /** * Kalium - Medical Theme Compatibility * remove duplicate eztoc containers * in faq sections * @since 2.0.38 */ if ( in_array( 'js_composer/js_composer.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && ( 'Kalium - Medical Theme' == apply_filters( 'current_theme', get_option( 'current_theme' ) ) || 'Kalium' == apply_filters( 'current_theme', get_option( 'current_theme' ) ) ) ) { add_shortcode( 'vc_toggle', 'eztoc_vc_toggle_modified' ); function eztoc_vc_toggle_modified( $atts, $content, $tag ) { if ( 'vc_toggle' == $tag ) { /** * Shortcode attributes * @var $atts * @var $title * @var $el_class * @var $style * @var $color * @var $size * @var $open * @var $css_animation * @var $el_id * @var $content - shortcode content * @var $css * Shortcode class * @var WPBakeryShortCode_Vc_Toggle $this_WPBakeryShortCode_Vc_Toggle */ $title = $el_class = $style = $color = $size = $open = $css_animation = $css = $el_id = ''; $inverted = false; $atts = vc_map_get_attributes('vc_toggle', $atts); extract($atts); // checking is color inverted $style = str_replace('_outline', '', $style, $inverted); /** * @since 4.4 */ $elementClass = array( 'base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'vc_toggle', 'vc_toggle', $atts), // TODO: check this code, don't know how to get base class names from params 'style' => 'vc_toggle_' . $style, 'color' => ( $color ) ? 'vc_toggle_color_' . $color : '', 'inverted' => ( $inverted ) ? 'vc_toggle_color_inverted' : '', 'size' => ( $size ) ? 'vc_toggle_size_' . $size : '', 'open' => ( 'true' === $open ) ? 'vc_toggle_active' : '', 'extra' => $atts['css'], 'css_animation' => '', // TODO: remove getCssAnimation as function in helpers ); $class_to_filter = trim(implode(' ', $elementClass)); $class_to_filter .= vc_shortcode_custom_css_class($css, ' '); $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $class_to_filter, 'vc_toggle', $atts); $heading_output = apply_filters('wpb_toggle_heading', $atts['title'], array( 'title' => $title, 'open' => $open, )); $output = '