HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/zaklada/wp-content/themes/zaklada/functions.php
<?php

define('THEMEROOT', get_stylesheet_directory_uri() . "/");
define('FILEROOT', dirname(__DIR__) . '/' . get_option('stylesheet'));



add_action('wp_enqueue_scripts', function () {
  wp_register_script('dinamo-vendor', THEMEROOT . 'frontend/js/vendor/vendor.bundle.js');
  wp_register_script('dinamo-core', THEMEROOT . 'frontend/js/core.bundle.js?v=12');
  $translation_array = array('templateUrl' => get_template_directory_uri());
  wp_localize_script('dinamo-core', 'object_name', $translation_array);
});


function dinamoZaklada_setup()
{
 // Make Zaklada available for translation. Translations can be added to the /languages/ directory.
	load_theme_textdomain( 'dinamo', get_template_directory() . '/languages' );   
}
add_action('after_setup_theme', 'dinamoZaklada_setup');


add_action( 'init', function(){

    add_theme_support( 'post-thumbnails' );
/* Navigation Menus */
register_nav_menus(array(

    'main-l' => 'Main Menu - Left',
    'main-r'  => 'Main Menu - Right',
    'footer-l'  => 'Footer Menu - Left',
    'footer-r'  => 'Footer Menu - Right',

));

    add_image_size( '4x3_small', 488, 387, true );

    add_image_size( '9x6_large', 960, 640, true );
    add_image_size( '9x6_small', 486, 324, true );

});

function get_pagination($current_page, $total_pages){

    $pages_before_current_result = array();
    $has_more_start = false;
    $has_more_end = false;
    $pages_after_current_result = array();
    for ($x = 1; $x < $current_page; $x++) {
        $pages_before_current_result[] = $x;
    }
    for ($x = $current_page + 1; $x < $total_pages +1; $x++) {
        $pages_after_current_result[] = $x;
    }

    if ($current_page - 3 > 1){
        $has_more_start = true;
    }
    if($current_page + 3 < $total_pages){
        $has_more_end = true;
    }

    return array(
        'pages_before_current' => $pages_before_current_result,
        'pages_after_current' => $pages_after_current_result,
        'has_more_start' => $has_more_start,
        'has_more_end' => $has_more_end,
    );


}


    function get_image_alt($attach_id){

        $alt_text = get_post_meta($attach_id, '_wp_attachment_image_alt', true);
        if(empty($alt_text)) // If not, Use the Caption
        {
            $attachment = get_post($attach_id);
            $alt_text = trim(strip_tags( $attachment->post_excerpt ));
        }
        if(empty($alt_text)) // Finally, use the title
        {
            $attachment = get_post($attach_id);
            $alt_text = trim(strip_tags( $attachment->post_title ));
        }

        return $alt_text;

    }


    function get_menu_children($nav_menu, $parent_id){
        $nav_children = array();
        foreach ($nav_menu as $sub) {
            if ($sub->menu_item_parent == $parent_id) {
                $nav_children[] = $sub;
            }
        }

        return $nav_children;
    }


function count_posts_wpml($language_code = '', $default_language_code = '', $post_type = 'post'){
    global $sitepress, $wpdb;

    if($default_language_code == ''){
        $default_language_code = $sitepress->get_default_language();
    }

    if($post_type == 'page'){
        $post_type = 'post_page';
    } else if($post_type == 'post'){
        $post_type = 'post_post';
    } else {
        return;
    }

    $query = "SELECT COUNT( wp_posts.ID )
FROM {$wpdb->prefix}posts
LEFT JOIN {$wpdb->prefix}icl_translations ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}icl_translations.element_id
WHERE {$wpdb->prefix}icl_translations.language_code = '{$language_code}'
AND {$wpdb->prefix}icl_translations.source_language_code = '{$default_language_code}'
AND {$wpdb->prefix}icl_translations.element_type = '{$post_type}'";

    return $wpdb->get_var( $query );
}

function render_main_menu($menu, $location, $lang = false){

        $menu_items = wp_get_nav_menu_items( wp_get_nav_menu_name($menu ) ); ?>

        <ul class="site-header__nav site-header__<?= $location ?>">
        <?php foreach ( $menu_items as $menu_item ):

            if($menu_item->menu_item_parent == 0) {

                $children = get_menu_children($menu_items, $menu_item->ID);
                $dropdown_class = "";
                if(count($children) > 0){
                    $dropdown_class = "dropdown";
                }
                ?>

                <li class="site-header__item <?= $dropdown_class ?> <?= esc_attr(implode(' ', $menu_item->classes)) ?>">
                    <a href="<?= esc_url($menu_item->url) ?>"
                    target="<?= esc_attr($menu_item->target ?: '_self') ?>"
                    class="site-header__link"><?= esc_html($menu_item->title); ?></a>

                    <?php if(count($children) > 0){ ?>
                        <ul class="site-header__submenu">
                            <?php foreach($children as $child){ ?>
                                <li class="site-header__submenu-item">
                                    <a target="<?= esc_attr($child->target ?: '_self') ?>" href="<?= esc_html($child->url) ?>" class="site-header__submenu-link"><?= esc_html($child->title); ?></a>
                                </li>
                            <?php } ?>
                        </ul>
                    <?php } ?>
                </li>
                <?php
            }
            
        endforeach;
    
    /**
     * - custom language switchers using the icl_get_languages API call from WPML
     *  https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/
     *  @param array $languages
     *  note: Rename image flags flags-hr(language code).svg 
     */
    
    if ( is_plugin_active( 'wpml-media-translation/plugin.php' ) ){
        if($lang){ 
            
            $languages = icl_get_languages('skip_missing=0&orderby=code');

             //  $languages = array(); // temporarly disabled
            if(!empty($languages)){ ?>

                <li class="site-header__item lang-dropdown">
                <div class="lang-dropdown__wrap">

                <?php
                foreach($languages as $l){
                    if($l['active'] ){?>
                        <div class="lang-dropdown__active">
                            <img src="<?php echo THEMEROOT; ?>frontend/img/icons/flag-<?php echo $l['language_code'];?>.svg" class="lang-dropdown__img" alt="<?php echo $l['language_code']; ?>">
                            <div class="site-header__link"><?php echo $l['language_code']; ?></div>
                            <img src="<?php echo THEMEROOT; ?>frontend/img/icons/arrow-down.svg" class="lang-dropdown__arrow" alt="<?php echo $l['language_code']; ?>">
                        </div>
                    <?php }    
                    if(!$l['active']){?>
                        <div class="lang-dropdown__submenu">
                            <a href="<?php echo $l['url'];?>" class="lang-dropdown__item">
                                <img src="<?php echo THEMEROOT; ?>frontend/img/icons/flag-<?php echo $l['language_code'];?>.svg" class="lang-dropdown__img" alt="<?php echo $l['language_code']; ?>">
                                <div class="site-header__link"><?php echo $l['language_code'];?></div>
                            </a>
                        </div>
                    <?php }
                } ?>
                </div><!-- lang dropdown wrap -->
                </li><!-- item lang -->
        <?php }
                    
                    
    }
    
    } ?>
        
        </ul>
       <?php
    }