Created
October 3, 2021 23:44
-
-
Save wpexplorer/0f4a428fadb179e6627920ba1a68163b to your computer and use it in GitHub Desktop.
Add some customizer settings for CPT - Total WP Theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Return array of CPT's that we want to add customizer panels for. | |
| function my_cpts() { | |
| return array( 'cars' ); | |
| } | |
| // Register new customizer panels. | |
| add_filter( 'wpex_customizer_panels', function( $panels ) { | |
| $cpts = my_cpts(); | |
| if ( ! is_array( $cpts ) ) { | |
| return; | |
| } | |
| foreach( $cpts as $cpt ) { | |
| $get_cpt = get_post_type_object( $cpt ); | |
| if ( ! is_object( $get_cpt ) ) { | |
| return; | |
| } | |
| $panels[$cpt] = array( | |
| 'title' => esc_html( $get_cpt->labels->name ), | |
| 'is_section' => true, | |
| ); | |
| } | |
| return $panels; | |
| } ); | |
| // Register new customizer sections. | |
| add_filter( 'wpex_customizer_sections', function( $sections ) { | |
| $cpts = my_cpts(); | |
| if ( ! is_array( $cpts ) ) { | |
| return; | |
| } | |
| // Define entry and single blocks. | |
| $entry_blocks = array( | |
| 'media' => esc_attr__( 'Media (Thumbnail, Slider, Video)', 'total' ), | |
| 'title' => esc_attr__( 'Title', 'total' ), | |
| 'meta' => esc_attr__( 'Meta', 'total' ), | |
| 'content' => esc_attr__( 'Content', 'total' ), | |
| 'readmore' => esc_attr__( 'Readmore', 'total' ), | |
| ); | |
| $single_blocks = array( | |
| 'media' => esc_attr__( 'Media (Thumbnail, Slider, Video)', 'total' ), | |
| 'title' => esc_attr__( 'Title', 'total' ), | |
| 'meta' => esc_attr__( 'Meta', 'total' ), | |
| 'content' => esc_attr__( 'Content', 'total' ), | |
| 'page-links' => esc_attr__( 'Page Links', 'total' ), | |
| 'share' => esc_attr__( 'Social Share', 'total' ), | |
| 'comments' => esc_attr__( 'Comments', 'total' ), | |
| ); | |
| // Loop through post types. | |
| foreach( $cpts as $cpt ) { | |
| $get_cpt = get_post_type_object( $cpt ); | |
| if ( ! is_object( $get_cpt ) ) { | |
| return; | |
| } | |
| $sections['wpex_' . $cpt] = array( | |
| 'title' => esc_html( $get_cpt->labels->name ), | |
| 'settings' => array( | |
| array( | |
| 'id' => $cpt . '_breadcrumbs', | |
| 'default' => true, | |
| 'control' => array( | |
| 'label' => esc_html__( 'Show Breadcrumbs?', 'total' ), | |
| 'type' => 'checkbox', | |
| ), | |
| ), | |
| // Archive settings. | |
| array( 'id' => $cpt . '_archive_heading', | |
| 'default' => true, | |
| 'control' => array( | |
| 'type' => 'wpex-heading', | |
| 'label' => esc_html__( 'Archive Settings', 'total' ), | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_archives_layout', | |
| 'control' => array( | |
| 'label' => esc_html__( 'Archives Layout', 'total' ), | |
| 'type' => 'select', | |
| 'choices' => wpex_get_post_layouts(), | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_grid_entry_columns', | |
| 'default' => '1', | |
| 'control' => array( | |
| 'label' => esc_html__( 'Archive Grid Columns', 'total' ), | |
| 'type' => 'select', | |
| 'choices' => wpex_grid_columns(), | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_readmore_text', | |
| 'control' => array( | |
| 'label' => esc_html__( 'Custom Read More Text', 'total' ), | |
| 'type' => 'text', | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_entry_blocks', | |
| 'default' => array_keys( $entry_blocks ), | |
| 'control' => array( | |
| 'label' => esc_html__( 'Entry Blocks', 'total' ), | |
| 'type' => 'multiple-select', | |
| 'choices' => $entry_blocks, | |
| ), | |
| ), | |
| // Single settings. | |
| array( | |
| 'id' => $cpt . '_singular_page_title', | |
| 'default' => true, | |
| 'control' => array( | |
| 'label' => esc_html__( 'Display Page Header Title?', 'total' ), | |
| 'type' => 'checkbox', | |
| 'active_callback' => 'wpex_cac_has_page_header', | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_single_layout', | |
| 'control' => array( | |
| 'label' => esc_html__( 'Single Layout', 'total' ), | |
| 'type' => 'select', | |
| 'choices' => wpex_get_post_layouts(), | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_single_header', | |
| 'control' => array( | |
| 'label' => esc_html__( 'Single Header Display', 'total' ), | |
| 'type' => 'select', | |
| 'choices' => array( | |
| '' => esc_html__( 'Default','total' ), | |
| 'post_title' => esc_html__( 'Post Title','total' ), | |
| ), | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_singular_template', | |
| 'control' => array( | |
| 'label' => esc_html__( 'Single Dynamic Template', 'total' ), | |
| 'type' => 'select', | |
| 'type' => 'wpex-dropdown-templates', | |
| ), | |
| ), | |
| array( | |
| 'id' => $cpt . '_single_blocks', | |
| 'default' => array_keys( $single_blocks ), | |
| 'control' => array( | |
| 'label' => esc_html__( 'Single Blocks', 'total' ), | |
| 'type' => 'multiple-select', | |
| 'choices' => $single_blocks, | |
| ), | |
| 'control_display' => array( | |
| 'check' => $cpt . '_singular_template', | |
| 'value' => '', | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| return $sections; | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment