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/tana/wp-content/themes/tana/functions.php
<?php

function tana_register_scripts() {

  wp_enqueue_style( 'style', get_stylesheet_uri() );

}
add_action( 'wp_enqueue_scripts', 'tana_register_scripts' );




function tana_register_menus() {

  register_nav_menus(array(
      'main-menu' => __( 'Main Menu' )
     ));

 }
add_action( 'init', 'tana_register_menus' );


function tana_add_classes_on_li( $classes, $item, $args ) {

  $classes[] = 'navbar-nav__item';

    if ( in_array( 'current-menu-item', $classes ) ) {
  		$classes[] = ' navbar-nav__item--active';
  	}

  return $classes;

}
add_filter( 'nav_menu_css_class', 'tana_add_classes_on_li', 1, 3 );



function tana_add_attributes_on_menu ( $atts, $item, $args ) {

  $page_id = get_post_meta( $item->ID, '_menu_item_object_id', true );

  if ( $item->ID == $item->ID ) :
    $atts['data-target'] = $page_id;
  endif;

  return $atts;

}
add_filter ( 'nav_menu_link_attributes', 'tana_add_attributes_on_menu', 10, 3 );



function tana_post_type_support() {

  add_theme_support( 'post-thumbnails' );

  remove_post_type_support( 'page', 'editor' );
  remove_post_type_support( 'post', 'editor' );

}
add_action( 'init', 'tana_post_type_support');



function tana_pages_ajax() {

  global $post;

  $page_id = $_POST['page-id'];
  // $page    = get_post( '19' );
  $slug    = get_page_template_slug ( $page_id );

  ob_start();
  get_template_part( str_replace(".php", "", $slug) );
  $page_content = ob_get_contents();
  ob_end_clean();

  $style = get_field( 'theme_style', $page_id );

  if ( is_page() && $post->post_parent ) {
    $style = get_field( 'theme_style', $page_id->post_parent );
  } else {
    $style = get_field( 'theme_style', $page_id );
  }

  $result = array();

  array_push( $result, array(
    'theme' => $style,
    'content' => $page_content
  ));

  wp_send_json( $result );
}
add_action( 'wp_ajax_nopriv_tana_pages_ajax', 'tana_pages_ajax' );
add_action( 'wp_ajax_tana_pages_ajax', 'tana_pages_ajax' );



function tana_secondary_pages_ajax() {

  $page_id    = $_POST['page-id'];
  $article_id = $_POST['article-id'];

  $hide_country_subpage = get_field('hide_country_subpages', $page_id);

  $services = array('patents', 'trade_marks', 'industrial_design', 'copyright', 'litigation', 'domain_names');

  $result = array();

  switch( $_REQUEST['data-subpage-type'] ) {
    case 'about' :
      array_push( $result, array(
        'title'  => get_field( 'hidden_title', $page_id),
        'image'  => get_field( 'hidden_image', $page_id )['url'],
        'h_text' => get_field( 'hidden_highlighted_text', $page_id ),
        'text'   => get_field( 'hidden_text', $page_id )
      ));
      break;
    case 'about-subpage' :
      array_push( $result, array(
        'title'  => get_field( 'title', $page_id),
        'h_text' => get_field( 'highlighted_text', $page_id ),
        'text'   => get_field( 'text', $page_id )
      ));
      break;

    case 'slovenia' :
    if(!$hide_country_subpage) :
      $si = get_field( 'slovenia', $page_id );
      array_push( $result, array(
        'title'    => $si['title'],
        'h_text'   => $si['highlighted_text'],
        'text'     => $si['text'],
      ));
    endif;
      break;
    case 'croatia' :
    if(!$hide_country_subpage) :
      $hr = get_field( 'croatia', $page_id );
      array_push( $result, array(
        'title'    => $hr['title'],
        'h_text'   => $hr['highlighted_text'],
        'text'     => $hr['text'],
      ));
    endif;
      break;
    case 'bosnia-herzegovina' :
    if(!$hide_country_subpage) :
      $ba = get_field( 'bosnia-herzegovina', $page_id );
      array_push( $result, array(
        'title'    => $ba['title'],
        'h_text'   => $ba['highlighted_text'],
        'text'     => $ba['text'],
      ));
    endif;
      break;
    case 'montenegro' :
    if(!$hide_country_subpage) :
      $me = get_field( 'montenegro', $page_id );
      array_push( $result, array(
        'title'    => $me['title'],
        'h_text'   => $me['highlighted_text'],
        'text'     => $me['text'],
      ));
    endif;
      break;
    case 'serbia' :
    if(!$hide_country_subpage) :
      $rs = get_field( 'serbia', $page_id );
        array_push( $result, array(
          'title'    => $rs['title'],
          'h_text'   => $rs['highlighted_text'],
          'text'     => $rs['text']
        ));
      endif;
      break;
    case 'kosovo' :
    if(!$hide_country_subpage) :
      $xk = get_field( 'kosovo', $page_id );
      array_push( $result, array(
        'title'    => $xk['title'],
        'h_text'   => $xk['highlighted_text'],
        'text'     => $xk['text']
      ));
    endif;
      break;
    case 'macedonia' :
    if(!$hide_country_subpage) :
      $mk = get_field( 'macedonia', $page_id );
      array_push( $result, array(
        'title'    => $mk['title'],
        'h_text'   => $mk['highlighted_text'],
        'text'     => $mk['text']
      ));
    endif;
      break;
    case 'albania' :
    if(!$hide_country_subpage) :
      $al = get_field( 'albania', $page_id );
      array_push( $result, array(
        'title'    => $al['title'],
        'h_text'   => $al['highlighted_text'],
        'text'     => $al['text']
      ));
    endif;
      break;

    case 'patents':
      $p = get_field('patents', $page_id);
      array_push( $result, array(
        'title'  => $p['title'],
        'desc'   => $p['description'],
        'h_text' => $p['highlighted_text'],
        'text'   => $p['text']
      ));
      break;
    case 'trade_marks':
      $tm = get_field('trade_marks', $page_id);
      array_push( $result, array(
        'title'  => $tm['title'],
        'desc'   => $tm['description'],
        'h_text' => $tm['highlighted_text'],
        'text'   => $tm['text']
      ));
      break;
    case 'industrial_design':
      $id = get_field('industrial_design', $page_id);
      array_push( $result, array(
        'title'  => $id['title'],
        'desc'   => $id['description'],
        'h_text' => $id['highlighted_text'],
        'text'   => $id['text']
      ));
      break;
    case 'copyright':
      $cr = get_field('copyright', $page_id);
      array_push( $result, array(
        'title'  => $cr['title'],
        'desc'   => $cr['description'],
        'h_text' => $cr['highlighted_text'],
        'text'   => $cr['text']
      ));
      break;
    case 'litigation':
      $lt = get_field('litigation', $page_id);
      array_push( $result, array(
        'title'  => $lt['title'],
        'desc'   => $lt['description'],
        'h_text' => $lt['highlighted_text'],
        'text'   => $lt['text']
      ));
      break;
      case 'domain_names':
        $dn = get_field('domain_names', $page_id);
        array_push( $result, array(
          'title'  => $dn['title'],
          'desc'   => $dn['description'],
          'h_text' => $dn['highlighted_text'],
          'text'   => $dn['text']
        ));
        break;

      case 'article' :
        array_push( $result, array(
          'title'         => get_the_title( $article_id ),
          'image'         => get_the_post_thumbnail_url( $article_id ),
          'imgalt'        => get_the_post_thumbnail_caption( $article_id ),
          'h_text'        => get_field( 'highlighted_text', $article_id  ),
          'text'          => get_field( 'text', $article_id  ),
          'publish_date'  => get_the_date( 'F d, Y', $article_id )
        ));
        break;
      case 'team' :
        $department = get_field( 'department', $page_id );
        array_push($result, $department);
        break;
      case 'links-grid' :
        $links = get_field( 'links', $page_id );
        array_push($result, $links);
        break;

    }

    wp_send_json( $result );

  }
add_action( 'wp_ajax_nopriv_tana_secondary_pages_ajax', 'tana_secondary_pages_ajax' );
add_action( 'wp_ajax_tana_secondary_pages_ajax', 'tana_secondary_pages_ajax' );


function tiny_mce_remove_unused_formats( $init ) {

	$init['block_formats'] = 'Paragraph=p;Heading 3=h3;';

	return $init;
}
add_filter('tiny_mce_before_init', 'tiny_mce_remove_unused_formats' );



function is_ajax(){

  if( ! empty( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] ) &&
      strtolower( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ]) == 'xmlhttprequest' ) {
    return true;
  };

  return false;

}



function tana_posts_load_more() {

  $ppp   = $_POST['ppp'];
  $paged = $_POST['paged'];
  $id    = $_POST['page-id'];

  $firstpage = 8;

  if ( $paged == 1 ) {
    $offset = 0;
  } elseif ( $paged == 2 ) {
    $offset = $firstpage;
  } elseif ( $paged > 2 ) {
    $offset = $firstpage + (6 * $paged);
  }

  if ( $paged == 1 ) { ?>
    <div class="col-sm-6 col-md-8 faded">

      <?php
        $featured = get_field( 'featured_post', $id );

        if( $featured == 'latest' ) :
          $_post = new WP_Query(array(
            'posts_per_page' => 1,
            'orderby'        => 'publish_date',
            'order'          => 'DESC'
          ));

          if( $_post->have_posts() ) :
            while( $_post->have_posts() ) :
              $_post->the_post();
              $first = $_post->posts[0]->ID;
                require_once( get_template_directory() . '/partials/post-short.php' );
              endwhile;
            endif;

        elseif( $featured == 'choose' ) :
          $_post = get_field( 'choose_featured_post', $id );

          if( $_post ) :
            $post = $_post;
            $first = $post->ID;
            setup_postdata( $post );
              require_once( get_template_directory() . '/partials/post-short.php' );
            wp_reset_postdata();
          endif;

        endif;
       ?>

    </div>

    <?php
      $_posts = new WP_Query(array(
        'posts_per_page' => 7,
        'orderby'        => 'publish_date',
        'order'          => 'DESC',
        'post__not_in'   => array( $first )
      ));

      if( $_posts->have_posts() ) :
        while ( $_posts->have_posts() ) :
          $_posts->the_post();?>
          <div class="col-sm-6 col-md-4 faded">
            <?php include( get_template_directory() . '/partials/post-short.php' ); ?>
          </div>
          <?php
        endwhile;
        wp_reset_postdata();
      endif;

    } else {

  $_posts = new WP_Query(array(
    'posts_per_page' => $ppp,
    'orderby'        => 'publish_date',
    'order'          => 'DESC',
    'offset'         => $offset,
  ));

  if( $_posts->have_posts() ) :
    while ( $_posts->have_posts() ) :
      $_posts->the_post(); ?>
      <div class="col-sm-6 col-md-4 faded">
        <?php include( get_template_directory() . '/partials/post-short.php' ); ?>
      </div>
      <?php
    endwhile;
    wp_reset_postdata();
  endif;

}

  wp_die();

}
add_action('wp_ajax_nopriv_tana_posts_load_more', 'tana_posts_load_more');
add_action('wp_ajax_tana_posts_load_more', 'tana_posts_load_more');


function tana_posts_category_load_more() {

  $ppp      = $_POST['ppp'];
  $category = $_POST['category'];
  $offset   = $_POST['offset'];

  $_posts = new WP_Query(array(
    'posts_per_page' => $ppp,
    'orderby'        => 'publish_date',
    'order'          => 'DESC',
    'offset'         => $offset,
    'cat'            => $category
  ));

  if( $_posts->have_posts() ) :
    while ( $_posts->have_posts() ) :
      $_posts->the_post(); ?>
      <div class="col-sm-6 col-md-4 faded">
        <?php include( get_template_directory() . '/partials/post-short.php' ); ?>
      </div>
      <?php
    endwhile;
    wp_reset_postdata();
  endif;

  wp_die();

}
add_action('wp_ajax_nopriv_tana_posts_category_load_more', 'tana_posts_category_load_more');
add_action('wp_ajax_tana_posts_category_load_more', 'tana_posts_category_load_more');