add_action('get_header', 'wp_maintenance_mode'); /** * codex functions and definitions * * @link https://developer.wordpress.org/themes/basics/theme-functions/ * * @package codex */ if ( ! defined( '_S_VERSION' ) ) { // Replace the version number of the theme on each release. define( '_S_VERSION', '1.0.0' ); } /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which * runs before the init hook. The init hook is too late for some features, such * as indicating support for post thumbnails. */ function codex_setup() { // Add default posts and comments RSS feed links to head. add_theme_support( 'automatic-feed-links' ); /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support( 'title-tag' ); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support( 'post-thumbnails' ); // This theme uses wp_nav_menu() in one location. register_nav_menus( array( 'menu-1' => esc_html__( 'Primary', 'codex' ), ) ); /* * Switch 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', 'gallery', 'caption', 'style', 'script', ) ); } add_action( 'after_setup_theme', 'codex_setup' ); /** * Set the content width in pixels, based on the theme's design and stylesheet. * * Priority 0 to make it available to lower priority callbacks. * * @global int $content_width */ function codex_content_width() { $GLOBALS['content_width'] = apply_filters( 'codex_content_width', 640 ); } add_action( 'after_setup_theme', 'codex_content_width', 0 ); function codex_scripts() { wp_enqueue_style( 'codex-style', get_stylesheet_uri(), array(), _S_VERSION ); // #STYLES wp_enqueue_style( 'typography', get_template_directory_uri() . '/source/css/typography.css', array(), _S_VERSION ); wp_enqueue_style( 'style-base', get_template_directory_uri() . '/source/css/style-base.css', array(), _S_VERSION ); wp_enqueue_style( 'style', get_template_directory_uri() . '/source/css/style.css', array(), _S_VERSION ); wp_enqueue_style( 'components', get_template_directory_uri() . '/source/css/components.css', array(), _S_VERSION ); wp_enqueue_style( 'grid', get_template_directory_uri() . '/source/css/grid.css', array(), _S_VERSION ); wp_enqueue_style( 'page-wrapper', get_template_directory_uri() . '/source/css/page-wrapper.css', array(), _S_VERSION ); // #SCRIPTS wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'js', get_template_directory_uri() . '/source/js/require.js', array(), _S_VERSION, true ); wp_enqueue_script( 'library', get_template_directory_uri() . '/source/js/library.js', array(), _S_VERSION, true ); wp_enqueue_script( 'javascript', get_template_directory_uri() . '/source/js/javascript.js', array(), _S_VERSION, true ); } add_action( 'wp_enqueue_scripts', 'codex_scripts' ); add_filter( 'woocommerce_breadcrumb_home_url', 'wpbl_breadcrumbs_home_url' ); function wpbl_breadcrumbs_home_url() { return wc_get_page_permalink( 'shop' ); // Устанавливаем ссылку на главную страницу магазина. } function scaled_image_path($attachment_id, $size = 'thumbnail') { $file = get_attached_file($attachment_id, true); if (empty($size) || $size === 'full') { // for the original size get_attached_file is fine return realpath($file); } if (! wp_attachment_is_image($attachment_id) ) { return false; // the id is not referring to a media } $info = image_get_intermediate_size($attachment_id, $size); if (!is_array($info) || ! isset($info['file'])) { return false; // probably a bad size argument } return realpath(str_replace(wp_basename($file), $info['file'], $file)); } // #POST_TYPES add_action( 'init', 'register_post_types' ); function register_post_types(){ register_post_type('application', [ 'label' => "Заявки", 'supports' => array( 'title', ), 'public' => false, 'show_ui' => true, 'menu_position' => 2, 'has_archive' => false, 'rewrite' => false, ] ); /* register_post_type('services', array( 'label' => null, 'labels' => array( 'menu_name' => 'Услуги', 'name' => 'Услуги', 'singular_name' => 'Услуга', 'add_new' => 'Добавить услугу', 'add_new_item' => 'Добавление услуги', 'edit_item' => 'Редактирование услуги', 'new_item' => 'Новая услуга', 'view_item' => 'Смотреть услугу', 'search_items' => 'Искать услугу', 'not_found' => 'Не найдено', 'not_found_in_trash' => 'Не найдено в корзине', ), 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'page-attributes', 'post-formats', ), 'public' => true, 'publicly_queryable' => true, 'query_var' => true, 'has_archive' => true, )); register_post_type('projects', array( 'label' => 'Портфолио', 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'page-attributes', 'post-formats', ), 'public' => true, 'publicly_queryable' => true, 'query_var' => true, 'has_archive' => true, )); */ } add_action( 'save_post', 'custom_fields_save', 0 ); function custom_fields_save( $post_id ) { $fields = array('_service'); foreach( $fields as $field ) { if( isset( $_POST['meta'][$field] )) { $value = $_POST['meta'][$field]; if(is_string($value)){ update_post_meta( $post_id, $field, esc_attr( $value ) ); } else{ foreach( $value as $_key => $_value ) { if($_value == '-1'){ delete_post_meta( $post_id, $field.'_'.$_key ); } else{ update_post_meta( $post_id, $field.'_'.$_key, esc_attr( $_value ) ); } } } } } } if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( 'page_title' => 'Настройки сайта', 'menu_title' => 'Настройки сайта', 'menu_slug' => 'theme-general-settings', 'capability' => 'edit_posts', 'redirect' => false )); } add_filter( 'upload_mimes', 'my_upload_mimes' ); function my_upload_mimes( $mime_types ) { $mime_types['svg'] = 'image/svg+xml'; $mime_types['json'] = 'text/plain'; $mime_types['csv'] = 'text/csv'; return $mime_types; } add_action('wp_ajax_ql_woocommerce_ajax', 'ql_woocommerce_ajax'); add_action('wp_ajax_nopriv_ql_woocommerce_ajax', 'ql_woocommerce_ajax'); function ql_woocommerce_ajax(){ global $woocommerce; $_JSON = array( 'POST' => $_POST, 'PRODUCT' => array('quantity' => 0, 'total' => 0), ); $product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0; $variation_id = isset($_POST['variation_id']) ? absint($_POST['variation_id']) : 0; $quantity = isset($_POST['quantity']) ? absint($_POST['quantity']) : 0; $price = 0; $product = wc_get_product( $product_id ); if(!empty($variation_id)){ $variation = wc_get_product( $variation_id ); } if(!empty($variation)){ $price = $variation->get_price(); } else{ $price = $product->get_price(); } $attributes = array(); if(!empty($_POST['attributes'])){ foreach($_POST['attributes'] as $key => $value){ $attributes[$key] = $value; } } $cart_item_data = array(); $cart_item_data['addsell'] = ""; if(!empty($_POST['addsell'][$product_id])){ $cart_item_data['addsell'] = serialize($_POST['addsell'][$product_id]); } $cart_item_data['adddata'] = ""; if(!empty($_POST['adddata'][$product_id])){ $cart_item_data['adddata'] = serialize($_POST['adddata'][$product_id]); } $cart_item = get_cart_item( $product_id, $variation_id ); if(!empty($cart_item['key'])){ $cart_item_key = $cart_item['key']; } if(!empty($cart_item_key)){ $woocommerce->cart->set_quantity($cart_item_key, $quantity); } else{ $woocommerce->cart->add_to_cart($product_id, $quantity, $variation_id, $attributes, $cart_item_data); } $_CART = $woocommerce->cart->get_cart(); if(!empty($_CART)){ foreach($_CART as $value){ if($value['product_id'] == $product_id && $value['variation_id'] == $variation_id ){ $_JSON['PRODUCT'] = array( 'quantity' => $value['quantity'], 'total' => $value['line_total'], ); } } } $_JSON['CART'] = $woocommerce->cart->get_totals(); $_JSON['CART']['quantity'] = $woocommerce->cart->get_cart_contents_count(); $_JSON['CART']['sum'] = $woocommerce->cart->get_cart_contents_total(); print json_encode($_JSON); wp_die(); } function get_image($post = false, $size = 'medium'){ $image = '/wp-content/themes/afina/assets/images/no-image.svg'; if(!empty($post)){ $image_id = get_post_thumbnail_id($post); if(!empty($image_id)){ $image_url = wp_get_attachment_image_url($image_id, $size); if(!empty($image_url)){ $image = $image_url; } } } return $image; } function breadcrumbs($data){ if(!is_array($data)){ return; } $return = array(); $url = ""; foreach($data as $key => $value){ $url_full = false; if(is_array($value)){ $url_path = $value[0]; $url_value = $value[1]; if(!empty($value[2])){ $url_full = true; } } else{ $url_path = $key; $url_value = $value; } if(!empty($url_path)){ if($url_full == true){ $url = $url_path; } else{ $url = $url . trim($url_path, "/") . "/"; } } $return[] = "<li class=\"breadcrumb-item fs-14\"><a href=\"".$url."\">".$url_value."</a></li>"; } return implode("\n", $return); } function get_numeric($num = 0){ if(!is_numeric($num)){ $num = (float) preg_replace('/[^0-9\.]/', '', preg_replace('/\,/', '.', $num)); } return (float) $num; } function get_number($num = 0){ return rtrim(rtrim(number_format(get_numeric($num), 2, '.', ' '), '0'), '.'); } function get_phone_nubmers($str = ""){ $str = trim($str); $str = preg_replace('/[^0-9\+]/', '', $str); return $str; } function get_price($num = 0, $class = ''){ return '<span'.(!empty($class)?' class="'.$class.'"':'').'>'.get_number($num).'</span> ₽'; } function get_month_name($no = 1){ $months = array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"); return !empty($months[--$no]) ? $months[$no] : $months[0]; } function get_cart_item($product_id = 0, $variation_id = 0){ static $cart = null; if(!empty($product_id)){ if($cart === null){ $cart = WC()->cart->get_cart(); } if(!empty($cart)){ foreach($cart as $cart_item_key => $cart_item){ if($cart_item['product_id'] == $product_id && $cart_item['variation_id'] == $variation_id){ return $cart_item; } } } } } function get_excerpt( $args = '' ){ global $post; if( is_string( $args ) ){ parse_str( $args, $args ); } $rg = (object) array_merge( [ 'post' => false, 'maxchar' => 170, 'text' => '', 'autop' => false, 'more_text' => '', 'ignore_more' => false, // 'save_tags' => '<strong><b><a><em><i><var><code><span>', 'save_tags' => '', 'sanitize_callback' => static function( string $text, object $rg ){ return strip_tags( $text, $rg->save_tags ); }, ], $args ); $rg = apply_filters( 'kama_excerpt_args', $rg ); if( ! $rg->text ){ if(!empty($rg->post)){ $rg->text = $rg->post->post_excerpt ?: $rg->post->post_content; } else{ $rg->text = $post->post_excerpt ?: $post->post_content; } } $text = $rg->text; // strip content shortcodes: [foo]some data[/foo]. Consider markdown $text = preg_replace( '~\[([a-z0-9_-]+)[^\]]*\](?!\().*?\[/\1\]~is', '', $text ); // strip others shortcodes: [singlepic id=3]. Consider markdown $text = preg_replace( '~\[/?[^\]]*\](?!\()~', '', $text ); // strip direct URLs $text = preg_replace( '~(?<=\s)https?://.+\s~', '', $text ); $text = trim( $text ); // echo $text; // <!--more--> if( ! $rg->ignore_more && strpos( $text, '<!--more-->' ) ){ preg_match( '/(.*)<!--more-->/s', $text, $mm ); $text = trim( $mm[1] ); // $text_append = sprintf( ' <a href="%s#more-%d">%s</a>', get_permalink( $post ), $post->ID, $rg->more_text ); } // text, excerpt, content else { $text = call_user_func( $rg->sanitize_callback, $text, $rg ); $has_tags = false !== strpos( $text, '<' ); // collect html tags if( $has_tags ){ $tags_collection = []; $nn = 0; $text = preg_replace_callback( '/<[^>]+>/', static function( $match ) use ( & $tags_collection, & $nn ){ $nn++; $holder = "~$nn"; $tags_collection[ $holder ] = $match[0]; return $holder; }, $text ); } // cut text $cuted_text = mb_substr( $text, 0, $rg->maxchar ); if( $text !== $cuted_text ){ // del last word, it not complate in 99% $text = preg_replace( '/(.*)\s\S*$/s', '\\1...', trim( $cuted_text ) ); } // bring html tags back if( $has_tags ){ $text = strtr( $text, $tags_collection ); $text = force_balance_tags( $text ); } } // add <p> tags. Simple analog of wpautop() if( $rg->autop ){ $text = preg_replace( [ "/\r/", "/\n{2,}/", "/\n/" ], [ '', '</p><p>', '<br />' ], "<p>$text</p>" ); } $text = apply_filters( 'kama_excerpt', $text, $rg ); if( isset( $text_append ) ){ $text .= $text_append; } $text = trim( preg_replace("/\n{2,}/", "\n\n", $text) ); return $text; } function get_text_fields($_fields = array(), $_post = array()){ $result = array(); if(!empty($_fields)){ foreach($_fields as $_field => $_name){ if(!empty($_post[$_field])){ $_value = $_post[$_field]; if(is_array($_value)){ $_value = implode(", ", array_diff($_value, array('')) ); } if(!empty($_value)){ $result[] = "<p><b>".$_name.":</b> ".$_value."</p>"; } } } } return implode("\n", $result); } function admin_email_send($data = array()){ if(empty($data['headers'])){ $data['headers'] = array( 'From: noreply@'.$_SERVER['HTTP_HOST'].' <noreply@'.$_SERVER['HTTP_HOST'].'>', 'Content-type: text/html; charset=utf-8', ); } if(empty($data['attachments'])){ $data['attachments'] = null; } if(empty($admin_email)){ $admin_email = get_field('admin_email', 'option'); } if(empty($admin_email)){ $admin_email = get_option('admin_email'); } if(!empty($admin_email)){ $responce = wp_mail( $admin_email, $data['subject'], $data['message'], $data['headers'], $data['attachments'] ); } } add_action( 'wp_ajax_js_form', 'ajax_js_form' ); add_action( 'wp_ajax_nopriv_js_form', 'ajax_js_form' ); function ajax_js_form(){ // $_SERVER['HTTP_HOST'] = 'барбекю26.рф'; $_SERVER['AJAX'] = array( '_POST' => $_POST, ); if(!empty($_POST['callback'])){ $_SERVER['AJAX']['callback'] = $_POST['callback']; } $_type = !empty($_POST['type']) ? $_POST['type'] : ''; $_fields = array(); if(!empty($_POST['_fields'])){ $base64 = base64_decode( $_POST['_fields'] ); if(!empty($base64)){ $unserialize = unserialize( $base64 ); if(!empty($unserialize)){ $_fields = $unserialize; } } unset($_POST['_fields']); } $_post = $_POST; $post_name = md5( microtime() ); $guid = "https://".$_SERVER['HTTP_HOST']."/application/?id=".$post_name; $post_title = "Заявка с сайта ".$_SERVER['HTTP_HOST']; $post_content = get_text_fields($_fields, $_post); $attachments = []; if($_type == 'review'){ if(!empty($_POST['product_id'])){ $data = array( 'comment_post_ID' => $_POST['product_id'], 'comment_author' => $_POST['name'], 'comment_content' => $_POST['text'], 'comment_type' => 'review', 'comment_date' => current_time('mysql'), 'comment_approved' => 0, ); $comment_ID = wp_insert_comment($data); if(is_numeric($comment_ID)){ add_comment_meta( $comment_ID, 'rating', $_POST['rating'], true); } } $subject = 'Отзыв на сайте'; $message = $post_content; } else{ $meta_input = array( '_fields' => $_fields, '_post' => $_post, ); $post_data = array( 'post_name' => $post_name, 'post_content' => $post_content, 'guid' => $guid, 'meta_input' => $meta_input, 'post_status' => 'private', 'post_type' => 'application', ); $post_id = wp_insert_post( $post_data ); if(is_numeric($post_id)){ $post_title = $post_title." №".$post_id; $_post_data = array( 'ID' => $post_id, 'post_title' => $post_title, ); $upload_files = array( 'upload_file' => 'file', ); foreach($upload_files as $key => $value){ $media_ids = upload_files($key, $post_id); if(!empty($media_ids)){ $_post_data['meta_input'][$value] = $media_ids; } } wp_update_post( $_post_data ); } $subject = $post_title; $message = $post_content; } if(!empty($media_ids)){ $_args = array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post__in' => $media_ids, ); $wp_query_attachment = new WP_Query($_args); if(!empty($wp_query_attachment->posts)){ foreach ($wp_query_attachment->posts as $post){ $attachments[] = get_path_form_url($post->guid); } } } if(!empty($subject) && !empty($message)){ admin_email_send( array( 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, ) ); // telegram_message($subject."\n".$message); } if(!empty($_SERVER['AJAX'])){ wp_die( json_encode($_SERVER['AJAX']) ); } } function upload_files($name = '', $post_id = 0){ $result = []; if(!empty($_FILES[$name])){ $files = $_FILES[$name]; if(!empty($files['name'])){ foreach($files['name'] as $key => $value){ if(!empty($value)){ $file = array( 'name' => $files['name'][ $key ], 'type' => $files['type'][ $key ], 'tmp_name' => $files['tmp_name'][ $key ], 'error' => $files['error'][ $key ], 'size' => $files['size'][ $key ], ); $media_id = media_handle_sideload($file, $post_id); if(is_numeric($media_id)){ $result[] = $media_id; } } } } } return $result; } function get_path_form_url($url){ $data = parse_url($url); if(!empty($data['path'])){ return ABSPATH . substr($data['path'], 1); } } add_filter( 'show_admin_bar', '__return_false' ); add_action('add_meta_boxes', 'true_add_metabox'); function true_add_metabox() { add_meta_box( 'application_metabox', 'Метаданные', 'application_metabox_callback', 'application', 'normal', 'default' ); } function application_metabox_callback( $post ) { $_meta = get_post_meta( $post->ID ); $_fields = array(); $_post = array(); if(!empty($_meta['_fields'][0])){ $_fields = unserialize($_meta['_fields'][0]); } if(!empty($_meta['_post'][0])){ $_post = unserialize($_meta['_post'][0]); } ?> <table class="striped widefat"> <tbody> </tbody> </table> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/fas5018853/fashtech.ru/docs/wp-content/themes/codex/functions.php:1) in <b>/home/fas5018853/fashtech.ru/docs/wp-includes/pluggable.php</b> on line <b>1535</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/fas5018853/fashtech.ru/docs/wp-content/themes/codex/functions.php:1) in <b>/home/fas5018853/fashtech.ru/docs/wp-includes/pluggable.php</b> on line <b>1538</b><br />