diff --git a/easy-footnotes-admin.php b/easy-footnotes-admin.php index 9fdaadc..a12c97c 100644 --- a/easy-footnotes-admin.php +++ b/easy-footnotes-admin.php @@ -18,6 +18,7 @@ $hide_easy_footnote_after_posts = isset( $_POST['hide_easy_footnote_after_posts'] ) ? true : false; $show_easy_footnote_on_front = isset( $_POST['show_easy_footnote_on_front'] ) ? true : false; $reset_footnotes = isset( $_POST['reset_footnotes'] ) ? true : false; + $combine_duplicate_footnotes = isset( $_POST['combine_duplicate_footnotes'] ) ? true : false; $updateOptions = array( 'footnoteLabel' => sanitize_text_field( $easyFootnoteLabel ), @@ -25,6 +26,7 @@ 'hide_easy_footnote_after_posts' => $hide_easy_footnote_after_posts, 'show_easy_footnote_on_front' => $show_easy_footnote_on_front, 'reset_footnotes' => $reset_footnotes, + 'combine_duplicate_footnotes' => $combine_duplicate_footnotes, ); update_option( 'easy_footnotes_options', $updateOptions ); @@ -41,6 +43,7 @@ $hide_easy_footnote_after_posts = isset( $footnoteOptions['hide_easy_footnote_after_posts'] ) ? $footnoteOptions['hide_easy_footnote_after_posts'] : false; $show_easy_footnote_on_front = isset( $footnoteOptions['show_easy_footnote_on_front'] ) ? $footnoteOptions['show_easy_footnote_on_front'] : false; $reset_footnotes = isset( $footnoteOptions['reset_footnotes'] ) ? $footnoteOptions['reset_footnotes'] : false; + $combine_duplicate_footnotes = isset( $footnoteOptions['combine_duplicate_footnotes'] ) ? $footnoteOptions['combine_duplicate_footnotes'] : false; } ?> @@ -58,10 +61,14 @@
size="20">
-size="20">
-size="20">
+size="20">
+ + size="20">
+
+
+
diff --git a/easy-footnotes.php b/easy-footnotes.php index aac5122..3cf43e3 100644 --- a/easy-footnotes.php +++ b/easy-footnotes.php @@ -4,7 +4,7 @@ * Plugin URI: https://jasonyingling.me/easy-footnotes-wordpress/ * Description: Easily add footnotes to your posts with a simple shortcode. * Text Domain: easy-footnotes - * Version: 1.1.10 + * Version: 1.1.11 * Author: Jason Yingling * Author URI: https://jasonyingling.me * License: GPL2 @@ -47,7 +47,7 @@ class easyFootnotes { private $footnoteSettings; - private $version = '1.1.10'; + private $version = '1.1.11'; /** * Constructing the initial plugin options, shortcodes, and hooks. @@ -59,6 +59,7 @@ public function __construct() { 'hide_easy_footnote_after_posts' => false, 'show_easy_footnote_on_front' => false, 'reset_footnotes' => false, + 'combine_duplicate_footnotes' => false, ); add_option( 'easy_footnotes_options', $this->footnoteSettings ); @@ -68,7 +69,7 @@ public function __construct() { add_filter( 'the_content', array( $this, 'easy_footnote_after_content' ), 20 ); $this->footnoteOptions = get_option( 'easy_footnotes_options' ); - if ( isset( $this->footnoteOptions['reset_footnotes'] ) && $this->footnoteOptions['reset_footnotes'] ) { + if ( isset( $this->footnoteOptions['reset_footnotes'] ) && $this->footnoteOptions['reset_footnotes'] || ( ! isset( $this->footnoteOptions[ 'combine_duplicate_footnotes' ] ) || $this->footnoteOptions[ 'combine_duplicate_footnotes' ] === false ) ) { add_filter( 'the_content', array( $this, 'easy_footnote_reset' ), 999 ); } @@ -142,7 +143,7 @@ public function easy_footnote_shortcode( $atts, $content = null ) { $this->usedFootnoteNumbers[] = $footnote_number; // Track custom number $this->footnoteLookup[$content_id] = $footnote_number; $this->footnotes[$footnote_number] = $content; - } elseif ( isset( $this->footnoteLookup[$content_id] ) ) { + } elseif ( isset( $this->footnoteLookup[$content_id] ) && isset( $this->footnoteOptions[ 'combine_duplicate_footnotes' ] ) && $this->footnoteOptions[ 'combine_duplicate_footnotes' ] === true ) { // Use existing footnote number for duplicate content $footnote_number = $this->footnoteLookup[$content_id]; } else { @@ -216,16 +217,18 @@ public function easy_footnote_after_content( $content ) { ksort($footnotesInsert); foreach ( $footnotesInsert as $count => $footnote ) { - // If the footnote is already in the lookup, use its number - if ( isset( $this->footnoteLookup[$footnote] ) ) { - $count = $this->footnoteLookup[$footnote]; - } else { - // Skip custom numbers that were already used - while ( in_array( $footnote_number, $this->usedFootnoteNumbers ) ) { - $footnote_number++; + + if ( isset( $this->footnoteOptions[ 'combine_duplicate_footnotes' ] ) && $this->footnoteOptions[ 'combine_duplicate_footnotes' ] === true ) { + // If the footnote is already in the lookup, use its number + if ( isset( $this->footnoteLookup[$footnote] ) ) { + $count = $this->footnoteLookup[$footnote]; + } else { + // Skip custom numbers that were already used + while ( in_array( $footnote_number, $this->usedFootnoteNumbers ) ) { + $footnote_number++; + } } - } - + } // Generate back-to-top link and the footnote item $footnoteCopy .= '