Easy Table of Contents - Version 2.0.3

Version Description

Requires WordPress >

Download this release

Release Info

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

Code changes from version 2.0.2 to 2.0.3

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.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -89,6 +89,10 @@ Easy Table Contents is a fork of the excellent [Table of Contents Plus](https://
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.
@@ -330,3 +334,6 @@ 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).
 
 
 
5
  Requires at least: 5.2
6
  Tested up to: 5.3
7
  Requires PHP: 5.6.20
8
+ Stable tag: 2.0.3
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
+ * TWEAK: Slightly tighten heading matching, last update made it a little too loose.
94
+ * BUG: Correct logic required to place TOC before first heading which is required for the more lax heading matching required for page builders.
95
+
96
  = 2.0.2 03/12/2020 =
97
  * COMPATIBILITY: Remove filter to exclude Ultimate Addons for VC Composer Tabs from heading eligibility.
98
  * COMPATIBILITY: Add additional filters to improve Elementor compatibility.
334
 
335
  = 2.0.2 =
336
  Requires WordPress >= 5.0 and PHP version >= 5.6.20 (>= 7.1 is recommended).
337
+
338
+ = 2.0.3 =
339
+ 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.2
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.2
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.2';
51
 
52
  /**
53
  * Stores the instance of this class.
@@ -601,8 +601,25 @@ if ( ! class_exists( 'ezTOC' ) ) {
601
 
602
  case 'before':
603
  default:
604
- $replace[0] = $html . $replace[0];
605
  $content = mb_find_replace( $find, $replace, $content );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
606
  }
607
 
608
  return $content;
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.3
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.3
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.3';
51
 
52
  /**
53
  * Stores the instance of this class.
601
 
602
  case 'before':
603
  default:
604
+ //$replace[0] = $html . $replace[0];
605
  $content = mb_find_replace( $find, $replace, $content );
606
+
607
+ $pattern = '`<h[1-6]{1}[^>]*' . preg_quote( $replace[0], '`' ) . '`msuU';
608
+ $result = preg_match( $pattern, $content, $matches );
609
+
610
+ /*
611
+ * Try to place TOC before the first heading found in eligible heading, failing that,
612
+ * insert TOC at top of content.
613
+ */
614
+ if ( 1 === $result ) {
615
+
616
+ $start = strpos( $content, $matches[0] );
617
+ $content = substr_replace( $content, $html, $start, 0 );
618
+
619
+ } else {
620
+
621
+ $content = $html . $content;
622
+ }
623
  }
624
 
625
  return $content;
includes/class.post.php CHANGED
@@ -913,7 +913,7 @@ class ezTOC_Post {
913
  '</h' . $matches[ $i ][2] . '>' // end of heading
914
  ),
915
  array(
916
- '',
917
  '</h' . $matches[ $i ][2] . '>'
918
  ),
919
  $matches[ $i ][0]
@@ -957,7 +957,7 @@ class ezTOC_Post {
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]
913
  '</h' . $matches[ $i ][2] . '>' // end of heading
914
  ),
915
  array(
916
+ '>',
917
  '</h' . $matches[ $i ][2] . '>'
918
  ),
919
  $matches[ $i ][0]
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]