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/dinamo-shop/wp-content/plugins/dinamo-plugin/index.php
<?php
/*
Plugin Name: Dinamo Site Plugin
Plugin URI: http://gnkdinamo.hr
Description: The site plugin for gnkdinamo.hr containing custom post types, custom fields and specific features
Version: 1.0
Author: Dinamo
Author URI: http://www.gnkdinamo.hr/
Text Domain: dinamo
*/





function my_plugin_load_plugin_textdomain() {
    load_plugin_textdomain( 'dinamo_shop_plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}

function print_name_and_number($name, $number) {
    $print = "";
    if($name && $number) {
        $print .= "<br /> " . __("NATPIS: ", "dinamo_shop_plugin") . $name . " | " . __("BROJ: ", "dinamo_shop_plugin") . $number;
    }
    return $print;
}

function print_number ($number) {    
    $print = "";
    if($number) {
        $print .= " | " . __("BROJ: ", "dinamo_shop_plugin") . $number;
    }
    return $print;
}

function get_print_name_for_print_type($print_type, $print_name_value, $print_number_value){
    $print_product_id = get_product_for_print_type($print_type);
    $print_product = wc_get_product($print_product_id);

    if($print_type) {
        if ($print_type == "1") {
            $print_name = __("Tisak natpisa i broja", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        } else if ($print_type == "2") {
            $print_name = __("Tisak broja", "dinamo_shop_plugin");
            $print_name .= print_number($print_number_value);
        } else if ($print_type == "3") {
            $print_name = __("Tisak broja, naziva i sponzora na prsima", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        } else if ($print_type == "4") {
            $print_name = __("Tisak sponzora na prsima", "dinamo_shop_plugin");
        } else if ($print_type == "5") {
            $print_name = __("Tisak broja, naziva, sponzora na prsima i PSK sponzora", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        } else if ($print_type == "6") {
            $print_name = __("Tisak sponzora na prsima i PSK sponzora", "dinamo_shop_plugin");
        } else if ($print_type == "7") {
            $print_name = __("Tisak broja, natpisa i PSK sponzora", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }    
        else if ($print_type == "8") {
            $print_name = __("Tisak broja, naziva i sponzora na leđima", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }else if ($print_type == "9") {
            $print_name = __("Tisak broja, naziva, sponzora na prsima i leđima", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }else if ($print_type == "10") {
            $print_name = __("Tisak sponzora na leđima", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }else if ($print_type == "11") {
            $print_name = __("Tisak sponzora na prsima i leđima", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }else if ($print_type == "12") {
            $print_name = __("Tisak broja, naziva, sponzora na leđima i PSK sponzora", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }else if ($print_type == "13") {
            $print_name = __("Tisak broja, naziva, sponzora na prsima, leđima i PSK sponzora", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }else if ($print_type == "14") {
            $print_name = __("Tisak sponzora na leđima i PSK sponzora", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }else if ($print_type == "15") {
            $print_name = __("Tisak sponzora na prsima, leđima i PSK sponzora", "dinamo_shop_plugin");
            $print_name .= print_name_and_number($print_name_value, $print_number_value);
        }
    }
    return $print_name;
}

function get_print_type_price($print_type, $product_id){
    $print_product_id = get_product_for_print_type($print_type);
    $print_product = wc_get_product($print_product_id);
    if($print_product != null) {


        if(get_field("free_personalization", $product_id)){
             return 0;
        }else {
            return $print_product->get_price();
        }


    }else{
        return 0;
    }
}

function calculate_price_with_print($regular_price, $print_type, $product_id, $add_europa_league = 0){

    $print_price = get_print_type_price($print_type, $product_id);

    if($add_europa_league) {
      $europa_league_print_product_id = get_field('print_europa_league', 'option');
      $europa_league_print_product = new WC_Product($europa_league_print_product_id);
      $europa_league_print_price = $europa_league_print_product->get_price();
      $print_price = (float)$print_price + (float)$europa_league_print_price;
    }
    return (float)$regular_price + (float)$print_price;
}





function get_product_for_print_type($print_type){

    if($print_type == "1"){
        $print_product = get_field("print_name_and_number_product", "option");
    }else if ($print_type == "2") {
        $print_product = get_field("print_number_product", "option");
    }else if ($print_type == "3") {
        $print_product = get_field("print_name_number_and_sponsor_logo_product", "option");
    }else if ($print_type == "4") {
        $print_product = get_field("print_sponsor_logo_product", "option");
    }else if ($print_type == "5") {
        $print_product = get_field("print_name_number_sponsor_logo_and_psk_logo_product", "option");
    }
    else if ($print_type == "6") {
        $print_product = get_field("print_sponsor_logo_and_psk_logo_product", "option");
    }
    else if ($print_type == "7") {
        $print_product = get_field("print_name_number_and_psk_logo_product", "option");
    }
    
    else if ($print_type == "8") {
        $print_product = get_field("print_name_number_and_sponsor_on_back_logo_product", "option");
    }else if ($print_type == "9") {
        $print_product = get_field("print_name_number_sponsor_on_front_and_back_product", "option");
    }else if ($print_type == "10") {
        $print_product = get_field("print_sponsor_on_back", "option");
    }else if ($print_type == "11") {
        $print_product = get_field("print_sponsor_on_front_and_back_product", "option");
    }else if ($print_type == "12") {
        $print_product = get_field("print_name_number_sponsor_on_back_logo_and_psk_logo_product", "option");
    }else if ($print_type == "13") {
        $print_product = get_field("print_name_number_sponsor_on_front_and_back_and_psk_logo_product", "option");
    }else if ($print_type == "14") {
        $print_product = get_field("print_sponsor_on_back_logo_and_psk_logo_product", "option");
    }else if ($print_type == "15") {
        $print_product = get_field("print_sponsor_on_front_and_back_and_psk_logo_product", "option");
    }

    else {
        $print_product = null;
    }

    return $print_product;
}

add_action( 'plugins_loaded', 'my_plugin_load_plugin_textdomain' );

require_once 'algoliasearch-client-php-master/algoliasearch.php';
require_once 'algolia/index.php';
require_once 'widgets/index.php';

require_once 'ajax/cart.php';
require_once 'ajax/account.php';



// Custom theme settings page
add_action( 'acf/init', function(){
    if( function_exists('acf_add_options_page') ) {
        acf_add_options_page(array(
            'page_title' => __( 'Theme settings', 'dinamo' ),
            'menu_title' => __( 'Theme settings', 'dinamo' ),
            'menu_slug'  => 'dinamo-theme-settings',
        ));

        acf_add_options_page(array(
            'page_title' => __( 'Algolia', 'dinamo' ),
            'menu_title' => __( 'Algolia', 'dinamo' ),
            'menu_slug'  => 'dinamo-algolia-transfer',
        ));
    }
});



function dinamo_locate_template( $template_name, $template_path = '', $default_path = '' ) {
    // Set variable to search in woocommerce-plugin-templates folder of theme.
    if ( ! $template_path ) :
        $template_path = 'dinamo-plugin/';
    endif;
    // Set default plugin templates path.
    if ( ! $default_path ) :
        $default_path = plugin_dir_path( __FILE__ ) . 'templates/'; // Path to the template folder
    endif;
    // Search template file in theme folder.
    $template = locate_template( array(
        $template_path . $template_name,
        $template_name
    ) );
    // Get plugins template file.
    if ( ! $template ) :
        $template = $default_path . $template_name;
    endif;
    return apply_filters( 'dinamo_locate_template', $template, $template_name, $template_path, $default_path );
}



// Orders Manager custom user role

add_action( 'init', function(){
    // remove_role( 'order_manager' );
    add_role( 'order_manager', 'Order Manager', array(
      'read' => true,
      'edit_posts' => true,
      'manage_woocomerce' => true, 
      'publish_shop_order' => true,
      'edit_shop_order' => true,
      'edit_shop_orders' => true,
      'edit_published_shop_orders' => true,
      'edit_private_shop_orders' => true,
      'edit_others_shop_orders' => true,
      'read_shop_order' => true,
      'shop_order' => true,
      'view_admin_dashboard' => true, 
    ));  
});


add_action( 'admin_menu', function(){
    $curr_user = wp_get_current_user();
  
    $menus = $GLOBALS[ 'menu' ];
  
    if( in_array( 'order_manager', $curr_user->roles ) ){
      foreach( $menus as $menu ){
        if( $menu['2'] != 'edit.php?post_type=shop_order' ){
          remove_menu_page( $menu['2'] );
        }
      }
    }
  
  }, 999);


add_action( 'current_screen', function(){
$screen = get_current_screen();

$curr_user = wp_get_current_user();

    if( $screen->id != ('edit-shop_order' || 'shop_order' ) && in_array( 'order_manager', $curr_user->roles ) ){
        wp_redirect( admin_url('edit.php?post_type=shop_order' ) );
    }

});


function autocancel_wc_orders(){
	$query = ( array(
		'limit'   => 5,
		'orderby' => 'date',
		'order'   => 'DESC', 
    'status'  => array( 'on-hold' ),
    'date_query' => array(
      array(
        'before' => '5 days ago',
      )
    ),
	) );
  
	$orders = wc_get_orders( $query );
	foreach( $orders as $order ){		
			$order->update_status('cancelled', 'Cancelled for missing bank payment');		
	}
}

add_action( 'admin_init', 'autocancel_wc_orders' );

// Save ACF fields in JSON
add_filter('acf/settings/save_json', 'dinamo_acf_json_save_point');
function dinamo_acf_json_save_point( $path ) {

    // update path
    $path = plugin_dir_path(__FILE__) . 'acf-json';

    return $path;
}

// Load ACF fields from JSON
add_filter('acf/settings/load_json', 'dinamo_acf_json_load_point');
function dinamo_acf_json_load_point( $paths ) {

    // remove original path (optional)
    unset($paths[0]);

    // append path
    $paths[] = plugin_dir_path(__FILE__) . 'acf-json';

    return $paths;
}