<?php
/**
 * Enqueue child styles.
 */
function child_enqueue_styles() {
	wp_enqueue_style( 'child-theme', get_stylesheet_directory_uri() . '/style.css', array(), 100 );
}

add_action( 'wp_enqueue_scripts', 'child_enqueue_styles' );

function custom_theme_sidebars() {

    // Register the About sidebar
    register_sidebar(
        array(
            'name' => __( 'About', 'custom-theme' ),
            'id' => 'sidebar-about',
            'description' => __( 'The sidebar for the About page.', 'custom-theme' ),
            'before_widget' => '<div class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="widget-title">',
            'after_title' => '</h2>'
        )
    );

    // Register the Services sidebar
    register_sidebar(
        array(
            'name' => __( 'Services', 'custom-theme' ),
            'id' => 'sidebar-where-we-work',
            'description' => __( 'The sidebar for the Services page.', 'custom-theme' ),
            'before_widget' => '<div class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="widget-title">',
            'after_title' => '</h2>'
        )
    );

    // Register the Support sidebar
    register_sidebar(
        array(
            'name' => __( 'Support', 'custom-theme' ),
            'id' => 'sidebar-support',
            'description' => __( 'The sidebar for the Support page.', 'custom-theme' ),
            'before_widget' => '<div class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="widget-title">',
            'after_title' => '</h2>'
        )
    );

	    // Register the Blog sidebar
    register_sidebar(
        array(
            'name' => __( 'Blog', 'custom-theme' ),
            'id' => 'sidebar-blog',
            'description' => __( 'The sidebar for the blog index and single blog.', 'custom-theme' ),
            'before_widget' => '<div class="widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="widget-title">',
            'after_title' => '</h2>'
        )
    );
}
add_action( 'widgets_init', 'custom_theme_sidebars' );


// Display Yoast Meta Title and Description from Dashboard -> Pages
function bw_add_meta_columns($columns) {
    $columns['bw_meta_title'] = __('Meta Title', 'kadence-child');
    $columns['bw_meta_description'] = __('Meta Description', 'kadence-child');
    return $columns;
}
add_filter('manage_pages_columns', 'bw_add_meta_columns');

function bw_display_meta_columns($column, $post_id) {
    switch ($column) {
        case 'bw_meta_title':
            // Fetch the meta title used by Yoast SEO
            $meta_title = get_post_meta($post_id, '_yoast_wpseo_title', true);
            echo $meta_title ? $meta_title : __('None', 'kadence-child');
            break;
        case 'bw_meta_description':
            // Fetch the meta description used by Yoast SEO
            $meta_description = get_post_meta($post_id, '_yoast_wpseo_metadesc', true);
            echo $meta_description ? $meta_description : __('None', 'kadence-child');
            break;
    }
}
add_action('manage_pages_custom_column', 'bw_display_meta_columns', 10, 2);

