functions.php 4.9 KB
<?php
/**
 * Understrap Child Theme functions and definitions
 *
 * @package UnderstrapChild
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
include 'inc/shortcodes.php';
include 'inc/blocks.php';
include 'inc/shortcodes-resources.php';
include 'inc/menu.php';
include 'inc/shortcodes-contest.php';
include 'inc/shortcodes-disqus.php';
include 'inc/shortcodes-members.php';



/**
 * Removes the parent themes stylesheet and scripts from inc/enqueue.php
 */
function understrap_remove_scripts() {
	wp_dequeue_style( 'understrap-styles' );
	wp_deregister_style( 'understrap-styles' );

	wp_dequeue_script( 'understrap-scripts' );
	wp_deregister_script( 'understrap-scripts' );
}
add_action( 'wp_enqueue_scripts', 'understrap_remove_scripts', 20 );



/**
 * Enqueue our stylesheet and javascript file
 */
function theme_enqueue_styles() {

	// Get the theme data.
	$the_theme     = wp_get_theme();
	$theme_version = $the_theme->get( 'Version' );

	$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
	// Grab asset urls.
	$theme_styles  = "/css/child-theme{$suffix}.css";
	$theme_scripts = "/js/child-theme{$suffix}.js";
	
	$css_version = $theme_version . '.' . filemtime( get_stylesheet_directory() . $theme_styles );

	wp_enqueue_style( 'child-understrap-styles', get_stylesheet_directory_uri() . $theme_styles, array(), $css_version );
	wp_enqueue_script( 'jquery' );
	
	$js_version = $theme_version . '.' . filemtime( get_stylesheet_directory() . $theme_scripts );
	
	wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $js_version, true );
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );



/**
 * Load the child theme's text domain
 */
function add_child_theme_textdomain() {
	load_child_theme_textdomain( 'understrap-child', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'add_child_theme_textdomain' );



/**
 * Overrides the theme_mod to default to Bootstrap 5
 *
 * This function uses the `theme_mod_{$name}` hook and
 * can be duplicated to override other theme settings.
 *
 * @return string
 */
function understrap_default_bootstrap_version() {
	return 'bootstrap5';
}
add_filter( 'theme_mod_understrap_bootstrap_version', 'understrap_default_bootstrap_version', 20 );



/**
 * Loads javascript for showing customizer warning dialog.
 */
function understrap_child_customize_controls_js() {
	wp_enqueue_script(
		'understrap_child_customizer',
		get_stylesheet_directory_uri() . '/js/customizer-controls.js',
		array( 'customize-preview' ),
		'20130508',
		true
	);
}
add_action( 'customize_controls_enqueue_scripts', 'understrap_child_customize_controls_js' );


// require_once __DIR__.'/inc/filters.php';

remove_action( 'um_logout_user_links', 'um_logout_user_links', 100 );
add_action( 'um_logout_user_links', 'um_logout_user_links_new', 100 );
/**
 * Adds main links to a logout widget
 *
 * @param $args
 */
function um_logout_user_links_new( $args ) {
	?>

	<li>
		<a href="<?php echo esc_url( um_get_core_page( 'account' ) ); ?>">
			<?php _e( 'My Profile', 'ultimate-member' ); ?>
		</a>
	</li>
	<li>
		<a href="<?php echo esc_url( add_query_arg( 'redirect_to', UM()->permalinks()->get_current_url( true ), um_get_core_page( 'logout' ) ) ); ?>">
			<?php _e( 'Logout', 'ultimate-member' ); ?>
		</a>
	</li>

	<?php
}


function um_validate_email_domain( $args ) {

	// Change allowed email domains here
	$allowed_email_domains = apply_filters( 'um_allowed_email_domains', array(
			'gotenzing.com',
			'ekccu.com',
			'heritagecu.ca',
			'stellervista.com'
			) );

	// Change error message here
	$message = __( 'You can not use this email domain for registration', 'ultimate-member' );

	if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) {
		$email_domain = array_pop( explode( '@', trim( $args['user_email'] ) ) );
		if ( !in_array( $email_domain, $allowed_email_domains ) ) {
			UM()->form()->add_error( 'user_email', $message );
		}
	}
}
add_action( 'um_submit_form_errors_hook__registration', 'um_validate_email_domain', 20 );


function is_valid_email_domain($login, $email, $errors ){
	$allowed_email_domains = array("gotenzing.com","heritagecu.ca","ekccu.com","stellervista.com");// allowed domains
	$valid = false; // sets default validation to false
	if ( isset( $email ) && is_email( $email ) ) {
		$email_domain = array_pop( explode( '@', trim( $email) ) );
		if ( in_array( $email_domain, $allowed_email_domains ) ) {
			$valid = true;
		}
	}
	// Return error message for invalid domains
	if( $valid === false ){
   
   			$errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: Registration is only allowed from selected approved domains. If you think you are seeing this in error, please contact the system administrator.' ));
	}
   }
   add_action('register_post', 'is_valid_email_domain',10,3 );