Untitled

 avatar
unknown
plain_text
a month ago
5.6 kB
4
Indexable
/**
 * Core plugin functionality.
 *
 * @package BmacxCore
 */

namespace BmacxCore\Core;

use BmacxCore\KitForms;
use BmacxCore\Settings;
use BlackstoneCore\EnableDarkTheme;
use BlackstoneCore\CampaignHeader;
use BlackstoneCore\FootnoteModals;
use BlackstoneCore\Settings\SiteWideModal as SettingsSiteWideModal;
use function BlackstoneCore\Utility\should_not_hide_content;
use function BlackstoneCore\Utility\get_current_site;

/**
 * Default setup routine
 *
 * @return void
 */
function setup() {
    $n = function( $function ) {
        return __NAMESPACE__ . "\\$function";
    };

    add_filter( 'bx_site_post_types', function() {
        return [
            'press-release',
            'document',
            'people',
            'reusable-content',
            'insight',
            'modal',
            'navigation-widget',
            'portfolio-company',
            'footnote'
        ];
    });

    add_action( 'init', $n( 'init' ) );
    add_filter( 'body_class', $n( 'body_classes' ) );
    add_filter( 'blackstone_main_current_site', $n( 'set_current_site' ) );
    
    // Add condition for Gutenberg block options specific to bmacx site.
    add_action( 'enqueue_block_editor_assets', $n( 'customize_gutenberg_template_options' ) );

    add_action( 'after_setup_theme', $n( 'theme_setup' ) );
    add_filter( 'bx_header_logo_link', $n( 'disable_header_logo_link' ) );

    add_action( 'admin_init', $n( 'enable_theme_dark_theme_for_footer' ) );
    do_action( 'bmacx_core_loaded' );
}

/**
 * Initializes the plugin and fires an action other plugins can hook into.
 *
 * @return void
 */
function init() {
    $campaign_header = new CampaignHeader();
    $campaign_header->register();

    $settings_enable_dark_theme = new EnableDarkTheme();
    $settings_enable_dark_theme->register();

    $footnotemodal = new FootnoteModals();
    $footnotemodal->register();

    do_action( 'bmacx_core_init' );
}

function theme_setup() {
    add_theme_support( 'announcement-banner' );
}

/**
 * Add additional body classes.
 *
 * @param array $classes Body classes.
 * @return array
 */
function body_classes( $classes ) {
    if ( should_not_hide_content() ) {
        return $classes;
    }
    $classes[] = 'hide-site-content';
    return $classes;
}

/**
 * Set the Current Site Slug
 *
 * @return string
 */
function set_current_site() {
    return 'bmacx'; // For bmacx site, returns the site slug
}

/**
 * Customize Gutenberg Template Options for bmacx Site
 */
function customize_gutenberg_template_options() {
    $current_site = get_current_site();

    // Check if we are on bmacx site and in the Blackstone V2 theme
    if ( $current_site === 'bmacx' && wp_get_theme()->get( 'Name' ) === 'Blackstone V2' ) {
        // Enqueue script to remove unnecessary options
        wp_add_inline_script(
            'wp-block-editor',
            '
            wp.hooks.addFilter(
                "editor.PluginDocumentSettingPanel",
                "bmacx/remove-unused-template-options",
                function( Panel ) {
                    return function( props ) {
                        const allowedOptions = [ "no_header_nav_key", "no_footer_nav_key" ];

                        return (
                            <Panel { ...props }>
                                { props.children.filter( child => allowedOptions.includes( child.props.metaKey ) ) }
                            </Panel>
                        );
                    };
                }
            );
            ',
            'after'
        );
    }
}

/**
 * Disable Header Logo Link
 *
 * @param bool $enabled Logo link.
 * @return bool
 */
function disable_header_logo_link( $enabled ) {
    return $enabled;
}

/**
 * Enable Theme Dark Theme for Footer
 */
function enable_theme_dark_theme_for_footer() {
    register_setting(
        'reading',
        'bx_v2_theme_footer_color_theme',
        [
            'type'              => 'string',
            'sanitize_callback' => 'sanitize_text_field',
        ]
    );

    add_settings_section(
        'bx_theme_switcher_reading',
        esc_html__( 'Blackstone V2 Theme Switcher', 'blackstone' ),
        '__return_false',
        'reading'
    );

    add_settings_field(
        'bx_v2_theme_footer_color_theme',
        esc_html__( 'Footer Color Theme', 'blackstone' ),
        function() {
            $color_themes = get_v2_color_themes();
            $selected     = get_option( 'bx_v2_theme_footer_color_theme', 'default' );
            ?>
            <select name="bx_v2_theme_footer_color_theme">
                <?php foreach ( $color_themes as $color_theme ) { ?>
                    <option 
                        value="<?php echo esc_attr( $color_theme['value'] ); ?>"
                        <?php selected( $selected, $color_theme['value'] ); ?>
                    >
                        <?php echo esc_html( $color_theme['label'] ); ?>
                    </option>
                <?php } ?>
            </select>
            <p class="description"><?php esc_html_e( 'The color theme of the V2 Theme\'s Footer.', 'blackstone' ); ?></p>
            <?php
        },
        'reading',
        'bx_theme_switcher_reading'
    );
}

function get_v2_color_themes() {
    return [
        [ 'label' => 'Default', 'value' => 'default' ],
        [ 'label' => 'Dark', 'value' => 'dark' ],
    ];
}
Editor is loading...
Leave a Comment