esc_html__( 'Content & Sidebar', 'suki' ), 'header' => esc_html__( 'Header', 'suki' ), 'page_header' => esc_html__( 'Page Header (Title Bar)', 'suki' ), 'footer' => esc_html__( 'Footer', 'suki' ), ) ); } /** * ==================================================== * Hook functions * ==================================================== */ /** * Add page settings meta box to post edit page. * * @param string $post_type * @param WP_Post $post */ public function add_post_meta_box( $post_type, $post ) { $post_types = array_merge( array( 'post', 'page' ), get_post_types( array( 'public' => true, 'publicly_queryable' => true, 'rewrite' => true, '_builtin' => false, ), 'names' ) ); $ignored_post_types = apply_filters( 'suki/admin/metabox/page_settings/ignored_post_types', array() ); $post_types = array_diff( $post_types, $ignored_post_types ); add_meta_box( 'suki_page_settings', /* translators: %s: theme name. */ sprintf( esc_html__( 'Page Settings (%s)', 'suki' ), esc_html( suki_get_theme_info( 'name' ) ) ), array( $this, 'render_meta_box__post' ), $post_types, 'side', 'default' ); } /** * Handle save action for page settings meta box on post edit page. * * @param integer $post_id */ public function save_post_meta_box( $post_id ) { // Check if our nonce is set. if ( ! isset( $_POST['suki_post_page_settings_nonce'] ) ) return; // Verify that the nonce is valid. if ( ! wp_verify_nonce( sanitize_key( $_POST['suki_post_page_settings_nonce'] ), 'suki_post_page_settings' ) ) return; // If this is an autosave, our form has not been submitted, so we don't want to do anything. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // Check the user's permissions. if ( ! current_user_can( 'edit_post', $post_id ) ) return; // Sanitize values. $sanitized = array(); if ( isset( $_POST['suki_page_settings'] ) && is_array( $_POST['suki_page_settings'] ) ) { $page_settings = array_map( 'sanitize_key', wp_unslash( $_POST['suki_page_settings'] ) ); foreach ( $page_settings as $key => $value ) { if ( '' === $value ) continue; // If value is 0 or 1, cast to integer. if ( '0' === $value || '1' === $value ) { $value = intval( $value ); } $sanitized[ $key ] = $value; } } // Update the meta field in the database. update_post_meta( $post_id, '_suki_page_settings', $sanitized ); } /** * Initialize meta box on all public taxonomies. */ public function init_term_meta_boxes() { $taxonomies = array_merge( array( 'category', 'post_tag' ), get_taxonomies( array( 'public' => true, 'publicly_queryable' => true, 'rewrite' => true, '_builtin' => false, ), 'names' ) ); foreach ( $taxonomies as $taxonomy ) { add_action( $taxonomy . '_add_form_fields', array( $this, 'render_meta_box__term_add' ) ); add_action( $taxonomy . '_edit_form_fields', array( $this, 'render_meta_box__term_edit' ) ); add_action( 'create_' . $taxonomy, array( $this, 'save_term_meta_box' ), 10, 2 ); add_action( 'edit_' . $taxonomy, array( $this, 'save_term_meta_box' ), 10, 2 ); } } /** * Handle save action for page settings meta box on edit term page. * * @param integer $term_id * @param integer $tt_id */ public function save_term_meta_box( $term_id, $tt_id ) { // Check if our nonce is set. if ( ! isset( $_POST['suki_term_page_settings_nonce'] ) ) return; // Verify that the nonce is valid. if ( ! wp_verify_nonce( sanitize_key( $_POST['suki_term_page_settings_nonce'] ), 'suki_term_page_settings' ) ) return;; // Sanitize values. $sanitized = array(); if ( isset( $_POST['suki_page_settings'] ) && is_array( $_POST['suki_page_settings'] ) ) { $page_settings = array_map( 'sanitize_key', wp_unslash( $_POST['suki_page_settings'] ) ); foreach ( $page_settings as $key => $value ) { if ( '' === $value ) continue; // If value is 0 or 1, cast to integer. if ( '0' === $value || '1' === $value ) { $value = intval( $value ); } $sanitized[ $key ] = $value; } } // Update the meta field in the database. update_term_meta( $term_id, 'suki_page_settings', $sanitized ); } /** * ==================================================== * Render functions * ==================================================== */ /** * Render page settings meta box on post / page edit page. * * @param WP_Post $post */ public function render_meta_box__post( $post ) { // Define an array of post IDs that will disable Page Settings meta box. // The Page Settings fields would not be displayed on those disabled IDs meta box. // Instead, The meta box would show the defined string specified on the disabled array. $disabled_ids = array(); // Add posts page to disabled IDs. if ( 'page' === get_option( 'show_on_front' ) && $posts_page_id = get_option( 'page_for_posts' ) ) { $disabled_ids[ $posts_page_id ] = '

' . esc_html__( 'Edit Page settings here', 'suki' ) . '

'; } // Filter to modify disabled IDs. $disabled_ids = apply_filters( 'suki/admin/metabox/page_settings/disabled_posts', $disabled_ids, $post ); // Check if current post ID is one of the disabled IDs if ( array_key_exists( $post->ID, $disabled_ids ) ) { // Print the notice here. echo $disabled_ids[ $post->ID ]; // WPCS: XSS OK // There is no other content should be rendered. return; } // Add a nonce field so we can check for it later. wp_nonce_field( 'suki_post_page_settings', 'suki_post_page_settings_nonce' ); // Render meta box. $this->render_meta_box_content( $post ); } /** * Render page settings meta box on add term page. */ public function render_meta_box__term_add() { ?>

'; $this->render_meta_box_content(); echo '
'; ?>

'; $this->render_meta_box_content( $term ); echo ''; ?> get_tabs(); $first_tab = key( $tabs ); ?>
$label ) : ?>
ID, '_' . $option_key, true ); } elseif ( is_a( $obj, 'WP_Term' ) ) { $values = get_term_meta( $obj->term_id, $option_key, true ); } else { $values = array(); } switch ( $tab ) { case 'header': ?>
$option_key . '[' . $key . ']', 'type' => 'select', 'choices' => array( '' => esc_html__( '-- Inherit from Customizer --', 'suki' ), '0' => esc_html__( 'No', 'suki' ), '1' => esc_html__( 'Yes', 'suki' ), ), 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'select', 'choices' => array( '' => esc_html__( '-- Inherit from Customizer --', 'suki' ), '0' => esc_html__( 'No', 'suki' ), '1' => esc_html__( 'Yes', 'suki' ), ), 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'select', 'choices' => array( '' => esc_html__( '-- Inherit from Customizer --', 'suki' ), '0' => esc_html__( 'Disabled', 'suki' ), '1' => esc_html__( 'Enabled', 'suki' ), ), 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'select', 'choices' => array( '' => esc_html__( '-- Inherit from Customizer --', 'suki' ), 'default' => esc_html__( 'Full width section, wrapped content', 'suki' ), 'full-width' => esc_html__( 'Full width content', 'suki' ), ), 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'select', 'choices' => array( '' => esc_html__( '-- Inherit from Customizer --', 'suki' ), 'wide' => esc_html__( 'Full content, no sidebar', 'suki' ), 'narrow' => esc_html__( 'Narrow content, no sidebar', 'suki' ), 'left-sidebar' => is_rtl() ? esc_html__( 'Right sidebar', 'suki' ) : esc_html__( 'Left sidebar', 'suki' ), 'right-sidebar' => is_rtl() ? esc_html__( 'Left sidebar', 'suki' ) : esc_html__( 'Right sidebar', 'suki' ), ), 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'checkbox', 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'checkbox', 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'select', 'choices' => array( '' => esc_html__( '-- Inherit from Customizer --', 'suki' ), '0' => esc_html__( 'No', 'suki' ), '1' => esc_html__( 'Yes', 'suki' ), ), 'value' => suki_array_value( $values, $key ), ) ); ?>
$option_key . '[' . $key . ']', 'type' => 'select', 'choices' => array( '' => esc_html__( '-- Inherit from Customizer --', 'suki' ), '0' => esc_html__( 'No', 'suki' ), '1' => esc_html__( 'Yes', 'suki' ), ), 'value' => suki_array_value( $values, $key ), ) ); ?>