Release urgent feature 2.7.0 in response to request from user @grflukas.

https://wordpress.org/support/topic/multiple-reference-containers-in-single-post/
Bundled with two bugfixes.
https://github.com/markcheret/footnotes/issues/65
https://github.com/markcheret/footnotes/issues/71
Last release directly to SVN.
= 2.7.0 =
- Adding: Reference container: optionally per section by shortcode, thanks to @grflukas issue report.
- Bugfix: Excerpts: make excerpt handling backward compatible, thanks to @mfessler bug report.
- Bugfix: Dashboard: debug the 'Quick start guide' tab, thanks to @rumperuu bug report.

git-svn-id: https://plugins.svn.wordpress.org/footnotes/trunk@2515217 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
pewgeuges 2021-04-14 23:10:29 +00:00
parent dc225809ba
commit a02cdacb7f
12 changed files with 189 additions and 83 deletions

View file

@ -490,13 +490,22 @@ class MCI_Footnotes_Task {
add_filter( 'pum_popup_content', array( $this, 'footnotes_in_content' ), $l_int_the_content_priority );
}
/**
* Adds a filter to the excerpt hook.
*
* @since 1.5.0 The hook 'get_the_excerpt' is filtered too.
* @since 1.5.5 The hook 'get_the_excerpt' is removed but not documented in changelog or docblock.
* @since 2.6.2 The hook 'get_the_excerpt' is readded when attempting to debug excerpt handling.
* @since 2.6.6 The hook 'get_the_excerpt' is removed again because it seems to cause issues in some themes.
*/
if ( MCI_Footnotes_Convert::to_bool( MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_EXPERT_LOOKUP_THE_EXCERPT ) ) ) {
add_filter( 'the_excerpt', array( $this, 'footnotes_in_excerpt' ), $l_int_the_excerpt_priority );
add_filter( 'get_the_excerpt', array( $this, 'footnotes_in_excerpt' ), $l_int_the_excerpt_priority );
add_filter( 'the_excerpt', array( $this, 'footnotes_in_excerpt' ), $l_int_the_excerpt_priority );
}
if ( MCI_Footnotes_Convert::to_bool( MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_EXPERT_LOOKUP_WIDGET_TITLE ) ) ) {
add_filter( 'widget_title', array( $this, 'footnotes_in_widget_title' ), $l_int_widget_title_priority );
}
if ( MCI_Footnotes_Convert::to_bool( MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_EXPERT_LOOKUP_WIDGET_TEXT ) ) ) {
add_filter( 'widget_text', array( $this, 'footnotes_in_widget_text' ), $l_int_widget_text_priority );
}
@ -1095,32 +1104,82 @@ class MCI_Footnotes_Task {
* Replaces footnotes in the content of the current page/post.
*
* @since 1.5.0
*
* - Adding: Reference container: optionally per section by shortcode, thanks to @grflukas issue report.
*
* @reporter @grflukas
* @link https://wordpress.org/support/topic/multiple-reference-containers-in-single-post/
*
* @since 2.7.0
* @param string $p_str_content Page/Post content.
* @return string $p_str_content Content with replaced footnotes.
*/
public function footnotes_in_content( $p_str_content ) {
// phpcs:disable WordPress.PHP.YodaConditions.NotYoda
// Appends the reference container if set to "post_end".
return $this->exec( $p_str_content, 'post_end' === MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_REFERENCE_CONTAINER_POSITION ) );
// phpcs:enable WordPress.PHP.YodaConditions.NotYoda
$l_str_ref_container_position = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_REFERENCE_CONTAINER_POSITION );
$l_str_footnote_section_shortcode = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTE_SECTION_SHORTCODE );
$l_int_footnote_section_shortcode_length = strlen( $l_str_footnote_section_shortcode );
if ( strpos( $p_str_content, $l_str_footnote_section_shortcode ) === false ) {
// phpcs:disable WordPress.PHP.YodaConditions.NotYoda
// Appends the reference container if set to "post_end".
return $this->exec( $p_str_content, 'post_end' === $l_str_ref_container_position );
// phpcs:enable WordPress.PHP.YodaConditions.NotYoda
} else {
$l_str_rest_content = $p_str_content;
$l_arr_sections_raw = array();
$l_arr_sections_processed = array();
do {
$l_int_section_end = strpos( $l_str_rest_content, $l_str_footnote_section_shortcode );
$l_arr_sections_raw[] = substr( $l_str_rest_content, 0, $l_int_section_end );
$l_str_rest_content = substr( $l_str_rest_content, $l_int_section_end + $l_int_footnote_section_shortcode_length );
} while ( strpos( $l_str_rest_content, $l_str_footnote_section_shortcode ) !== false );
$l_arr_sections_raw[] = $l_str_rest_content;
foreach ( $l_arr_sections_raw as $l_str_section ) {
$l_arr_sections_processed[] = self::exec( $l_str_section, true );
}
$p_str_content = implode( $l_arr_sections_processed );
return $p_str_content;
}
}
/**
* Replaces existing excerpt with a new one generated on the basis of the post.
* Processes existing excerpt or replaces it with a new one generated on the basis of the post.
*
* @since 1.5.0
* @param string $p_str_excerpt Excerpt content.
* @return string $p_str_excerpt Excerpt as-is.
* The input was already the processed excerpt, no more footnotes to search.
* @return string $p_str_excerpt Processed or new excerpt.
* @since 2.6.2 Debug No option.
* @since 2.6.3 Debug Yes option, the setting becomes fully effective.
*
* - Bugfix: Excerpts: make excerpt handling backward compatible, thanks to @mfessler bug report.
*
* @reporter @mfessler
* @link https://github.com/markcheret/footnotes/issues/65
*
* @since 2.7.0
* The input was already the processed excerpt, no more footnotes to search.
* But issue #65 brought up that manual excerpts can include processable footnotes.
* Default 'manual' is fallback and is backward compatible with the initial setup.
*/
public function footnotes_in_excerpt( $p_str_excerpt ) {
if ( MCI_Footnotes_Convert::to_bool( MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_IN_EXCERPT ) ) ) {
$l_str_excerpt_mode = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_IN_EXCERPT );
if ( 'yes' === $l_str_excerpt_mode ) {
return $this->generate_excerpt_with_footnotes( $p_str_excerpt );
} else {
} elseif ( 'no' === $l_str_excerpt_mode ) {
return $this->generate_excerpt( $p_str_excerpt );
} else {
return $this->exec( $p_str_excerpt );
}
}