<?php 

/* wczytywanie js i css */
function load_styles_and_scripts() {

  //wczytywanie CSS
  wp_enqueue_style (
    'bootstrap-styles',
    get_template_directory_uri() . '/assets/css/bootstrap.min.css'
  );

  wp_enqueue_style (
    'main-styles',
    get_template_directory_uri() . '/style.css'
  );

  wp_enqueue_style (
    'font-awesome-style',
    'http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'
  );


  // wczytywanie JS

    wp_enqueue_script (
    'jquery-scripts',
    get_template_directory_uri() . '/assets/js/jquery-3.2.1.min.js',
    false,
    '3.2.1',
    true
  );
        wp_enqueue_script (
    'jquery-cookie',
    get_template_directory_uri() . '/assets/js/jquery.cookie.js',
    false,
    '1.4.1',
    true
  );


  wp_enqueue_script (
    'bootstrap-scripts',
    get_template_directory_uri() . '/assets/js/bootstrap.min.js',
    false,
    '3.3.7',
    true
  );

  wp_enqueue_script (
    'custom-scripts',
    get_template_directory_uri() . '/assets/js/scripts.js',
    false,
    '1',
    true
  );


}

add_action('wp_enqueue_scripts', 'load_styles_and_scripts');
/* wczytywanie js i css */ 

/**
* Uruchamianie górnego i dolnego menu na stronie
**/
register_nav_menus(array(

    'main-nav' => 'Gorne menu strony',
    'footer-nav' => 'Menu w stopce'

));


/**
 * Tworzenie sidebara
 */
register_sidebar ( array(
  'name'          => 'main-sidebar',
  'description'   => 'Pasek boczny',
  'before_widget' => '<br><div class="col-md-12"><div class="panel panel-default no-corners">',
  'after_widget'  => '</div></div></div>',
  'before_title'  => '<div class="panel-heading"><h3 class="panel-title">',
  'after_title'   => '</h3></div><div class="panel-body">'
));


/**
 * Włączenie wspierania miniaturek postów
 */
add_theme_support( 'post-thumbnails');


/**
 * Templatka wyglądu pola komentarzy
 */
function comments_feed_template_callback($comment, $args, $depth) {

  $GLOBAL['comment'] = $comment;

  ?>
    <div class="media">
      <a href="<?php get_comment_author_url(); ?>" class="pull-left">
        <!--<?php echo get_avatar( get_the_author_meta( 'user_email' ), $size = '96', $default = '', $alt = false ) ?> -->
      </a>
      <div class="media-body">
        <h5 class="media-heading">
          <a href="<?php get_comment_author_url(); ?>"><?php echo get_comment_author(); ?></a>
          <small><?php comment_date(); ?> o <?php comment_time(); ?></small>
        </h5>
        <?php comment_text(); ?>
        <?php comment_reply_link(array_merge($args, array(
          'reply_text' => __('<strong>Odpowiedz </strong><i class="icon-share-alt"></i>'),
          'depth' => $depth,
          'max_depth' => $args['max_depth']
        ))); ?>
      </div>
    </div>
    <hr>
  <?php
}
//Przycisk dla odpowiedzi w komentarzu
add_filter('comment_reply_link', 'add_reply_link_class');

function add_reply_link_class($class) {
  $class = str_replace("class='comment-reply-link", "class='btn btn-default pull-right", $class);
  return $class;
}


/*  rejestracja widgetów w stopce */ 
function footer_widgets_init() {
    //pierwsza kolumna
    register_sidebar ( array(
      'name'          => 'footer-sidebar-1',
      'description'   => 'Pierwsza kolumna w stopce',
      'before_widget' => '',
      'after_widget'  => '',
      'before_title'  => '',
      'after_title'   => ''
    ));
    //druga kolumna
    register_sidebar ( array(
      'name'          => 'footer-sidebar-2',
      'description'   => 'Druga kolumna w stopce',
      'before_widget' => '',
      'after_widget'  => '',
      'before_title'  => '',
      'after_title'   => ''
    ));
    //trzecia kolumna
    register_sidebar ( array(
      'name'          => 'footer-sidebar-3',
      'description'   => 'Trzecia kolumna w stopce',
      'before_widget' => '<div class="custom-footer-widget">',
      'after_widget'  => '</div>',
      'before_title'  => '<div class="page-header"><h3 class="widget-title">',
      'after_title'   => '</h3></div>'
    ));
}
//Inicjacja widgetów
add_action( 'widgets_init', 'footer_widgets_init' );
/**
 * Włączenie wspierania miniaturek postów
 */
add_theme_support( 'post-thumbnails');
/**
 * Templatka wyglądu pola komentarzy
 */

/**
 * filtry 
 */

/**
 * Extended Walker class for use with the
 * Twitter Bootstrap toolkit Dropdown menus in Wordpress.
 * Edited to support n-levels submenu.
 * @author johnmegahan https://gist.github.com/1597994, Emanuele 'Tex' Tessore https://gist.github.com/3765640
 */
class BootstrapNavMenuWalker extends Walker_Nav_Menu {
 
 
  function start_lvl( &$output, $depth ) {
 
    $indent = str_repeat( "\t", $depth );
    $submenu = ($depth > 0) ? ' sub-menu' : '';
    $output    .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
 
  }
 
  function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
 
 
    $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
 
    $li_attributes = '';
    $class_names = $value = '';
 
    $classes = empty( $item->classes ) ? array() : (array) $item->classes;
    
    // managing divider: add divider class to an element to get a divider before it.
    $divider_class_position = array_search('divider', $classes);
    if($divider_class_position !== false){
      $output .= "<li class=\"divider\"></li>\n";
      unset($classes[$divider_class_position]);
    }
    
    $classes[] = ($args->has_children) ? 'dropdown' : '';
    $classes[] = ($item->current || $item->current_item_ancestor) ? 'active' : '';
    $classes[] = 'menu-item-' . $item->ID;
    if($depth && $args->has_children){
      $classes[] = 'dropdown-submenu';
    }
 
 
    $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
    $class_names = ' class="' . esc_attr( $class_names ) . '"';
 
    $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
    $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
 
    $output .= $indent . '<li' . $id . $value . $class_names . $li_attributes . '>';
 
    $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
    $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
    $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
    $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
    $attributes .= ($args->has_children)      ? ' class="dropdown-toggle" data-toggle="dropdown"' : '';
 
    $item_output = $args->before;
    $item_output .= '<a'. $attributes .'>';
    $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    $item_output .= ($depth == 0 && $args->has_children) ? ' <b class="caret"></b></a>' : '</a>';
    $item_output .= $args->after;
 
 
    $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  }
  
 
  function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
    //v($element);
    if ( !$element )
      return;
 
    $id_field = $this->db_fields['id'];
 
    //display this element
    if ( is_array( $args[0] ) )
      $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
    else if ( is_object( $args[0] ) )
      $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
    $cb_args = array_merge( array(&$output, $element, $depth), $args);
    call_user_func_array(array(&$this, 'start_el'), $cb_args);
 
    $id = $element->$id_field;
 
    // descend only when the depth is right and there are childrens for this element
    if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
 
      foreach( $children_elements[ $id ] as $child ){
 
        if ( !isset($newlevel) ) {
          $newlevel = true;
          //start the child delimiter
          $cb_args = array_merge( array(&$output, $depth), $args);
          call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
        }
        $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
      }
      unset( $children_elements[ $id ] );
    }
 
    if ( isset($newlevel) && $newlevel ){
      //end the child delimiter
      $cb_args = array_merge( array(&$output, $depth), $args);
      call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
    }
 
    //end this element
    $cb_args = array_merge( array(&$output, $element, $depth), $args);
    call_user_func_array(array(&$this, 'end_el'), $cb_args);
 
  }
 
}

/* disable admin bar */
add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
    if (current_user_can('subscriber')) {
        show_admin_bar(false);
    }
}

/* filter redirekta na ekranie logowania */ 
add_filter('wp_login_form', 'log_to_home');

function log_to_home()
{
  $args = array(
  'echo'           => true,
  'remember'       => true,
  'redirect'       => home_url( '/lekcje' )); 
}

  /* split menu for logged in and not logged in */
  function my_wp_nav_menu_args( $args = '' ) {
 
    if( is_user_logged_in() ) { 
        $args['menu'] = 'menu_log_in';
    } else { 
        $args['menu'] = 'menu_log_out';
    } 
        return $args;
  }
 add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );


 /* new course */
add_action( 'init', 'lekcja_1_post_type_func' );
function lekcja_1_post_type_func() {
$labels = array(
'name' => _x( 'lekcja_1', 'lekcja_1' ),
'singular_name' => _x( 'lekcja_1', 'lekcja_1' ),
'add_new' => _x( 'Add New', 'lekcja_1' ),
'add_new_item' => _x( 'Add New', 'lekcja_1' ),
'edit_item' => _x( 'Edit', 'lekcja_1' ),
'new_item' => _x( 'New', 'lekcja_1' ),
'view_item' => _x( 'View', 'lekcja_1' ),
'search_items' => _x( 'Search', 'lekcja_1' ),
'not_found' => _x( 'Not found', 'lekcja_1' ),
'not_found_in_trash' => _x( 'Nothing found in Trash', 'lekcja_1' ),
'parent_item_colon' => _x( 'Parent:', 'lekcja_1' ),
'menu_name' => _x( 'lekcja_1', 'lekcja_1' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Hi, this is my custom post type.',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'lekcja_1', $args );
}
/* kurs 2 */
 add_action( 'init', 'lekcja_2_post_type_func' );
function lekcja_2_post_type_func() {
$labels = array(
'name' => _x( 'lekcja_2', 'lekcja_2' ),
'singular_name' => _x( 'lekcja_2', 'lekcja_2' ),
'add_new' => _x( 'Add New', 'lekcja_2' ),
'add_new_item' => _x( 'Add New', 'lekcja_2' ),
'edit_item' => _x( 'Edit', 'lekcja_2' ),
'new_item' => _x( 'New', 'lekcja_2' ),
'view_item' => _x( 'View', 'lekcja_2' ),
'search_items' => _x( 'Search', 'lekcja_2' ),
'not_found' => _x( 'Not found', 'lekcja_2' ),
'not_found_in_trash' => _x( 'Nothing found in Trash', 'lekcja_2' ),
'parent_item_colon' => _x( 'Parent:', 'lekcja_2' ),
'menu_name' => _x( 'lekcja_2', 'lekcja_2' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Hi, this is my custom post type.',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'lekcja_2', $args );
}
/* kurs 3 */
  add_action( 'init', 'lekcja_3_post_type_func' );
function lekcja_3_post_type_func() {
$labels = array(
'name' => _x( 'lekcja_3', 'lekcja_3' ),
'singular_name' => _x( 'lekcja_3', 'lekcja_3' ),
'add_new' => _x( 'Add New', 'lekcja_3' ),
'add_new_item' => _x( 'Add New', 'lekcja_3' ),
'edit_item' => _x( 'Edit', 'lekcja_3' ),
'new_item' => _x( 'New', 'lekcja_3' ),
'view_item' => _x( 'View', 'lekcja_3' ),
'search_items' => _x( 'Search', 'lekcja_3' ),
'not_found' => _x( 'Not found', 'lekcja_3' ),
'not_found_in_trash' => _x( 'Nothing found in Trash', 'lekcja_3' ),
'parent_item_colon' => _x( 'Parent:', 'lekcja_3' ),
'menu_name' => _x( 'lekcja_3', 'lekcja_3' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Hi, this is my custom post type.',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'lekcja_3', $args );
}
/* kurs 4 */
  add_action( 'init', 'lekcja_4_post_type_func' );
function lekcja_4_post_type_func() {
$labels = array(
'name' => _x( 'lekcja_4', 'lekcja_4' ),
'singular_name' => _x( 'lekcja_4', 'lekcja_4' ),
'add_new' => _x( 'Add New', 'lekcja_4' ),
'add_new_item' => _x( 'Add New', 'lekcja_4' ),
'edit_item' => _x( 'Edit', 'lekcja_4' ),
'new_item' => _x( 'New', 'lekcja_4' ),
'view_item' => _x( 'View', 'lekcja_4' ),
'search_items' => _x( 'Search', 'lekcja_4' ),
'not_found' => _x( 'Not found', 'lekcja_4' ),
'not_found_in_trash' => _x( 'Nothing found in Trash', 'lekcja_4' ),
'parent_item_colon' => _x( 'Parent:', 'lekcja_4' ),
'menu_name' => _x( 'lekcja_4', 'lekcja_4' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Hi, this is my custom post type.',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'lekcja_4', $args );
}
/* kurs 5 */ 
  add_action( 'init', 'lekcja_5_post_type_func' );
function lekcja_5_post_type_func() {
$labels = array(
'name' => _x( 'lekcja_5', 'lekcja_5' ),
'singular_name' => _x( 'lekcja_5', 'lekcja_5' ),
'add_new' => _x( 'Add New', 'lekcja_5' ),
'add_new_item' => _x( 'Add New', 'lekcja_5' ),
'edit_item' => _x( 'Edit', 'lekcja_5' ),
'new_item' => _x( 'New', 'lekcja_5' ),
'view_item' => _x( 'View', 'lekcja_5' ),
'search_items' => _x( 'Search', 'lekcja_5' ),
'not_found' => _x( 'Not found', 'lekcja_5' ),
'not_found_in_trash' => _x( 'Nothing found in Trash', 'lekcja_5' ),
'parent_item_colon' => _x( 'Parent:', 'lekcja_5' ),
'menu_name' => _x( 'lekcja_5', 'lekcja_5' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Hi, this is my custom post type.',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'lekcja_5', $args );
}
/*kurs 6 */
  add_action( 'init', 'lekcja_6_post_type_func' );
function lekcja_6_post_type_func() {
$labels = array(
'name' => _x( 'lekcja_6', 'lekcja_6' ),
'singular_name' => _x( 'lekcja_6', 'lekcja_6' ),
'add_new' => _x( 'Add New', 'lekcja_6' ),
'add_new_item' => _x( 'Add New', 'lekcja_6' ),
'edit_item' => _x( 'Edit', 'lekcja_6' ),
'new_item' => _x( 'New', 'lekcja_6' ),
'view_item' => _x( 'View', 'lekcja_6' ),
'search_items' => _x( 'Search', 'lekcja_6' ),
'not_found' => _x( 'Not found', 'lekcja_6' ),
'not_found_in_trash' => _x( 'Nothing found in Trash', 'lekcja_6' ),
'parent_item_colon' => _x( 'Parent:', 'lekcja_6' ),
'menu_name' => _x( 'lekcja_6', 'lekcja_6' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Hi, this is my custom post type.',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'lekcja_6', $args );
}




function  logged_user()
{
  if (!is_user_logged_in()){ ?>
    
      <a class="nav-but" href="<?php echo get_home_url()?>/rejestracja">Utwórz darmowe konto</a>
    
    <?php } else { ?>
    <div class="col-sm-6 col-md-5 avatar-pos hidden-xs">
      <div class="row small-row">
      <?php
      $user = wp_get_current_user();
 
      if ( $user ) :
      ?>

      <div class="col-sm-8 col-md-8 avatar-welcome">
      Witaj: <b><?php  global $current_user;
      get_currentuserinfo();

      echo  $current_user->user_login; ?></b>
    </div>
    <a href="<?php echo wp_logout_url( home_url());?>"><div class="col-sm-8 col-md-4 menu-avatar" id="avatar1"  style="background-image:url('<?php echo esc_url( get_avatar_url( $user->ID ) ); ?>');" >
    <?php endif; ?>
    </div></a></div>  </div>
      <?php }

}





/* funkcja dodaje popup z loginem bądź rejestracją na podstawie atrybutu funkcji - obecnie zastąpiona funkcją logowania i rejestracji ajax  odpalamy ją tak<a data-toggle="modal" data-target="#loginmodal">Zaloguj się</a> i <a data-toggle="modal" data-target="#registermodal">Zarejestruj się</a>*/  

function login_register_modal($atr)
{
    $typ = $atr === "login" ?  "loginmodal" : "registermodal"; 
   ?>

   <!-- modal Zaloguj window -->
<!-- Modal -->
<div class="modal fade" id="<?php echo $typ; ?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo $typ; ?>Label" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="<?php echo $typ; ?>Label">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
         <?php 
         if ($atr === "login" )
         {

        if (!is_user_logged_in()){ wp_login_form( $args );}; 
      }
      else if ($atr === "register" )
      {
        echo "formularz rejestracji";
      }
      ?>
      </div>
    </div>
  </div>
</div>
<!-- koniec z modal --> 

   <?php
}

/*filtr dane do formularza logowania */
add_filter( 'login_form_defaults', 'login_ar' );
function login_ar() {
  $args = array(
  'echo'           => true,
  'remember'       => true,
  'redirect'       => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
  'form_id'        => 'loginform',
  'id_username'    => 'user_login',
  'id_password'    => 'user_pass',
  'id_remember'    => 'rememberme',
  'id_submit'      => 'wp-submit',
  'label_username' => __( 'Login' ),
  'label_password' => __( 'Hasło' ),
  'label_remember' => __( 'Remember Me' ),
  'label_log_in'   => __( 'Log In' ),
  'value_username' => '',
  'value_remember' => false
);
  return $args;
}


/*formularz rejestracji */
require get_template_directory() . '/ajax-login-register/ajax-login-register.php';

/* skrócenie znaków w excerpt */
function custom_excerpt_length( $length ) {
        return 10;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 60);

function lessons()
{
  ?>
  <script>

     document.getElementById("lekcja_1").onclick = function(){
    // navigate to new page

    window.location.href = "<?php echo get_home_url();?>/lekcja_1";
}

  document.getElementById("lekcja_2").onclick = function(){
    // navigate to new page

    window.location.href = "<?php echo get_home_url();?>/lekcja_2";
}
  document.getElementById("lekcja_3").onclick = function(){
    // navigate to new page

    window.location.href = "<?php echo get_home_url();?>/lekcja_3";
}
  document.getElementById("lekcja_4").onclick = function(){
    // navigate to new page

    window.location.href = "<?php echo get_home_url();?>/lekcja_4";
}
  document.getElementById("lekcja_5").onclick = function(){
    // navigate to new page

    window.location.href = "<?php echo get_home_url();?>/lekcja_5";
}
 document.getElementById("lekcja_6").onclick = function(){
    // navigate to new page

    window.location.href = "<?php echo get_home_url();?>/lekcja_6";
}

jQuery(".ls-block").addClass("cursor");
  </script>
  <?php
}

function block_unlg()
{
  if (!is_user_logged_in()) {
?>
<script>
  window.location.replace("<?php echo get_home_url();?>");
</script>

<?php

}
}
