File: /mnt/data/dev/dev-dreamstour-wp/wp-content/themes/dreamstour/inc/init.php
<?php
// Get current ID of post/page, etc
if( !function_exists( 'dreamstour_get_current_id' )):
function dreamstour_get_current_id(){
if (get_query_var('user_type') && get_query_var('dashboard_tab')) {
$dashboard_page_id = get_theme_mod('dashboard_page');
return $dashboard_page_id ?: get_the_ID();
}
$current_page_id = '';
// Get The Page ID You Need
if(class_exists("woocommerce")) {
if( is_shop() ){
$current_page_id = get_option ( 'woocommerce_shop_page_id' );
}elseif(is_cart()) {
$current_page_id = get_option ( 'woocommerce_cart_page_id' );
}elseif(is_checkout()){
$current_page_id = get_option ( 'woocommerce_checkout_page_id' );
}elseif(is_account_page()){
$current_page_id = get_option ( 'woocommerce_myaccount_page_id' );
}elseif(is_view_order_page()){
$current_page_id = get_option ( 'woocommerce_view_order_page_id' );
}
}
if($current_page_id=='') {
if ( is_home () && is_front_page () ) {
$current_page_id = '';
} elseif ( is_home () ) {
$current_page_id = get_option ( 'page_for_posts' );
} elseif ( is_search () || is_category () || is_tag () || is_tax () || is_archive() ) {
$current_page_id = '';
} elseif ( !is_404 () ) {
$current_page_id = get_the_id();
}
}
return $current_page_id;
}
endif;
if( !function_exists( 'dreamstour_pagination_theme' )):
function dreamstour_pagination_theme() {
if ( is_singular() )
return;
global $wp_query;
if ( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
$links = [];
if ( $paged >= 1 )
$links[] = $paged;
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 1;
$links[] = $paged + 2;
}
echo '<nav class="pagination-nav mb-4 mb-lg-0"><ul class="pagination justify-content-center">' . "\n";
/** Previous Link (only show if not on first page) */
if ( get_previous_posts_link() ) {
printf(
'<li class="page-item previous-page">%s</li>' . "\n",
get_previous_posts_link('<span aria-hidden="true"><i class="fa-solid fa-chevron-left"></i></span>')
);
}
/** First page */
if ( ! in_array( 1, $links ) ) {
$class = ( 1 == $paged ) ? ' active' : '';
printf( '<li class="page-item%s"><a class="page-link" href="%s">1</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ) );
if ( ! in_array( 2, $links ) ) {
echo '<li class="page-item disabled"><a class="page-link" href="javascript:void(0);">…</a></li>' . "\n";
}
}
/** Middle pages */
sort( $links );
foreach ( (array) $links as $link ) {
$class = ( $paged == $link ) ? ' active' : '';
printf( '<li class="page-item%s"><a class="page-link" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Last page */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) ) {
echo '<li class="page-item disabled"><a class="page-link" href="javascript:void(0);">…</a></li>' . "\n";
}
$class = ( $paged == $max ) ? ' active' : '';
printf( '<li class="page-item%s"><a class="page-link" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Link (only show if not on last page) */
if ( get_next_posts_link() ) {
printf(
'<li class="page-item next-page">%s</li>' . "\n",
get_next_posts_link('<span aria-hidden="true"><i class="fa-solid fa-chevron-right"></i></span>')
);
}
echo '</ul></nav>' . "\n";
}
endif;
if( !function_exists( 'dreamstour_pagination_theme_old' )):
function dreamstour_pagination_theme_old() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo wp_kses( __( '<div class="blog-pagination"><nav><ul class="pagination page-item justify-content-center">','dreamstour' ), true ) . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li class="previtem page-numbers">%s</li>' . "\n", get_previous_posts_link('<i class="fas fa-regular fa-arrow-left me-2"></i>'. esc_html__('Prev', 'dreamstour')) );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s><a class="page-item" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo wp_kses( __('<li><a class="page-item">•••</a></li>' ,'dreamstour') , true);
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo wp_kses( __('<li><a class="page-item">•••</a></li>' ,'dreamstour') , true) . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li class="nextlink page-numbers">%s</li>' . "\n", get_next_posts_link(esc_html__('Next', 'dreamstour').' <i class="fas fa-regular fa-arrow-right ms-2"></i>') );
echo wp_kses( __( '</ul></nav></div>' ,'dreamstour'), true ) . "\n";
}
endif;
/* Setup Theme */
/* Add theme support */
add_action('after_setup_theme', 'dreamstour_theme_support', 10);
add_filter('oembed_result', 'dreamstour_framework_fix_oembeb', 10 );
add_filter('paginate_links', 'dreamstour_fix_pagination_error',10);
function dreamstour_theme_support(){
if ( ! isset( $content_width ) ) $content_width = 900;
add_theme_support('title-tag');
// Adds RSS feed links to <head> for posts and comments.
add_theme_support( 'automatic-feed-links' );
// Switches default core markup for search form, comment form, and comments
// to output valid HTML5.
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'script', 'style' ) );
/* See http://codex.wordpress.org/Post_Formats */
/// add_theme_support( 'post-formats', array( 'image', 'gallery', 'audio', 'video') );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'custom-header' );
add_theme_support( 'custom-background');
add_image_size( 'dreamstour_list', '350', false );
add_image_size( 'dreamstour_m', '600', false );
add_image_size( 'dreamstour_bloglist', '855', false );
add_image_size( 'dreamstour_bloggrid', '415', false );
add_theme_support( 'woocommerce' );
}
function dreamstour_framework_fix_oembeb( $url ){
$array = array (
'webkitallowfullscreen' => '',
'mozallowfullscreen' => '',
'frameborder="0"' => '',
'</iframe>)' => '</iframe>'
);
$url = strtr( $url, $array );
if ( strpos( $url, "<embed src=" ) !== false ){
return str_replace('</param><embed', '</param><param name="wmode" value="opaque"></param><embed wmode="opaque" ', $url);
}
elseif ( strpos ( $url, 'feature=oembed' ) !== false ){
return str_replace( 'feature=oembed', 'feature=oembed&wmode=opaque', $url );
}
else{
return $url;
}
}
// Fix pagination
function dreamstour_fix_pagination_error($link) {
return str_replace('#038;', '&', $link);
}
function dreamstour_wpadminjs() {
wp_enqueue_style('dreamstour_fixcssadmin', get_template_directory_uri() . '/inc/cssadmin.css', false, '1.1');
}
add_action( 'admin_enqueue_scripts', 'dreamstour_wpadminjs' );
add_filter( 'woocommerce_product_description_heading', 'dreamstour_remove_product_description_heading' );
function dreamstour_remove_product_description_heading() {
return '';
}
add_action( 'woocommerce_before_cart', 'dreamstour_woocommerce_before_cart', 10, 1 );
function dreamstour_woocommerce_before_cart(){
echo '<div class="dreamstour_page_cart">';
}
add_action( 'woocommerce_after_cart', 'dreamstour_woocommerce_after_cart', 10, 1 );
function dreamstour_woocommerce_after_cart(){
echo '</div>';
}
add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_delimiter' );
function wcc_change_breadcrumb_delimiter( $defaults ) {
// Change the breadcrumb delimeter from '/' to '>'
$defaults['delimiter'] = ' > ';
return $defaults;
}
add_filter( 'woocommerce_output_related_products_args', 'dreamstour_related_products_args' );
function dreamstour_related_products_args( $args ) {
$args['posts_per_page'] = 3; // 4 related products
$args['columns'] = 3; // arranged in 2 columns
return $args;
}
function dreamstour_heading_title(){
ob_start();
$user_type = get_query_var('user_type');
$dashboard_tab = get_query_var('dashboard_tab');
if ($user_type && $dashboard_tab) {
// Dashboard page titles
$tabs = [
'agent' => [
'overview' => __('Agent Dashboard', 'dreamstour'),
'tours' => __('My Tours', 'dreamstour'),
'bookings' => __('Bookings', 'dreamstour'),
'earnings' => __('Earnings', 'dreamstour'),
'reviews' => __('Reviews', 'dreamstour'),
'profile' => __('Profile', 'dreamstour'),
],
'customer' => [
'overview' => __('Customer Dashboard', 'dreamstour'),
'bookings' => __('My Bookings', 'dreamstour'),
'wishlist' => __('Wishlist', 'dreamstour'),
'reviews' => __('My Reviews', 'dreamstour'),
'profile' => __('Profile', 'dreamstour'),
]
];
if (isset($tabs[$user_type][$dashboard_tab])) {
echo esc_html($tabs[$user_type][$dashboard_tab]);
} else {
echo esc_html(ucfirst($user_type) . ' ' . __('Dashboard', 'dreamstour'));
}
} else if (is_page_template('page-templates/dashboard.php')) {
// Main dashboard page
echo esc_html__('Dashboard', 'dreamstour');
}
else {
// Author Tours Template: custom heading
if (is_page_template('author-tours.php')) {
$author_label = '';
$author_slug = get_query_var('author_name');
if (!empty($author_slug)) {
$u = get_user_by('slug', $author_slug);
if ($u) { $author_label = $u->display_name; }
}
if ($author_label === '' && isset($_GET['author_id'])) {
$u = get_user_by('id', absint($_GET['author_id']));
if ($u) { $author_label = $u->display_name; }
}
if ($author_label === '' && is_user_logged_in()) {
$u = wp_get_current_user();
if ($u && $u->ID) { $author_label = $u->display_name; }
}
if ($author_label !== '') {
echo esc_html(sprintf(__('Author: %s', 'dreamstour'), $author_label));
return ob_get_clean();
}
}
// Your existing logic for other pages
if( class_exists( 'woocommerce' ) && is_woocommerce() ){
if( isset( $_GET['dsrent_search'] ) && $_GET['dsrent_search'] != '' ){
echo esc_html__( 'Search' ,'dreamstour');
}else if ( is_product_category() || is_shop() ){
if ( apply_filters( 'woocommerce_show_page_title', true ) ) :
woocommerce_page_title();
endif;
}else if( is_product() ){
$product = wc_get_product( get_the_id() );
if( !$product->is_type( 'dsrent_car_rental' ) ){
the_title();
}
}else{
the_title();
}
}else{
if( isset( $_GET['dsrent_search'] ) && $_GET['dsrent_search'] != '' ){
echo esc_html__( 'Search','dreamstour' );
} else if ( is_home() ) {
echo esc_html__( 'Blog','dreamstour');
} else if ( is_search () ) {
echo esc_html__( 'Search','dreamstour' );
} elseif( is_category() ){
echo single_cat_title();
} elseif( is_tag() ){
echo esc_html__( 'Tag','dreamstour' );
} elseif( is_tax () || is_archive() ){
the_archive_title();
} else if( is_single() ){
echo esc_html__( 'Post Detail','dreamstour' );
} else if( is_single() ){
echo esc_html( 'Post Detail','dreamstour' );
} else if ( !is_404 () ) {
if( get_post_meta( dreamstour_get_current_id() ,'dreamstour_met_page_heading', true ) != 'no' ){
the_title();
}
}else if( is_404() ){
echo esc_html__( '404 Page','dreamstour' );
}
}
}
return ob_get_clean();
}
function dreamstour_breadcrumbs_header(){
$user_type = get_query_var('user_type');
$dashboard_tab = get_query_var('dashboard_tab');
if ($user_type && $dashboard_tab) {
// Display custom breadcrumbs for dashboard
dreamstour_dashboard_breadcrumbs($user_type, $dashboard_tab);
} else {
// Existing breadcrumb logic for other pages
if( isset( $_GET['dsrent_search'] ) && $_GET['dsrent_search'] != '' ){
dreamstour_breadcrumbs();
}else if( ! ( class_exists( 'woocommerce' ) && is_woocommerce() ) ){
if( get_post_meta( dreamstour_get_current_id() ,'dreamstour_met_show_breadcrumbs', true ) != 'no' ){
dreamstour_breadcrumbs();
}
}else if( is_product() ){
$product = wc_get_product( get_the_id() );
if( !$product->is_type( 'dsrent_car_rental' ) ){
do_action( 'woocommerce_before_main_content' );
}
}else{
do_action( 'woocommerce_before_main_content' );
}
}
}
// New function for dashboard breadcrumbs
function dreamstour_dashboard_breadcrumbs($user_type, $current_tab) {
$dashboard_page_id = get_theme_mod('dashboard_page');
$dashboard_url = get_permalink($dashboard_page_id);
$tabs = [
'agent' => [
'overview' => __('Overview', 'dreamstour'),
'tours' => __('My Tours', 'dreamstour'),
'bookings' => __('Bookings', 'dreamstour'),
'earnings' => __('Earnings', 'dreamstour'),
'reviews' => __('Reviews', 'dreamstour'),
'profile' => __('Profile', 'dreamstour'),
],
'customer' => [
'overview' => __('Overview', 'dreamstour'),
'bookings' => __('My Bookings', 'dreamstour'),
'wishlist' => __('Wishlist', 'dreamstour'),
'reviews' => __('My Reviews', 'dreamstour'),
'profile' => __('Profile', 'dreamstour'),
]
];
?>
<nav class="dreamstour-dashboard-breadcrumb" aria-label="breadcrumb">
<ol class="breadcrumb justify-content-center">
<li class="breadcrumb-item">
<a href="<?php echo esc_url(home_url('/')); ?>">
<i class="isax isax-home5 me-1"></i>
</a>
</li>
<li class="breadcrumb-item">
<!-- <a href="<?php echo esc_url($dashboard_url); ?>"> -->
<?php esc_html_e('Dashboard', 'dreamstour'); ?>
<!-- </a> -->
</li>
<?php if ($current_tab !== 'overview' && isset($tabs[$user_type][$current_tab])): ?>
<li class="breadcrumb-item active" aria-current="page">
<?php echo esc_html($tabs[$user_type][$current_tab]); ?>
</li>
<?php endif; ?>
</ol>
</nav>
<?php
}