add_section( $section_id, array( 'title' => __( 'Name and description', 'p2020' ), 'priority' => 1, ) ); /** * We relocate the controls below to our new section. */ // Site Title $blogname = $wp_customize->get_control( 'blogname' ); $blogname->section = $section_id; $blogname->priority = 1; // Rename Tagline to Description and convert to textarea type $blogdescription = $wp_customize->get_control( 'blogdescription' ); $blogdescription->section = $section_id; $blogdescription->label = __( 'Description', 'p2020' ); $blogdescription->type = 'textarea'; $blogdescription->priority = 2; // Site Icon $site_icon = $wp_customize->get_control( 'site_icon' ); $site_icon->section = $section_id; $site_icon->priority = 3; } /** * Advanced options section. Contains o2 options and contributors list control. * * @param \WP_Customize_Manager $wp_customize Theme Customizer object. */ function add_advanced_options_section( \WP_Customize_Manager $wp_customize ) { $section_id = 'p2020_advanced_options'; $wp_customize->add_section( $section_id, array( 'title' => __( 'Advanced options', 'p2020' ), 'priority' => $wp_customize->get_panel( 'widgets' )->priority + 1, ) ); // Add new setting and control for showing/hiding page contributors $wp_customize->add_setting( 'p2020_hide_page_contributors', array( 'default' => false, 'type' => 'option', 'transport' => 'refresh', ) ); $wp_customize->add_control( 'p2020_hide_page_contributors', array( 'label' => __( 'Hide contributors list in pages', 'p2020' ), 'section' => $section_id, 'type' => 'checkbox', ) ); // Add new setting and control for showing/hiding post link previews $wp_customize->add_setting( 'p2020_hide_post_link_preview', array( 'default' => false, 'type' => 'option', 'transport' => 'refresh', ) ); $wp_customize->add_control( 'p2020_hide_post_link_preview', array( 'label' => __( 'Hide post link preview cards', 'p2020' ), 'section' => $section_id, 'type' => 'checkbox', ) ); $wp_customize->get_control( 'o2_options[front_side_post_prompt]' )->section = $section_id; } /** * Add postMessage support for site title and description for the Theme Customizer. * * @param \WP_Customize_Manager $wp_customize Theme Customizer object. */ function customize_register( \WP_Customize_Manager $wp_customize ) { $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->selective_refresh->add_partial( 'header_image', [ 'selector' => '#p2020-sidebar-header-image-container', ], ); if ( apply_filters( 'p2020_use_space_icon_layout', true ) ) { $wp_customize->selective_refresh->add_partial( 'site_icon', [ 'selector' => '#p2020-sidebar-site-icon-container', ] ); } add_site_identity_section( $wp_customize ); add_advanced_options_section( $wp_customize ); // Move Header Image section to after Name and description $wp_customize->get_section( 'header_image' )->title = __( 'Header image', 'p2020' ); $wp_customize->get_section( 'header_image' )->priority = 2; } add_action( 'customize_register', __NAMESPACE__ . '\customize_register' ); /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function customize_preview_js() { wp_enqueue_script( 'p2020_customizer', get_template_directory_uri() . '/js/customizer.js', [ 'customize-preview' ], '20130304', true ); } add_action( 'customize_preview_init', __NAMESPACE__ . '\customize_preview_js' ); /** * Return a list of allowed sections. * * @return array Pattern strings of allowed section IDs. */ function get_allowed_sections() { $allowed_sections = [ 'p2020_site_identity', 'header_image', 'colors', 'sidebar-widgets-sidebar-\d+', 'p2020_advanced_options', 'nav_menu\[\d+\]', 'add_menu', 'menu_locations', ]; return apply_filters( 'p2020_allowed_sections', $allowed_sections ); } /** * Remove sections that are not in the allowlist. */ function disable_nonrelevant_sections( \WP_Customize_Manager $wp_customize ) { if ( apply_filters( 'p2020_allow_all_sections', false ) ) { return; } $all_sections = array_keys( $wp_customize->sections() ); $allowed_sections = get_allowed_sections( $wp_customize ); $disallowed_sections = preg_grep( '/' . implode( '|', $allowed_sections ) . '/', $all_sections, PREG_GREP_INVERT ); foreach ( $disallowed_sections as $section ) { $wp_customize->remove_section( $section ); } } // Keep the priority high enough so our callback is ran after everything else. add_action( 'customize_register', __NAMESPACE__ . '\disable_nonrelevant_sections', 1000 ); /** * Disable "Additional CSS" added in Jetpack_Custom_CSS_Customizer. * * https://opengrok.a8c.com/source/xref/trunk/wp-content/mu-plugins/custom-css-in-customizer.php#15 */ add_filter( 'enable_custom_customizer', '__return_false' );