add_setting( $configuration['id'], array( 'default' => $configuration['default'], 'transport' => $configuration['transport'], ) ); } call_user_func( array( $manager, $method ), $configuration['id'], $configuration ); } } if ( ! function_exists( 'is_block_editor_screen' ) ) { /** * Check is block editor screen * * @return boolean * * @since 1.0 */ function is_block_editor_screen() { if ( ! is_admin() ) { return false; } $screen = get_current_screen(); if ( ! $screen->is_block_editor ) { return false; } return true; } } if ( ! function_exists( 'is_wc_installed' ) ) { /** * Check whether WC is installed * * @return boolean * * @since 1.0 */ function is_wc_installed() { return function_exists( 'WC' ); } } if ( ! function_exists( 'is_elementor_installed' ) ) { /** * Check whether Elementor is installed * * @return boolean * * @since 1.0 */ function is_elementor_installed() { return class_exists( 'Elementor\Plugin' ); } } if ( ! function_exists( 'brandy_is_starter_sites_installed' ) ) { /** * Check whether Brandy Starter Sites is installed * * @return boolean * * @since 1.0 */ function brandy_is_starter_sites_installed() { return defined( 'BRANDYSITES_VERSION' ); } } if ( ! function_exists( 'is_brandy_blocks_installed' ) ) { /** * Check whether Brandy Blocks plugin is installed * * @return boolean * * @since 1.0 */ function is_brandy_blocks_installed() { return defined( 'BRANDY_BLOCKS_VERSION' ); } } if ( ! function_exists( 'brandy_get_reading_time' ) ) { /** * Get reading time for given content. * Calculate by minutes. * * @return string. * * @since 1.0 */ function brandy_get_reading_time( $content = '' ) { $WORDS_PER_MINUTE = 250; $wordcount = str_word_count( wp_strip_all_tags( $content ) ); $reading_time = ceil( $wordcount / $WORDS_PER_MINUTE ); return sprintf( '%1$s %2$s', _n( 'minute', 'minutes', $reading_time, 'brandy' ), $reading_time ); } } if ( ! function_exists( 'brandy_current_niche' ) ) { /** * Get current site niche. * * @return string|boolean Current niche. * * @since 1.0 */ function brandy_current_niche() { return get_option( 'brandy_current_niche', false ); } } if ( ! function_exists( 'brandy_is_current_niche' ) ) { /** * Check given niche is current site niche. * * @param string $niche Niche ID. * * @return string|boolean Result. * * @since 1.0 */ function brandy_is_current_niche( $niche ) { return brandy_current_niche() == $niche; } } if ( ! function_exists( 'brandy_get_template_part' ) ) { /** * Get template part by niche. * Allow developer to alter theme template part. * Developer can alter part by function brandy_register_template_part. * * @param string $slug Part slug. * @param string|null $name Template name. * @param array $args Same as get_template_part args * * @since 1.0 */ function brandy_get_template_part( $slug, $name = \null, $args = array() ) { $template = $slug . ( ! empty( $name ) ? "-$name" : '' ); $template_file = apply_filters( "brandy/$template", '' ); if ( empty( $template_file ) || ! file_exists( $template_file ) ) { return get_template_part( $slug, $name, $args ); } require $template_file; } } if ( ! function_exists( 'brandy_get_nav_menu_name' ) ) { /** * Returns menu name. * If menu doesn't exist, find menu name based on where the menu is placing (Header/Footer). * * @param string $menu_name Menu name to check exists * @param string $builder Header or Footer builder * @return string Menu name * * @since 1.0 */ function brandy_get_nav_menu_name( $menu_name, $builder = 'header' ) { if ( wp_get_nav_menu_object( $menu_name ) ) { return $menu_name; } $builder_locations = array(); if ( 'header' === $builder ) { $builder_locations = ThemeSetup::get_header_locations(); } if ( 'footer' === $builder ) { $builder_locations = ThemeSetup::get_footer_locations(); } $all_locations = array_merge( array_keys( $builder_locations ), array_keys( ThemeSetup::get_main_locations() ) ); while ( ! empty( $all_locations ) ) { $location = array_shift( $all_locations ); $menu_name_by_location = wp_get_nav_menu_name( $location ); if ( ! empty( $menu_name_by_location ) ) { return $menu_name_by_location; } } return $menu_name; } } if ( ! function_exists( 'brandy_the_post_thumbnail' ) ) { /** * Print current post thumbnail. * Show default thumbnail when post doesn't have featured image. * * @param int|WP_Post * * @since 1.0 */ function brandy_the_post_thumbnail( $post = null ) { $thumbnail = get_the_post_thumbnail( $post ); if ( empty( $thumbnail ) ) { echo wp_kses_post( brandy_get_post_placeholder_thumbnail() ); } else { echo wp_kses_post( $thumbnail ); } } } if ( ! function_exists( 'brandy_get_post_placeholder_thumbnail' ) ) { /** * Returns placeholder feature image for post * which doesn't have thumnbnail * * @return string Image tag * @since 1.0 */ function brandy_get_post_placeholder_thumbnail( $attr = array() ) { $src = brandy_get_post_placeholder_thumbnail_url(); $default_attr = array( 'src' => esc_url( $src ), 'alt' => 'Thumbnail placeholder', ); $attr = wp_parse_args( $default_attr, $attr ); $attr_string = ''; ob_start(); brandy_print_dom_attributes( $attr ); $attr_string = ob_get_contents(); ob_end_clean(); return sprintf( '', $attr_string ); } } if ( ! function_exists( 'brandy_get_post_placeholder_thumbnail_url' ) ) { /** * Returns placeholder feature image for post * which doesn't have thumnbnail * * @return string Image tag * @since 1.0 */ function brandy_get_post_placeholder_thumbnail_url() { return BRANDY_TEMPLATE_URL . '/assets/images/default-placeholder.png'; } } if ( ! function_exists( 'brandy_get_user_device' ) ) { /** * Get user device. * * @return string User device. */ function brandy_get_user_device() { $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? null; if ( empty( $user_agent ) ) { return null; } $mobile_devices = array( 'mobile', 'android', 'iphone', 'ipod', 'blackberry', 'opera mini', 'iemobile' ); $tablet_devices = array( 'tablet', 'ipad', 'playbook', 'kindle', 'nexus 7', 'nexus 10' ); $posible_mobile_devices = array_merge( $mobile_devices, $tablet_devices ); foreach ( $posible_mobile_devices as $device ) { if ( strpos( $user_agent, $device ) !== false ) { return 'mobile'; } } return 'desktop'; } }