Remove default chapter icons from post meta
There is no need to bloat the table with them. This also allows to replace the default icon without having to do a database update.
This commit is contained in:
parent
4f23b4364b
commit
1a07af1988
@ -237,7 +237,7 @@ These are the protected meta fields used specifically for the **fcn_chapter** po
|
||||
| fictioneer_chapter_foreword | string | Content of the chapter foreword.
|
||||
| fictioneer_chapter_afterword | string | Content of the chapter afterword.
|
||||
| fictioneer_chapter_password_note | string | Content of the note shown if the story is password protected.
|
||||
| fictioneer_chapter_icon | string | Font Awesome icon class string.
|
||||
| fictioneer_chapter_icon | string | Font Awesome icon class string. Empty if default icon.
|
||||
| fictioneer_chapter_text_icon | string | Text string in place of an icon.
|
||||
| fictioneer_chapter_short_title | string | Shorter variant title. Not used by default, intended for child themes.
|
||||
| fictioneer_chapter_prefix | string | Prefix for titles in chapter lists.
|
||||
|
@ -108,9 +108,6 @@ function fictioneer_migrate_chapters( $query_args = [], $story_args = [], $previ
|
||||
update_post_meta( $post->ID, 'fictioneer_chapter_story', $story_id );
|
||||
}
|
||||
|
||||
// Set default chapter icon
|
||||
update_post_meta( $post->ID, 'fictioneer_chapter_icon', 'fa-solid fa-book' );
|
||||
|
||||
// Update other meta
|
||||
update_post_meta( $post->ID, 'fictioneer_first_publish_date', $post->post_date_gmt );
|
||||
|
||||
|
@ -158,7 +158,6 @@ function fictioneer_generate_test_content() {
|
||||
fictioneer_generate_test_comments( $chapter_id, $comment_count );
|
||||
|
||||
update_post_meta( $chapter_id, 'fictioneer_chapter_story', $story_id );
|
||||
update_post_meta( $chapter_id, 'fictioneer_chapter_icon', 'fa-solid fa-book' );
|
||||
update_post_meta( $chapter_id, 'fictioneer_first_publish_date', current_time( 'mysql', true ) );
|
||||
}
|
||||
}
|
||||
|
@ -729,6 +729,7 @@ function fictioneer_get_metabox_tokens( $post, $meta_key, $options, $args = [] )
|
||||
function fictioneer_get_metabox_icons( $post, $meta_key, $args = [] ) {
|
||||
// Setup
|
||||
$meta_value = esc_attr( get_post_meta( $post->ID, $meta_key, true ) );
|
||||
$meta_value = $meta_value ? $meta_value : FICTIONEER_DEFAULT_CHAPTER_ICON;
|
||||
$label = strval( $args['label'] ?? '' );
|
||||
$description = strval( $args['description'] ?? '' );
|
||||
$placeholder = strval( $args['placeholder'] ?? '' );
|
||||
@ -2973,11 +2974,15 @@ function fictioneer_save_chapter_metaboxes( $post_id ) {
|
||||
|
||||
// Valid?
|
||||
if ( ! $icon_object && ( empty( $icon ) || strpos( $icon, 'fa-' ) !== 0 ) ) {
|
||||
$icon = FICTIONEER_DEFAULT_CHAPTER_ICON;
|
||||
$icon = '';
|
||||
}
|
||||
|
||||
if ( $icon_object && ( ! property_exists( $icon_object, 'style' ) || ! property_exists( $icon_object, 'id' ) ) ) {
|
||||
$icon = FICTIONEER_DEFAULT_CHAPTER_ICON;
|
||||
$icon = '';
|
||||
}
|
||||
|
||||
if ( $icon === FICTIONEER_DEFAULT_CHAPTER_ICON ) {
|
||||
$icon = ''; // Do not save default icon
|
||||
}
|
||||
|
||||
$fields['fictioneer_chapter_icon'] = $icon;
|
||||
|
@ -389,6 +389,29 @@ function fictioneer_clean_up_discord_trigger_meta_fields() {
|
||||
}
|
||||
add_action( 'fictioneer_after_update', 'fictioneer_clean_up_discord_trigger_meta_fields' );
|
||||
|
||||
/**
|
||||
* Removed default chapter icons from post meta table
|
||||
*
|
||||
* @since 5.24.1
|
||||
*/
|
||||
|
||||
function fictioneer_remove_default_chapter_icons_from_meta() {
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"
|
||||
DELETE FROM $wpdb->postmeta
|
||||
WHERE meta_key = %s
|
||||
AND meta_value = %s
|
||||
",
|
||||
'fictioneer_chapter_icon',
|
||||
FICTIONEER_DEFAULT_CHAPTER_ICON
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'fictioneer_after_update', 'fictioneer_remove_default_chapter_icons_from_meta' );
|
||||
|
||||
// =============================================================================
|
||||
// PROTECT META FIELDS
|
||||
// =============================================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user