Replace page layout and configuration ACF meta
This commit is contained in:
parent
17faf1672c
commit
19cfebde0f
@ -602,6 +602,7 @@ The integrated role manager to add and, edit, and remove roles. Not the most sop
|
||||
* **Select Page Template:** You cannot change the page template without this.
|
||||
* **Custom Page CSS:** Inject CSS into the header for an unique style. Dangerous!
|
||||
* **Custom ePUB CSS:** Inject CSS into the ePUB for an unique style. Dangerous!
|
||||
* **Custom Page Header:** Change the header image for selected pages.
|
||||
* **SEO Meta:** Show and edit the SEO meta for posts (if enabled in the settings).
|
||||
* **Make Sticky:** You can make posts and stories stick to the top in lists.
|
||||
* **Edit Permalink:** Customize the permalink slug derived from the title. Dangerous!
|
||||
|
@ -1,65 +0,0 @@
|
||||
{
|
||||
"key": "group_5ed5854a23288",
|
||||
"title": "Configurations",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5ed5856ed2c3e",
|
||||
"label": "Short Name",
|
||||
"name": "fictioneer_short_name",
|
||||
"aria-label": "",
|
||||
"type": "text",
|
||||
"instructions": "Required for the tab view in stories, such as Glossary or Characters. If not set, the tab will not be shown.",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"maxlength": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": ""
|
||||
},
|
||||
{
|
||||
"key": "field_60040fa3bc4f1",
|
||||
"label": "Filter & Search ID",
|
||||
"name": "fictioneer_filter_and_search_id",
|
||||
"aria-label": "",
|
||||
"type": "text",
|
||||
"instructions": "ID for a filter and\/or search plugin.",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"maxlength": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": ""
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "post_type",
|
||||
"operator": "==",
|
||||
"value": "page"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 9,
|
||||
"position": "side",
|
||||
"style": "default",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": true,
|
||||
"description": "",
|
||||
"show_in_rest": 0,
|
||||
"modified": 1692460526
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
{
|
||||
"key": "group_62120d4daeb36",
|
||||
"title": "Page Layout",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_62120d5bf9dbc",
|
||||
"label": "Custom Header Image",
|
||||
"name": "fictioneer_custom_header_image",
|
||||
"aria-label": "",
|
||||
"type": "image",
|
||||
"instructions": "Override the default header image. Mind that this needs a large image and should still fit the site. The image is scaled and cropped to cover the space.",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"return_format": "url",
|
||||
"preview_size": "medium",
|
||||
"library": "all",
|
||||
"min_width": "",
|
||||
"min_height": "",
|
||||
"min_size": "",
|
||||
"max_width": "",
|
||||
"max_height": "",
|
||||
"max_size": 2,
|
||||
"mime_types": "",
|
||||
"show_column": 0,
|
||||
"show_column_weight": 1000,
|
||||
"allow_quickedit": 0,
|
||||
"allow_bulkedit": 0
|
||||
},
|
||||
{
|
||||
"key": "field_621b5610818d2",
|
||||
"label": "Custom CSS",
|
||||
"name": "fictioneer_custom_css",
|
||||
"aria-label": "",
|
||||
"type": "textarea",
|
||||
"instructions": "Inserts a custom style tag in the <head>.",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "code-box",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": ".header { ... }",
|
||||
"maxlength": "",
|
||||
"rows": "",
|
||||
"new_lines": "",
|
||||
"show_column": 0,
|
||||
"show_column_weight": 1000,
|
||||
"allow_quickedit": 0,
|
||||
"allow_bulkedit": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "post_type",
|
||||
"operator": "!=",
|
||||
"value": "post"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 12,
|
||||
"position": "side",
|
||||
"style": "default",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": true,
|
||||
"description": "",
|
||||
"show_in_rest": 0,
|
||||
"modified": 1692459889
|
||||
}
|
@ -193,7 +193,7 @@ function fictioneer_get_metabox_image( $post, $meta_key, $args = [] ) {
|
||||
// Start HTML ---> ?>
|
||||
<div class="fictioneer-metabox-image">
|
||||
<?php if ( $label ) : ?>
|
||||
<label class="fictioneer-metabox-image__label" for="<?php echo $meta_key; ?>"><?php echo $label; ?></label>
|
||||
<div class="fictioneer-metabox-image__label"><?php echo $label; ?></div>
|
||||
<?php endif; ?>
|
||||
<input type="hidden" name="<?php echo $meta_key; ?>" class="fictioneer-metabox-image__id" value="<?php echo esc_attr( $meta_value ); ?>" autocomplete="off">
|
||||
<div class="fictioneer-metabox-image__wrapper">
|
||||
@ -213,6 +213,33 @@ function fictioneer_get_metabox_image( $post, $meta_key, $args = [] ) {
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// METABOX CLASSES
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Append classes to the metabox
|
||||
*
|
||||
* @since Fictioneer 5.7.4
|
||||
*
|
||||
* @param array $classes An array of postbox classes.
|
||||
*
|
||||
* @return array The modified array of postbox classes.
|
||||
*/
|
||||
|
||||
function fictioneer_append_metabox_classes( $classes ) {
|
||||
// Add class
|
||||
$classes[] = 'fictioneer-side-metabox';
|
||||
|
||||
// Return with added class
|
||||
return $classes;
|
||||
}
|
||||
add_filter( 'postbox_classes_fcn_story_fictioneer-story-meta', 'fictioneer_append_metabox_classes' );
|
||||
|
||||
foreach ( ['page', 'fcn_story', 'fcn_chapter', 'fcn_collection', 'fcn_recommendation'] as $type ) {
|
||||
add_filter( "postbox_classes_{$type}_fictioneer-page-layout", 'fictioneer_append_metabox_classes' );
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// STORY META FIELDS
|
||||
// =============================================================================
|
||||
@ -235,25 +262,6 @@ function fictioneer_add_story_meta_metabox() {
|
||||
}
|
||||
add_action( 'add_meta_boxes', 'fictioneer_add_story_meta_metabox' );
|
||||
|
||||
/**
|
||||
* Append classes to the story metabox
|
||||
*
|
||||
* @since Fictioneer 5.7.4
|
||||
*
|
||||
* @param array $classes An array of postbox classes.
|
||||
*
|
||||
* @return array The modified array of postbox classes.
|
||||
*/
|
||||
|
||||
function fictioneer_append_story_metabox_classes( $classes ) {
|
||||
// Add class
|
||||
$classes[] = 'fictioneer-side-metabox';
|
||||
|
||||
// Return with added class
|
||||
return $classes;
|
||||
}
|
||||
add_filter( 'postbox_classes_fcn_story_fictioneer-story-meta', 'fictioneer_append_story_metabox_classes' );
|
||||
|
||||
/**
|
||||
* Render story metabox
|
||||
*
|
||||
@ -418,7 +426,7 @@ function fictioneer_render_story_metabox( $post ) {
|
||||
|
||||
// --- Filters -----------------------------------------------------------------
|
||||
|
||||
$output = apply_filters( 'fictioneer_filter_story_sidebar_meta_fields', $output, $post );
|
||||
$output = apply_filters( 'fictioneer_filter_story_meta_fields', $output, $post );
|
||||
|
||||
// --- Render ------------------------------------------------------------------
|
||||
|
||||
@ -432,7 +440,7 @@ function fictioneer_render_story_metabox( $post ) {
|
||||
/**
|
||||
* Save story metabox data
|
||||
*
|
||||
* @since Fictioneer 4.0
|
||||
* @since Fictioneer 5.7.4
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
*/
|
||||
@ -516,17 +524,196 @@ function fictioneer_save_story_metabox( $post_id ) {
|
||||
|
||||
// --- Filters -----------------------------------------------------------------
|
||||
|
||||
$fields = apply_filters( 'fictioneer_filter_story_sidebar_meta_updates', $fields );
|
||||
$fields = apply_filters( 'fictioneer_filter_story_meta_updates', $fields, $post_id );
|
||||
|
||||
// --- Save --------------------------------------------------------------------
|
||||
|
||||
foreach ( $fields as $key => $value ) {
|
||||
fictioneer_update_post_meta( $post_id, $key, $value ?? 0 );
|
||||
fictioneer_update_post_meta( $post_id, $key, $value ?? 0 ); // Add, update, or delete (if falsy)
|
||||
}
|
||||
}
|
||||
add_action( 'save_post', 'fictioneer_save_story_metabox' );
|
||||
|
||||
// =============================================================================
|
||||
// PAGE LAYOUT FIELDS
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Adds page layout metabox
|
||||
*
|
||||
* @since Fictioneer 5.7.4
|
||||
*
|
||||
* @param int $post_type The current post type.
|
||||
*/
|
||||
|
||||
function fictioneer_add_page_layout_metabox( $post_type ) {
|
||||
if (
|
||||
! current_user_can( 'fcn_custom_page_header' ) &&
|
||||
! current_user_can( 'fcn_custom_page_css' ) &&
|
||||
$post_type !== 'page'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_meta_box(
|
||||
'fictioneer-page-layout',
|
||||
__( 'Page Layout', 'fictioneer' ),
|
||||
'fictioneer_render_page_layout_metabox',
|
||||
['page', 'fcn_story', 'fcn_chapter', 'fcn_recommendation', 'fcn_collection'],
|
||||
'side',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
add_action( 'add_meta_boxes', 'fictioneer_add_page_layout_metabox' );
|
||||
|
||||
/**
|
||||
* Render page layout metabox
|
||||
*
|
||||
* @since Fictioneer 5.7.4
|
||||
*
|
||||
* @param WP_Post $post The current post object.
|
||||
*/
|
||||
|
||||
function fictioneer_render_page_layout_metabox( $post ) {
|
||||
// --- Setup -------------------------------------------------------------------
|
||||
|
||||
$nonce = wp_create_nonce( 'fictioneer_metabox_nonce' );
|
||||
$output = [];
|
||||
|
||||
// --- Add fields --------------------------------------------------------------
|
||||
|
||||
if ( $post->post_type === 'page' ) {
|
||||
$output['fictioneer_short_name'] = fictioneer_get_metabox_text(
|
||||
$post,
|
||||
'fictioneer_short_name',
|
||||
array(
|
||||
'label' => _x( 'Short Name', 'Page short name meta field label.', 'fictioneer' ),
|
||||
'description' => __( 'Required for the tab view in stories.', 'fictioneer' )
|
||||
)
|
||||
);
|
||||
|
||||
if ( current_user_can( 'install_plugins' ) ) {
|
||||
$output['fictioneer_filter_and_search_id'] = fictioneer_get_metabox_text(
|
||||
$post,
|
||||
'fictioneer_filter_and_search_id',
|
||||
array(
|
||||
'label' => _x( 'Filter & Search ID', 'Page filter ans search meta field label.', 'fictioneer' ),
|
||||
'description' => __( 'ID for a filter and/or search plugins.', 'fictioneer' )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( current_user_can( 'fcn_custom_page_header', $post->ID ) ) {
|
||||
$output['fictioneer_custom_header_image'] = fictioneer_get_metabox_image(
|
||||
$post,
|
||||
'fictioneer_custom_header_image',
|
||||
array(
|
||||
'label' => __( 'Custom Header Image', 'fictioneer' ),
|
||||
'description' => __( 'Replaces the default header image.', 'fictioneer' ),
|
||||
'button' => __( 'Set header image', 'fictioneer' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( current_user_can( 'fcn_custom_page_css', $post->ID ) ) {
|
||||
$output['fictioneer_custom_css'] = fictioneer_get_metabox_textarea(
|
||||
$post,
|
||||
'fictioneer_custom_css',
|
||||
array(
|
||||
'label' => __( 'Custom Page CSS', 'fictioneer' ),
|
||||
'description' => __( 'Only applied to the page.', 'fictioneer' ),
|
||||
'placeholder' => __( '.selector { ... }', 'fictioneer' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// --- Filters -----------------------------------------------------------------
|
||||
|
||||
$output = apply_filters( 'fictioneer_filter_page_layout_meta_fields', $output, $post );
|
||||
|
||||
// --- Render ------------------------------------------------------------------
|
||||
|
||||
echo implode( '', $output );
|
||||
|
||||
// Start HTML ---> ?>
|
||||
<input type="hidden" name="fictioneer_metabox_nonce" value="<?php echo esc_attr( $nonce ); ?>" autocomplete="off">
|
||||
<?php // <--- End HTML
|
||||
}
|
||||
|
||||
/**
|
||||
* Save page layout metabox data
|
||||
*
|
||||
* @since Fictioneer 5.7.4
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
*/
|
||||
|
||||
function fictioneer_save_page_layout_metabox( $post_id ) {
|
||||
$post_type = get_post_type( $post_id );
|
||||
|
||||
// --- Verify ------------------------------------------------------------------
|
||||
|
||||
if (
|
||||
! wp_verify_nonce( ( $_POST['fictioneer_metabox_nonce'] ?? '' ), 'fictioneer_metabox_nonce' ) ||
|
||||
fictioneer_multi_save_guard( $post_id ) ||
|
||||
! in_array( $post_type, ['page', 'fcn_story', 'fcn_chapter', 'fcn_recommendation', 'fcn_collection'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// --- Permissions? ------------------------------------------------------------
|
||||
|
||||
$permission_list = array(
|
||||
'page' => ['edit_pages', 'edit_published_pages'],
|
||||
'fcn_story' => ['edit_fcn_stories', 'edit_published_fcn_stories'],
|
||||
'fcn_chapter' => ['edit_fcn_chapters', 'edit_published_fcn_chapters'],
|
||||
'fcn_collections' => ['edit_fcn_collections', 'edit_published_fcn_collections'],
|
||||
'fcn_recommendation' => ['edit_fcn_recommendations', 'edit_published_fcn_recommendations']
|
||||
);
|
||||
|
||||
if (
|
||||
! current_user_can( $permission_list[ $post_type ][0], $post_id ) ||
|
||||
( get_post_status( $post_id ) === 'publish' && ! current_user_can( $permission_list[ $post_type ][1], $post_id ) )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// --- Sanitize and add data ---------------------------------------------------
|
||||
|
||||
$fields = [];
|
||||
|
||||
if ( $post_type === 'page' ) {
|
||||
$fields['fictioneer_short_name'] = sanitize_text_field( $_POST['fictioneer_short_name'] ?? '' );
|
||||
|
||||
if ( current_user_can( 'install_plugins' ) ) {
|
||||
$fields['fictioneer_filter_and_search_id'] = absint( $_POST['fictioneer_filter_and_search_id'] ?? 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( current_user_can( 'fcn_custom_page_header', $post_id ) ) {
|
||||
$fields['fictioneer_custom_header_image'] = absint( $_POST['fictioneer_custom_header_image'] ?? 0 );
|
||||
}
|
||||
|
||||
if ( current_user_can( 'fcn_custom_page_css', $post_id ) ) {
|
||||
$css = sanitize_textarea_field( $_POST['fictioneer_custom_css'] ?? '' );
|
||||
$css = preg_match( '/<\/?\w+/', $css ) ? '' : $css;
|
||||
$fields['fictioneer_custom_css'] = str_replace( '<', '', $css );
|
||||
}
|
||||
|
||||
// --- Filters -----------------------------------------------------------------
|
||||
|
||||
$fields = apply_filters( 'fictioneer_filter_page_layout_meta_updates', $fields, $post_id );
|
||||
|
||||
// --- Save --------------------------------------------------------------------
|
||||
|
||||
foreach ( $fields as $key => $value ) {
|
||||
fictioneer_update_post_meta( $post_id, $key, $value ?? 0 ); // Add, update, or delete (if falsy)
|
||||
}
|
||||
}
|
||||
|
||||
if ( current_user_can( 'fcn_custom_page_header' ) || current_user_can( 'fcn_custom_page_css' ) ) {
|
||||
add_action( 'save_post', 'fictioneer_save_page_layout_metabox' );
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -17,6 +17,7 @@ define(
|
||||
'fcn_privacy_clearance',
|
||||
'fcn_shortcodes',
|
||||
'fcn_simple_comment_html',
|
||||
'fcn_custom_page_header',
|
||||
'fcn_custom_page_css',
|
||||
'fcn_custom_epub_css',
|
||||
'fcn_seo_meta',
|
||||
@ -85,6 +86,19 @@ function fictioneer_initialize_roles( $force = false ) {
|
||||
) {
|
||||
fictioneer_setup_roles();
|
||||
}
|
||||
|
||||
// If this capability is missing, the roles need to be updated
|
||||
if ( $administrator && ! in_array( 'fcn_custom_page_header', array_keys( $administrator->capabilities ) ) ) {
|
||||
get_role( 'administrator' )->add_cap( 'fcn_custom_page_header' );
|
||||
|
||||
if ( $editor = get_role( 'editor' ) ) {
|
||||
$editor->add_cap( 'fcn_custom_page_header' );
|
||||
}
|
||||
|
||||
if ( $moderator = get_role( 'fcn_moderator' ) ) {
|
||||
$moderator->add_cap( 'fcn_only_moderate_comments' );
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'admin_init', 'fictioneer_initialize_roles' );
|
||||
|
||||
@ -135,6 +149,7 @@ function fictioneer_setup_roles() {
|
||||
'fcn_all_blocks',
|
||||
'fcn_story_pages',
|
||||
'fcn_edit_date',
|
||||
'fcn_custom_page_header',
|
||||
'moderate_comments', // Legacy restore
|
||||
'edit_comment', // Legacy restore
|
||||
'edit_pages', // Legacy restore
|
||||
@ -756,27 +771,6 @@ if ( ! current_user_can( 'manage_options' ) ) {
|
||||
add_action( 'current_screen', 'fictioneer_restrict_admin_only_pages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes search and filter ID input field
|
||||
*
|
||||
* @since 5.6.0
|
||||
* @since 5.6.2 Simplified with helper function.
|
||||
*
|
||||
* @param array $fields An array of fields to be rendered.
|
||||
*
|
||||
* @return array The modified array.
|
||||
*/
|
||||
|
||||
function fictioneer_remove_filter_search_id_input( $fields ) {
|
||||
// Return modified fields array
|
||||
return fictioneer_acf_remove_fields( 'field_60040fa3bc4f1', $fields );
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
add_filter( 'acf/update_value/name=fictioneer_filter_and_search_id', 'fictioneer_acf_prevent_value_update', 10, 3 );
|
||||
add_filter( 'acf/pre_render_fields', 'fictioneer_remove_filter_search_id_input' );
|
||||
}
|
||||
|
||||
// === EDIT_PAGES ============================================================
|
||||
|
||||
/**
|
||||
@ -1120,29 +1114,6 @@ if ( ! current_user_can( 'manage_options' ) ) {
|
||||
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
|
||||
}
|
||||
|
||||
// === FCN_CUSTOM_PAGE_CSS ===================================================
|
||||
|
||||
/**
|
||||
* Removes custom page/story CSS input fields
|
||||
*
|
||||
* @since 5.6.0
|
||||
* @since 5.6.2 Simplified with helper function.
|
||||
*
|
||||
* @param array $fields An array of fields to be rendered.
|
||||
*
|
||||
* @return array The modified array.
|
||||
*/
|
||||
|
||||
function fictioneer_remove_custom_page_css_inputs( $fields ) {
|
||||
// Return modified fields array (fictioneer_story_css, fictioneer_custom_css)
|
||||
return fictioneer_acf_remove_fields( ['field_621b5610818d2'], $fields );
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'fcn_custom_page_css' ) ) {
|
||||
add_filter( 'acf/update_value/name=fictioneer_custom_css', 'fictioneer_acf_prevent_value_update', 10, 3 );
|
||||
add_filter( 'acf/pre_render_fields', 'fictioneer_remove_custom_page_css_inputs' );
|
||||
}
|
||||
|
||||
// === FCN_CUSTOM_EPUB_CSS ===================================================
|
||||
|
||||
/**
|
||||
|
@ -32,6 +32,7 @@ $editor_caps = array(
|
||||
'fcn_select_page_template',
|
||||
'fcn_custom_page_css',
|
||||
'fcn_custom_epub_css',
|
||||
'fcn_custom_page_header',
|
||||
'fcn_seo_meta',
|
||||
'fcn_make_sticky',
|
||||
'fcn_edit_permalink',
|
||||
|
Loading…
x
Reference in New Issue
Block a user