Easy Table of Contents - Version 2.0.2

Version Description

Requires WordPress >

Download this release

Release Info

Developer shazahm1@hotmail.com
Plugin Icon 128x128 Easy Table of Contents
Version 2.0.2
Comparing to
See all releases

Code changes from version 2.0.1 to 2.0.2

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: table of contents, toc
5
  Requires at least: 5.2
6
  Tested up to: 5.3
7
  Requires PHP: 5.6.20
8
- Stable tag: 2.0.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -89,6 +89,11 @@ Easy Table Contents is a fork of the excellent [Table of Contents Plus](https://
89
 
90
  == Changelog ==
91
 
 
 
 
 
 
92
  = 2.0.1 03/09/2020 =
93
  * COMPATIBILITY: Exclude the WordPress Related Posts plugin nodes.
94
  * COMPATIBILITY: Exclude a couple Atomic Block plugin nodes.
@@ -322,3 +327,6 @@ Requires WordPress >= 5.0 and PHP version >= 5.6.20 (>= 7.1 is recommended).
322
 
323
  = 2.0.1 =
324
  Requires WordPress >= 5.0 and PHP version >= 5.6.20 (>= 7.1 is recommended).
 
 
 
5
  Requires at least: 5.2
6
  Tested up to: 5.3
7
  Requires PHP: 5.6.20
8
+ Stable tag: 2.0.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
89
 
90
  == Changelog ==
91
 
92
+ = 2.0.2 03/12/2020 =
93
+ * COMPATIBILITY: Remove filter to exclude Ultimate Addons for VC Composer Tabs from heading eligibility.
94
+ * COMPATIBILITY: Add additional filters to improve Elementor compatibility.
95
+ * TWEAK: Loosen heading matching when doing find/replace to insert in page links. Excluding the opening heading tag to allow matching heading where page builders dynamically add classes and id which break heading matching during find/replace.
96
+
97
  = 2.0.1 03/09/2020 =
98
  * COMPATIBILITY: Exclude the WordPress Related Posts plugin nodes.
99
  * COMPATIBILITY: Exclude a couple Atomic Block plugin nodes.
327
 
328
  = 2.0.1 =
329
  Requires WordPress >= 5.0 and PHP version >= 5.6.20 (>= 7.1 is recommended).
330
+
331
+ = 2.0.2 =
332
+ Requires WordPress >= 5.0 and PHP version >= 5.6.20 (>= 7.1 is recommended).
easy-table-of-contents.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Easy Table of Contents
4
  * Plugin URI: http://connections-pro.com/
5
  * Description: Adds a user friendly and fully automatic way to create and display a table of contents generated from the page content.
6
- * Version: 2.0.1
7
  * Author: Steven A. Zahm
8
  * Author URI: http://connections-pro.com/
9
  * Text Domain: easy-table-of-contents
@@ -26,7 +26,7 @@
26
  * @package Easy Table of Contents
27
  * @category Plugin
28
  * @author Steven A. Zahm
29
- * @version 2.0.1
30
  */
31
 
32
  use function Easy_Plugins\Table_Of_Contents\String\mb_find_replace;
@@ -47,7 +47,7 @@ if ( ! class_exists( 'ezTOC' ) ) {
47
  * @since 1.0
48
  * @var string
49
  */
50
- const VERSION = '2.0.1';
51
 
52
  /**
53
  * Stores the instance of this class.
3
  * Plugin Name: Easy Table of Contents
4
  * Plugin URI: http://connections-pro.com/
5
  * Description: Adds a user friendly and fully automatic way to create and display a table of contents generated from the page content.
6
+ * Version: 2.0.2
7
  * Author: Steven A. Zahm
8
  * Author URI: http://connections-pro.com/
9
  * Text Domain: easy-table-of-contents
26
  * @package Easy Table of Contents
27
  * @category Plugin
28
  * @author Steven A. Zahm
29
+ * @version 2.0.2
30
  */
31
 
32
  use function Easy_Plugins\Table_Of_Contents\String\mb_find_replace;
47
  * @since 1.0
48
  * @var string
49
  */
50
+ const VERSION = '2.0.2';
51
 
52
  /**
53
  * Stores the instance of this class.
includes/class.post.php CHANGED
@@ -899,7 +899,26 @@ class ezTOC_Post {
899
 
900
  if ( isset( $this->pages[ $page ] ) ) {
901
 
902
- $headings = wp_list_pluck( $this->pages[ $page ]['headings'], 0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
903
  }
904
 
905
  return $headings;
@@ -938,7 +957,7 @@ class ezTOC_Post {
938
  '</h' . $matches[ $i ][2] . '>' // end of heading
939
  ),
940
  array(
941
- $matches[ $i ][1],
942
  '<span class="ez-toc-section" id="' . $anchor . '"></span></h' . $matches[ $i ][2] . '>'
943
  ),
944
  $matches[ $i ][0]
899
 
900
  if ( isset( $this->pages[ $page ] ) ) {
901
 
902
+ //$headings = wp_list_pluck( $this->pages[ $page ]['headings'], 0 );
903
+
904
+ $matches = $this->pages[ $page ]['headings'];
905
+ $count = count( $matches );
906
+
907
+ for ( $i = 0; $i < $count; $i++ ) {
908
+
909
+ //$anchor = $matches[ $i ]['id'];
910
+ $headings[] = str_replace(
911
+ array(
912
+ $matches[ $i ][1], // start of heading
913
+ '</h' . $matches[ $i ][2] . '>' // end of heading
914
+ ),
915
+ array(
916
+ '',
917
+ '</h' . $matches[ $i ][2] . '>'
918
+ ),
919
+ $matches[ $i ][0]
920
+ );
921
+ }
922
  }
923
 
924
  return $headings;
957
  '</h' . $matches[ $i ][2] . '>' // end of heading
958
  ),
959
  array(
960
+ '',
961
  '<span class="ez-toc-section" id="' . $anchor . '"></span></h' . $matches[ $i ][2] . '>'
962
  ),
963
  $matches[ $i ][0]
includes/inc.plugin-compatibility.php CHANGED
@@ -289,7 +289,7 @@ add_filter(
289
  'ez_toc_exclude_by_selector',
290
  function( $selectors ) {
291
 
292
- $selectors['ultimate-addons-for-vc-composer'] = '.ult_tabs';
293
 
294
  return $selectors;
295
  }
@@ -309,3 +309,117 @@ add_filter(
309
  return $selectors;
310
  }
311
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  'ez_toc_exclude_by_selector',
290
  function( $selectors ) {
291
 
292
+ //$selectors['ultimate-addons-for-vc-composer'] = '.ult_tabs';
293
 
294
  return $selectors;
295
  }
309
  return $selectors;
310
  }
311
  );
312
+
313
+ class ezTOC_Elementor {
314
+
315
+ /**
316
+ * Whether the excerpt is being called.
317
+ *
318
+ * Used to determine whether the call to `the_content()` came from `get_the_excerpt()`.
319
+ *
320
+ * @since 2.0.2
321
+ *
322
+ * @var bool Whether the excerpt is being used. Default is false.
323
+ */
324
+ private $_is_excerpt = false;
325
+
326
+ /**
327
+ * ezTOC_Elementor constructor.
328
+ *
329
+ * @since 2.0.2
330
+ */
331
+ public function __construct() {
332
+
333
+ //add_filter( 'elementor/frontend/the_content', array( 'ezTOC', 'the_content' ), 100 );
334
+
335
+ // Hack to avoid enqueue post CSS while it's a `the_excerpt` call.
336
+ add_filter( 'get_the_excerpt', array( $this, 'start_excerpt_flag' ), 1 );
337
+ add_filter( 'get_the_excerpt', array( $this, 'end_excerpt_flag' ), 20 );
338
+ add_filter( 'ez_toc_maybe_apply_the_content_filter', array( $this, 'maybe_apply_the_content_filter' ) );
339
+
340
+ add_filter(
341
+ 'ez_toc_strip_shortcodes_tagnames',
342
+ function( $tags_to_remove ) {
343
+
344
+ $shortcodes = array (
345
+ 'elementor-template',
346
+ );
347
+
348
+ $tags_to_remove = array_merge( $tags_to_remove, $shortcodes );
349
+
350
+ return $tags_to_remove;
351
+ }
352
+ );
353
+ }
354
+
355
+ /**
356
+ * Callback for the `elementor/init` action.
357
+ *
358
+ * Add the compatibility filters for Elementor.
359
+ *
360
+ * @since 2.0.2
361
+ */
362
+ public static function start() {
363
+
364
+ new self();
365
+ }
366
+
367
+ /**
368
+ * Callback for the `get_the_excerpt` filter.
369
+ *
370
+ * Start excerpt flag.
371
+ *
372
+ * Flags when `the_excerpt` is called. Used to avoid enqueueing CSS in the excerpt.
373
+ *
374
+ * @since 2.0.2
375
+ *
376
+ * @param string $excerpt The post excerpt.
377
+ *
378
+ * @return string The post excerpt.
379
+ */
380
+ public function start_excerpt_flag( $excerpt ) {
381
+ $this->_is_excerpt = true;
382
+ return $excerpt;
383
+ }
384
+
385
+ /**
386
+ * Callback for the `get_the_excerpt` filter.
387
+ *
388
+ * End excerpt flag.
389
+ *
390
+ * Flags when `the_excerpt` call ended.
391
+ *
392
+ * @since 2.0.2
393
+ *
394
+ * @param string $excerpt The post excerpt.
395
+ *
396
+ * @return string The post excerpt.
397
+ */
398
+ public function end_excerpt_flag( $excerpt ) {
399
+ $this->_is_excerpt = false;
400
+ return $excerpt;
401
+ }
402
+
403
+ /**
404
+ * Callback for the `ez_toc_maybe_apply_the_content_filter` filter.
405
+ *
406
+ * If doing Elementor excerpt, which calls `the_content` filter, do not apply the ezTOC `the_content` filter.
407
+ *
408
+ * @since 2.0.2
409
+ *
410
+ * @param bool $apply
411
+ *
412
+ * @return bool mixed
413
+ */
414
+ public function maybe_apply_the_content_filter( $apply ) {
415
+
416
+ if ( $this->_is_excerpt ) {
417
+
418
+ $apply = false;
419
+ }
420
+
421
+ return $apply;
422
+ }
423
+ }
424
+ //new ezTOC_Elementor();
425
+ add_action( 'elementor/init', array( 'ezTOC_Elementor', 'start' ) );