Add option to fix line breaks
This commit is contained in:
parent
5634dd2c04
commit
afdeac9b4a
@ -372,7 +372,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
|
||||
| `show_admin_bar` | `__return_false`
|
||||
| `strip_shortcodes_tagnames` | `fictioneer_exempt_shortcodes_from_removal`
|
||||
| `style_loader_tag` | `fictioneer_add_font_awesome_integrity`
|
||||
| `the_content` | `fictioneer_embed_consent_wrappers`, `fictioneer_add_lightbox_to_post_images`, `fictioneer_add_chapter_paragraph_id`, `fictioneer_replace_br_with_whitespace`
|
||||
| `the_content` | `fictioneer_embed_consent_wrappers`, `fictioneer_add_lightbox_to_post_images`, `fictioneer_add_chapter_paragraph_id`, `fictioneer_replace_br_with_whitespace`, `fictioneer_fix_line_breaks`
|
||||
| `the_password_form` | `fictioneer_password_form`, `fictioneer_unlock_with_patreon`
|
||||
| `the_content_more_link` | `fictioneer_wrap_read_more_link`
|
||||
| `the_excerpt_rss` | `fictioneer_filter_rss_excerpt`
|
||||
|
@ -647,6 +647,38 @@ function fictioneer_add_chapter_paragraph_id( $content ) {
|
||||
}
|
||||
add_filter( 'the_content', 'fictioneer_add_chapter_paragraph_id', 10, 1 );
|
||||
|
||||
/**
|
||||
* Fixes line breaks before paragraphs are added
|
||||
*
|
||||
* @since 5.25.0
|
||||
*
|
||||
* @param string $content The content.
|
||||
*
|
||||
* @return string The modified content.
|
||||
*/
|
||||
|
||||
function fictioneer_fix_line_breaks( $content ) {
|
||||
// Return early if...
|
||||
if (
|
||||
get_post_type() !== 'fcn_chapter' ||
|
||||
! in_the_loop() ||
|
||||
! is_main_query() ||
|
||||
post_password_required()
|
||||
) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Replace single new lines
|
||||
$content = str_replace( ["\r\n", "\r"], "\n", $content );
|
||||
$content = preg_replace( '/([^\n])\n([^\n])/', "$1\n\n$2", $content );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
if ( get_option( 'fictioneer_enable_line_break_fix' ) ) {
|
||||
add_filter( 'the_content', 'fictioneer_fix_line_breaks', 1, 1 );
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// ADD LIGHTBOX TO POST IMAGES
|
||||
// =============================================================================
|
||||
|
@ -713,6 +713,12 @@ define( 'FICTIONEER_OPTIONS', array(
|
||||
'group' => 'fictioneer-settings-general-group',
|
||||
'sanitize_callback' => 'fictioneer_sanitize_checkbox',
|
||||
'default' => 0
|
||||
),
|
||||
'fictioneer_enable_line_break_fix' => array(
|
||||
'name' => 'fictioneer_enable_line_break_fix',
|
||||
'group' => 'fictioneer-settings-general-group',
|
||||
'sanitize_callback' => 'fictioneer_sanitize_checkbox',
|
||||
'default' => 0
|
||||
)
|
||||
),
|
||||
'integers' => array(
|
||||
@ -1183,6 +1189,7 @@ function fictioneer_get_option_label( $option ) {
|
||||
'fictioneer_enable_global_splide' => __( 'Enable Splide slider globally', 'fictioneer' ),
|
||||
'fictioneer_log_posts' => __( 'Log all post updates', 'fictioneer' ),
|
||||
'fictioneer_disable_menu_transients' => __( 'Disable menu Transient caching', 'fictioneer' ),
|
||||
'fictioneer_enable_line_break_fix' => __( 'Enable fixing of chapter paragraphs', 'fictioneer' ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -222,6 +222,17 @@ $images = get_template_directory_uri() . '/img/documentation/';
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="fictioneer-card__row">
|
||||
<?php
|
||||
fictioneer_settings_label_checkbox(
|
||||
'fictioneer_enable_line_break_fix',
|
||||
__( 'Enable fixing of chapter paragraphs', 'fictioneer' ),
|
||||
__( 'If you messed up copy/paste and all paragraphs are one.', 'fictioneer' ),
|
||||
__( 'If you copy and paste chapters into the editor, particularly the classic editor, paragraphs may be lost. This occurs because WordPress uses double new lines to separate content into paragraphs. If your content only has single new lines, you will get a single line break instead of a paragraph. While it is better to fix this in the content, this option can smooth things out. However, keep in mind that single line breaks will no longer be possible.', 'fictioneer' )
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="fictioneer-card__row">
|
||||
<?php
|
||||
fictioneer_settings_label_checkbox(
|
||||
|
Loading…
x
Reference in New Issue
Block a user