Add additional chapter bulk edit fields
This commit is contained in:
parent
4354eb7177
commit
65d64c7b83
@ -298,7 +298,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
|
||||
| `publish_to_draft` | `fictioneer_chapter_to_draft`
|
||||
| `rest_api_init` | `fictioneer_register_endpoint_get_story_comments`
|
||||
| `restrict_manage_posts` | `fictioneer_add_chapter_story_filter_dropdown`
|
||||
| `save_post` | `fictioneer_refresh_chapters_schema`, `fictioneer_refresh_chapter_schema`, `fictioneer_refresh_collections_schema`, `fictioneer_refresh_post_caches`, `fictioneer_refresh_post_schema`, `fictioneer_refresh_recommendations_schema`, `fictioneer_refresh_recommendation_schema`, `fictioneer_refresh_stories_schema`, `fictioneer_refresh_story_schema`, `fictioneer_save_seo_metabox`, `fictioneer_save_word_count`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_update_shortcode_relationships`, `fictioneer_purge_transients`, `fictioneer_save_story_metaboxes`, `fictioneer_save_chapter_metaboxes`, `fictioneer_save_advanced_metabox`, `fictioneer_save_support_links_metabox`, `fictioneer_save_collection_metaboxes`, `fictioneer_save_recommendation_metaboxes`, `fictioneer_save_post_metaboxes`, `fictioneer_delete_cached_story_card_after_update`, `fictioneer_rebuild_story_data_collection`, `fictioneer_post_chapter_to_discord`, `fictioneer_bulk_edit_save_patreon`
|
||||
| `save_post` | `fictioneer_refresh_chapters_schema`, `fictioneer_refresh_chapter_schema`, `fictioneer_refresh_collections_schema`, `fictioneer_refresh_post_caches`, `fictioneer_refresh_post_schema`, `fictioneer_refresh_recommendations_schema`, `fictioneer_refresh_recommendation_schema`, `fictioneer_refresh_stories_schema`, `fictioneer_refresh_story_schema`, `fictioneer_save_seo_metabox`, `fictioneer_save_word_count`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_update_shortcode_relationships`, `fictioneer_purge_transients`, `fictioneer_save_story_metaboxes`, `fictioneer_save_chapter_metaboxes`, `fictioneer_save_advanced_metabox`, `fictioneer_save_support_links_metabox`, `fictioneer_save_collection_metaboxes`, `fictioneer_save_recommendation_metaboxes`, `fictioneer_save_post_metaboxes`, `fictioneer_delete_cached_story_card_after_update`, `fictioneer_rebuild_story_data_collection`, `fictioneer_post_chapter_to_discord`, `fictioneer_bulk_edit_save_patreon`, `fictioneer_bulk_edit_save_chapter_fields`
|
||||
| `send_headers` | `fictioneer_block_pages_from_indexing`
|
||||
| `show_user_profile` | `fictioneer_custom_profile_fields`
|
||||
| `shutdown` | `fictioneer_save_story_card_cache`, `fictioneer_save_query_result_cache_registry`
|
||||
|
File diff suppressed because one or more lines are too long
@ -4632,3 +4632,147 @@ if (
|
||||
|
||||
add_action( 'save_post', 'fictioneer_bulk_edit_save_patreon' );
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// CHAPTER LIST VIEW AND BULK EDIT
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Add chapter meta fields to bulk edit
|
||||
*
|
||||
* @since 5.24.1
|
||||
*
|
||||
* @param string $column_name Name of the column to edit.
|
||||
* @param string $post_type The post type slug.
|
||||
*/
|
||||
|
||||
function fictioneer_add_bulk_edit_chapter_meta( $column_name, $post_type ) {
|
||||
// Check post type
|
||||
if ( $post_type !== 'fcn_chapter' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure this function is only executed once
|
||||
static $added = false;
|
||||
|
||||
if ( $added ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$added = true;
|
||||
|
||||
// Start HTML ---> ?>
|
||||
|
||||
<p class="bulk-edit-help"><?php _e( 'Use <code>_remove</code> to remove current values.', 'fictioneer' ); ?></p>
|
||||
|
||||
<?php if ( ! get_option( 'fictioneer_hide_chapter_icons' ) ) : ?>
|
||||
<fieldset class="inline-edit-col-right">
|
||||
<div class="inline-edit-chapter-icon-wrap">
|
||||
<label class="inline-edit-chapter-icon">
|
||||
<span class="title"><?php _ex( 'Icon', 'Chapter icon meta field label.', 'fictioneer' ); ?></span>
|
||||
<input type="text" name="bulk_edit_fictioneer_chapter_icon" autocomplete="off" autocorrect="off">
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php if ( get_option( 'fictioneer_enable_advanced_meta_fields' ) ) : ?>
|
||||
<fieldset class="inline-edit-col-right">
|
||||
<div class="inline-edit-chapter-text-icon-wrap">
|
||||
<label class="inline-edit-chapter-text-icon">
|
||||
<span class="title"><?php _ex( 'Text Icon', 'Chapter text icon meta field label.', 'fictioneer' ); ?></span>
|
||||
<input type="text" name="bulk_edit_fictioneer_chapter_text_icon" autocomplete="off" autocorrect="off">
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( get_option( 'fictioneer_enable_advanced_meta_fields' ) ) : ?>
|
||||
<fieldset class="inline-edit-col-right">
|
||||
<div class="inline-edit-chapter-prefix-wrap">
|
||||
<label class="inline-edit-chapter-prefix">
|
||||
<span class="title"><?php _ex( 'Prefix', 'Chapter prefix meta field label.', 'fictioneer' ); ?></span>
|
||||
<input type="text" name="bulk_edit_fictioneer_chapter_prefix" autocomplete="off" autocorrect="off">
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
|
||||
<fieldset class="inline-edit-col-right">
|
||||
<div class="inline-edit-chapter-group-wrap">
|
||||
<label class="inline-edit-chapter-group">
|
||||
<span class="title"><?php _ex( 'Group', 'Chapter group meta field label.', 'fictioneer' ); ?></span>
|
||||
<input type="text" name="bulk_edit_fictioneer_chapter_group" autocomplete="off" autocorrect="off">
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php // <--- End HTML
|
||||
}
|
||||
add_action( 'bulk_edit_custom_box', 'fictioneer_add_bulk_edit_chapter_meta', 10, 2 );
|
||||
|
||||
/**
|
||||
* Save chapter bulk edit fields
|
||||
*
|
||||
* @since 5.24.1
|
||||
*
|
||||
* @param int $post_id ID of the updated post.
|
||||
*/
|
||||
|
||||
function fictioneer_bulk_edit_save_chapter_fields( $post_id ) {
|
||||
// Abort if...
|
||||
if (
|
||||
! wp_verify_nonce( $_REQUEST['_wpnonce'] ?? 0, 'bulk-posts' ) ||
|
||||
( $_REQUEST['action2'] ?? 0 ) === 'trash' ||
|
||||
get_post_type( $post_id ) !== 'fcn_chapter' ||
|
||||
! current_user_can( 'edit_fcn_chapters', $post_id ) ||
|
||||
( get_post_status( $post_id ) === 'publish' && ! current_user_can( 'edit_published_fcn_chapters', $post_id ) )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup
|
||||
$icon = sanitize_text_field( $_REQUEST['bulk_edit_fictioneer_chapter_icon'] ?? '' );
|
||||
$text_icon = sanitize_text_field( $_REQUEST['bulk_edit_fictioneer_chapter_text_icon'] ?? '' );
|
||||
$prefix = sanitize_text_field( $_REQUEST['bulk_edit_fictioneer_chapter_prefix'] ?? '' );
|
||||
$group = sanitize_text_field( $_REQUEST['bulk_edit_fictioneer_chapter_group'] ?? '' );
|
||||
|
||||
// Update icon
|
||||
if ( $icon && ! get_option( 'fictioneer_hide_chapter_icons' ) ) {
|
||||
if ( strpos( $icon, 'fa-' ) === 0 && $icon !== FICTIONEER_DEFAULT_CHAPTER_ICON ) {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_icon', $icon );
|
||||
} elseif ( $icon === '_remove' ) {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_icon', 0 );
|
||||
}
|
||||
}
|
||||
|
||||
// Update text icon
|
||||
if (
|
||||
$text_icon &&
|
||||
! get_option( 'fictioneer_hide_chapter_icons' ) &&
|
||||
get_option( 'fictioneer_enable_advanced_meta_fields' )
|
||||
) {
|
||||
if ( $text_icon === '_remove' ) {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_text_icon', 0 );
|
||||
} else {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_text_icon', mb_substr( $text_icon, 0, 10, 'UTF-8' ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Update prefix
|
||||
if ( $prefix && get_option( 'fictioneer_enable_advanced_meta_fields' ) ) {
|
||||
if ( $prefix === '_remove' ) {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_prefix', 0 );
|
||||
} else {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_prefix', $prefix );
|
||||
}
|
||||
}
|
||||
|
||||
// Update group
|
||||
if ( $group ) {
|
||||
if ( $group === '_remove' ) {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_group', 0 );
|
||||
} else {
|
||||
fictioneer_update_post_meta( $post_id, 'fictioneer_chapter_group', $group );
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'save_post', 'fictioneer_bulk_edit_save_chapter_fields' );
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1183,6 +1183,11 @@ td.fictioneer_patreon_lock_amount {
|
||||
}
|
||||
}
|
||||
|
||||
.bulk-edit-help {
|
||||
float: left;
|
||||
margin: 1em 0 .5em !important;
|
||||
}
|
||||
|
||||
// ==============================================================================
|
||||
// FICTIONEER DIALOG MODALS
|
||||
// ==============================================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user