Allow chapter notes to ignore password

This commit is contained in:
Tetrakern 2024-02-23 12:33:52 +01:00
parent a03e396b90
commit b9058427b2
2 changed files with 26 additions and 10 deletions

View File

@ -1986,7 +1986,7 @@ function fictioneer_render_story_data_metabox( $post ) {
'fictioneer_story_global_note',
array(
'label' => _x( 'Global Note', 'Story global note meta field label.', 'fictioneer' ),
'description' => __( 'Displayed in a box above all chapters; include "[!password]" to hide in protected chapters. Limited HTML allowed.', 'fictioneer' )
'description' => __( 'Displayed in a box above all chapters; start with "[!password]" to hide in protected chapters. Limited HTML allowed.', 'fictioneer' )
)
);
@ -2717,7 +2717,7 @@ function fictioneer_render_chapter_data_metabox( $post ) {
'fictioneer_chapter_foreword',
array(
'label' => _x( 'Foreword', 'Chapter foreword meta field label.', 'fictioneer' ),
'description' => __( 'Displayed in a box above the chapter. Limited HTML allowed.', 'fictioneer' )
'description' => __( 'Displayed in a box above the chapter; start with "[!show]" to show in protected chapters. Limited HTML allowed.', 'fictioneer' )
)
);
@ -2727,7 +2727,7 @@ function fictioneer_render_chapter_data_metabox( $post ) {
'fictioneer_chapter_afterword',
array(
'label' => _x( 'Afterword', 'Chapter afterword meta field label.', 'fictioneer' ),
'description' => __( 'Displayed in a box below the chapter. Limited HTML allowed.', 'fictioneer' )
'description' => __( 'Displayed in a box below the chapter; start with "[!show]" to show in protected chapters. Limited HTML allowed.', 'fictioneer' )
)
);

View File

@ -130,21 +130,29 @@ add_action( 'fictioneer_chapter_before_header', 'fictioneer_chapter_global_note'
* Outputs the HTML for the chapter foreword section
*
* @since 5.0.0
* @since 5.11.1 - Show if started with "[!show]".
*
* @param int $args['chapter_id'] The chapter ID.
*/
function fictioneer_chapter_foreword( $args ) {
// Setup
$foreword = fictioneer_get_content_field( 'fictioneer_chapter_foreword', $args['chapter_id'] );
$note = fictioneer_get_content_field( 'fictioneer_chapter_foreword', $args['chapter_id'] );
// Abort conditions
if ( empty( $foreword ) || post_password_required() ) {
if (
empty( $note ) ||
( strpos( $note, '[!show]' ) === false && post_password_required() )
) {
return;
}
$note = str_replace( '[!show]', '', $note );
// Start HTML ---> ?>
<section id="chapter-foreword" class="chapter__foreword infobox polygon clearfix chapter-note-hideable"><?php echo $foreword; ?></section>
<section id="chapter-foreword" class="chapter__foreword infobox polygon clearfix chapter-note-hideable"><?php
echo trim( $note );
?></section>
<?php // <--- End HTML
}
add_action( 'fictioneer_chapter_before_header', 'fictioneer_chapter_foreword', 10 );
@ -436,21 +444,29 @@ add_action( 'fictioneer_chapter_actions_bottom_left', 'fictioneer_chapter_media_
* Outputs the HTML for the chapter afterword
*
* @since 5.0.0
* @since 5.11.1 - Show if started with "[!show]".
*
* @param int $args['chapter_id'] The chapter ID.
*/
function fictioneer_chapter_afterword( $args ) {
// Setup
$afterword = fictioneer_get_content_field( 'fictioneer_chapter_afterword', $args['chapter_id'] );
$note = fictioneer_get_content_field( 'fictioneer_chapter_afterword', $args['chapter_id'] );
// Abort conditions
if ( empty( $afterword ) || post_password_required() ) {
return '';
if (
empty( $note ) ||
( strpos( $note, '[!show]' ) === false && post_password_required() )
) {
return;
}
$note = str_replace( '[!show]', '', $note );
// Start HTML ---> ?>
<section id="chapter-afterword" class="chapter__afterword infobox polygon clearfix chapter-note-hideable"><?php echo $afterword; ?></section>
<section id="chapter-afterword" class="chapter__afterword infobox polygon clearfix chapter-note-hideable"><?php
echo trim( $note );
?></section>
<?php // <--- End HTML
}
add_action( 'fictioneer_chapter_after_content', 'fictioneer_chapter_afterword', 10 );