HEX
Server: Apache/2.4.6 (CentOS) mpm-itk/2.4.7-04 mod_fcgid/2.3.9 PHP/5.4.16
System: Linux dvm.vladweb.ru 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: region-gk.ru (1016)
PHP: 7.3.33
Disabled: NONE
Upload Files
File: /home/region-gk.ru/data/www/region-gk.ru/wp-content/themes/region/functions.php
<?php
function region_add_woocommerce_support()
{
    add_theme_support('woocommerce');
}

add_action('after_setup_theme', 'region_add_woocommerce_support');


// Свойства
add_action('woocommerce_product_options_general_product_data', 'art_woo_add_custom_fields');
function art_woo_add_custom_fields()
{
    global $product, $post;
    ?>
    <div class="options_group">
        <h2><strong>Описание</strong></h2>
        <?php
        wp_editor(get_post_meta($post->ID, '_custom_desc', true), 'custom_desc', array(
            'wpautop' => 1,
            'media_buttons' => 1,
            'textarea_name' => 'custom_desc',
            'textarea_rows' => 10,
            'tabindex' => null,
            'editor_css' => '<style>.quicktags-toolbar, .wp-editor-tools, .wp-editor-wrap, .wp-switch-editor {padding: 5px 10px;}</style>',
            'editor_class' => 'form-field',
            'teeny' => 0,
            'dfw' => 0,
            'tinymce' => 1,
            'quicktags' => 1,
            'drag_drop_upload' => false
        ));

        ?>
    </div>
    <?php
}

add_action('woocommerce_process_product_meta', 'art_woo_custom_fields_save', 10);
function art_woo_custom_fields_save($post_id)
{
    // Сохранение области тектса
    $woocommerce_textarea = $_POST['custom_desc'];
    if (!empty($woocommerce_textarea)) {
        update_post_meta($post_id, '_custom_desc', $woocommerce_textarea);
    }

}

// Характеристики
add_action('woocommerce_product_options_general_product_data', 'art_woo_add_custom_fields2');
function art_woo_add_custom_fields2()
{
    global $product, $post;
    ?>
    <div class="options_group">
        <h2><strong>Характеристики</strong></h2>
        <?php
        wp_editor(get_post_meta($post->ID, '_custom_desc2', true), 'custom_desc2', array(
            'wpautop' => 1,
            'media_buttons' => 1,
            'textarea_name' => 'custom_desc2',
            'textarea_rows' => 10,
            'tabindex' => null,
            'editor_css' => '<style>.quicktags-toolbar, .wp-editor-tools, .wp-editor-wrap, .wp-switch-editor {padding: 5px 10px;}</style>',
            'editor_class' => 'form-field',
            'teeny' => 0,
            'dfw' => 0,
            'tinymce' => 1,
            'quicktags' => 1,
            'drag_drop_upload' => false
        ));

        ?>
    </div>
    <?php
}

add_action('woocommerce_process_product_meta', 'art_woo_custom_fields_save2', 10);
function art_woo_custom_fields_save2($post_id)
{
    // Сохранение области тектса
    $woocommerce_textarea = $_POST['custom_desc2'];
    if (!empty($woocommerce_textarea)) {
        update_post_meta($post_id, '_custom_desc2', $woocommerce_textarea);
    }

}

// Где используются
add_action('woocommerce_product_options_general_product_data', 'art_woo_add_custom_fields3');
function art_woo_add_custom_fields3()
{
    global $product, $post;
    ?>
    <div class="options_group">
        <h2><strong>Где используются</strong></h2>
        <?php
        wp_editor(get_post_meta($post->ID, '_custom_desc3', true), 'custom_desc3', array(
            'wpautop' => 1,
            'media_buttons' => 1,
            'textarea_name' => 'custom_desc3',
            'textarea_rows' => 5,
            'tabindex' => null,
            'editor_css' => '<style>.quicktags-toolbar, .wp-editor-tools, .wp-editor-wrap, .wp-switch-editor {padding: 5px 10px;}</style>',
            'editor_class' => 'form-field',
            'teeny' => 0,
            'dfw' => 0,
            'tinymce' => 1,
            'quicktags' => 1,
            'drag_drop_upload' => false
        ));

        ?>
    </div>
    <?php
}

add_action('woocommerce_process_product_meta', 'art_woo_custom_fields_save3', 10);
function art_woo_custom_fields_save3($post_id)
{
    // Сохранение области тектса
    $woocommerce_textarea = $_POST['custom_desc3'];
    if (!empty($woocommerce_textarea)) {
        update_post_meta($post_id, '_custom_desc3', $woocommerce_textarea);
    }

}

add_filter('woocommerce_output_related_products_args', 'jk_related_products_args');
function jk_related_products_args($args)
{
    $args['posts_per_page'] = 6;
    return $args;
}

function custom_woocommerce_catalog_orderby($orderby)
{
    unset($orderby["price"]);
    unset($orderby["price-desc"]);
    unset($orderby["popularity"]);
    unset($orderby["rating"]);
    unset($orderby["date"]);
    unset($orderby["title"]);
    unset($orderby["menu_order"]);
    return $orderby;
}

add_filter("woocommerce_catalog_orderby", "custom_woocommerce_catalog_orderby", 20);

function woocommerce_get_catalog_ordering_popular_args($args)
{
    global $wp_query;
    if (isset($_GET['orderby'])) {
        switch ($_GET['orderby']) :
            case 'default' :
                $args['orderby'] = 'date';
                $args['order'] = 'DESC';
                $args['meta_key'] = '';
                break;
            case 'name_list_asc' :
                $args['orderby'] = 'title';
                $args['order'] = 'ASC';
                $args['meta_key'] = '';
                break;
            case 'name_list_desc' :
                $args['orderby'] = 'title';
                $args['order'] = 'DESC';
                $args['meta_key'] = '';
                break;
        endswitch;
    }

    return $args;
}

add_filter('woocommerce_get_catalog_ordering_args', 'woocommerce_get_catalog_ordering_popular_args');
function woocommerce_catalog_popular_orderby($sortby)
{
    $sortby['default'] = 'По умолчанию';
    $sortby['name_list_asc'] = 'По алфавиту А-Я';
    $sortby['name_list_desc'] = 'По алфавиту Я-А';
    return $sortby;
}

add_filter('woocommerce_catalog_orderby', 'woocommerce_catalog_popular_orderby', 1);

add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );

add_action( 'wp_enqueue_scripts', 'add_styles' );
function add_styles()
{
     $css_file = get_stylesheet_directory() . '/css/style.min.css';
     wp_enqueue_style( 'css-file', get_stylesheet_directory_uri().'/css/style.min.css', NULL, filemtime($css_file) );
}

add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
	$url = ((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
	$url = explode('page', $url);
	$url = $url[0];
	
	return $url;
});
add_filter( 'rank_math/frontend/disable_adjacent_rel_links', '__return_true' );

function remove_json_api () {

    // Remove the REST API lines from the HTML Header
    remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );

    // Remove the REST API endpoint.
    remove_action( 'rest_api_init', 'wp_oembed_register_route' );

    // Turn off oEmbed auto discovery.
    add_filter( 'embed_oembed_discover', '__return_false' );

    // Don't filter oEmbed results.
    remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );

    // Remove oEmbed discovery links.
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );

    // Remove oEmbed-specific JavaScript from the front-end and back-end.
    remove_action( 'wp_head', 'wp_oembed_add_host_js' );

}
add_action( 'after_setup_theme', 'remove_json_api' );

remove_action('wp_head', 'rsd_link');
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 );



function css_to_wp_head() {
	wp_enqueue_style( 'wp_fontawesome_style', get_stylesheet_directory_uri() . '/css/fa-all.min.css', array(), null );
	wp_enqueue_style( 'wp_custom_style', get_stylesheet_directory_uri() . '/css/custom.css?'.time(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'css_to_wp_head' );

function js_to_wp_foot() {
	wp_enqueue_script( 'wp_fontawesome_js', get_stylesheet_directory_uri() . '/js/fa-all.min.js', array(), null, true );
	wp_enqueue_script( 'wp_custom_js', get_stylesheet_directory_uri() . '/js/custom.js?'.time(), array(), null, true );
}
add_action( 'wp_enqueue_scripts', 'js_to_wp_foot' );



function _wpcl_bcn_pick_post_term( $wp_term, $id, $type, $taxonomy ) {
$terms_post = get_the_terms( $post->cat_ID , 'product_cat' );
    foreach ($terms_post as $term_cat) { 
        if ($term_cat->term_id === 15) {
            return false;
        }
    }
	if ( get_cat_ID('Uncategorized') ) {
		return false;
	}
	return $wp_term;
};
add_filter( 'bcn_pick_post_term', '_wpcl_bcn_pick_post_term', 10, 4 );

add_action('admin_init', 'admin_area_ID');
function admin_area_ID() {
	// для таксономий (рубрик, меток и т.д.)
	foreach (get_taxonomies() as $taxonomy) {
		add_action("manage_edit-${taxonomy}_columns",          'tax_add_col');
		add_filter("manage_edit-${taxonomy}_sortable_columns", 'tax_add_col');
		add_filter("manage_${taxonomy}_custom_column",         'tax_show_id', 10, 3);
	}
	add_action('admin_print_styles-edit-tags.php', 'tax_id_style');
	function tax_add_col($columns) {return $columns + array ('tax_id' => 'ID');}
	function tax_show_id($v, $name, $id) {return 'tax_id' === $name ? $id : $v;}
	function tax_id_style() {print '<style>#tax_id{width:4em}</style>';}
	// для постов и страниц
	add_filter('manage_posts_columns', 'posts_add_col', 5);
	add_action('manage_posts_custom_column', 'posts_show_id', 5, 2);
	add_filter('manage_pages_columns', 'posts_add_col', 5);
	add_action('manage_pages_custom_column', 'posts_show_id', 5, 2);
	add_action('admin_print_styles-edit.php', 'posts_id_style');
	function posts_add_col($defaults) {$defaults['wps_post_id'] = __('ID'); return $defaults;}
	function posts_show_id($column_name, $id) {if ($column_name === 'wps_post_id') echo $id;}
	function posts_id_style() {print '<style>#wps_post_id{width:4em}</style>';}
}

add_filter( 'rank_math/frontend/description', function( $description ) {
    $cat = get_the_terms( $post->ID, 'product_cat' )[0]->term_id;
    if ($cat >= 102 && $cat <= 155) :
        return get_the_title() . ' - купить по выгодным ценам. Доставим быстро по Приморскому краю. Гарантия качества! ' . get_the_title() .' - качественная продукция в ассортименте.';
    endif;
	return $description;
});

// admin
add_action( 'admin_enqueue_scripts', 'load_admin_style' );
function load_admin_style() {
    /*wp_register_style( 'admin_css', get_template_directory_uri() . '/admin-styles.css', false, '1.0.0' );*/
    //OR
    wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/admin-styles.css', false );
}



/**
 * Template Parts with Display Posts Shortcode
 * @author Bill Erickson
 * @see https://www.billerickson.net/template-parts-with-display-posts-shortcode
 *
 * @param string $output, current output of post
 * @param array $original_atts, original attributes passed to shortcode
 * @return string $output
 */
function be_dps_template_part( $output, $original_atts ) {

	// Return early if our "layout" attribute is not specified
	if( empty( $original_atts['layout'] ) )
		return $output;
	ob_start();
	get_template_part( 'partials/dps', $original_atts['layout'] );
	$new_output = ob_get_clean();
	if( !empty( $new_output ) )
		$output = $new_output;
	return $output;
}
add_action( 'display_posts_shortcode_output', 'be_dps_template_part', 10, 2 );



/*
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . '/');
  
/**
* Filter the single_template with our custom function
*/
add_filter('single_template', 'my_single_template');
  
/**
* Single template function which will choose our template
*/
function my_single_template($single) {
global $wp_query, $post;
  
/**
* Checks for single template by category
* Check by category slug and ID
*/
foreach((array)get_the_category() as $cat) :
  
if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';
  
elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';

else return SINGLE_PATH . '/single.php';
  
endforeach;
}