new functions
This commit is contained in:
105
functions.php
105
functions.php
@@ -35,7 +35,7 @@ function theme_enqueue_styles_scripts()
|
||||
|
||||
wp_enqueue_style('main-style', get_template_directory_uri() . '/frontend/dist/assets/main.css', array(), $style_ver);
|
||||
wp_enqueue_script('main-script2', get_template_directory_uri() . '/frontend/dist/assets/main2.js', array(), $script_ver, true);
|
||||
|
||||
|
||||
// Preconnect for Google Fonts
|
||||
//wp_enqueue_style('google-fonts-preconnect', 'https://fonts.gstatic.com', [], null, 'all');
|
||||
//wp_resource_hints(['https://fonts.googleapis.com', 'https://fonts.gstatic.com'], 'preconnect');
|
||||
@@ -266,6 +266,7 @@ function loadmore_ajax_handler()
|
||||
$args = json_decode(stripslashes($_POST['query']), true);
|
||||
$args['paged'] = $_POST['page'] + 1; // следующая страница
|
||||
$args['post_status'] = 'publish';
|
||||
$args['posts_per_page'] = 12;
|
||||
$args['cat'] = [-17, -20, -21];
|
||||
|
||||
query_posts($args);
|
||||
@@ -561,31 +562,31 @@ function custom_meta_tags() {
|
||||
|
||||
$og_tags .= '<meta property="og:locale" content="ru_RU">';
|
||||
$og_tags .= '<meta property="og:site_name" content="'. $sitename .'">'. PHP_EOL;
|
||||
|
||||
|
||||
|
||||
// Получаем заголовок страницы
|
||||
if (is_single() || is_page()) {
|
||||
|
||||
$current_url = get_permalink();
|
||||
|
||||
|
||||
$post = get_post(); // Получаем объект текущего поста или страницы
|
||||
$title = get_the_title($post).' - '.$sitename; // Получаем заголовок текущего поста или страницы
|
||||
$excerpt = get_the_excerpt($post);
|
||||
|
||||
if (has_excerpt()) {
|
||||
$description = $excerpt;
|
||||
$description = $excerpt;
|
||||
} elseif (strlen($excerpt) > 300) {
|
||||
$description = wp_trim_words($excerpt, 30, '...');
|
||||
$description = wp_trim_words($excerpt, 30, '...');
|
||||
} else {
|
||||
$description = $excerpt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$tags = get_the_tags($post); // Получаем теги текущего поста или страницы
|
||||
$keywords = ''; // Переменная для хранения ключевых слов
|
||||
if ($tags) {
|
||||
$keywords = implode(', ', wp_list_pluck($tags, 'name')); // Формируем строку с тегами через запятую
|
||||
}
|
||||
|
||||
|
||||
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
|
||||
$post_thumbnail_url = wp_get_attachment_image_src($post_thumbnail_id, 'full');
|
||||
if ($post_thumbnail_url) {
|
||||
@@ -630,7 +631,7 @@ function custom_meta_tags() {
|
||||
if (!empty($keywords)) {
|
||||
$meta_tags .= '<meta name="keywords" content="' . esc_attr($keywords) . '">'. PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Выводим мета-теги
|
||||
echo $meta_tags;
|
||||
@@ -642,18 +643,18 @@ add_action('wpcf7_before_send_mail', 'my_custom_contact_form_handler', 10, 3);
|
||||
function my_custom_contact_form_handler($contact_form, $abort, $submission) {
|
||||
|
||||
|
||||
|
||||
|
||||
// Получаем ID формы
|
||||
$form_id = $contact_form->id();
|
||||
|
||||
|
||||
if ( $form_id == '0ddb83c' ) {
|
||||
|
||||
|
||||
// Получаем данные формы
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
|
||||
|
||||
if ($submission) {
|
||||
|
||||
|
||||
$posted_data = $submission->get_posted_data();
|
||||
|
||||
// Подключаемся к базе данных WordPress
|
||||
@@ -661,7 +662,7 @@ function my_custom_contact_form_handler($contact_form, $abort, $submission) {
|
||||
|
||||
// Определяем таблицу в базе данных WordPress в зависимости от ID формы
|
||||
$table_name = $wpdb->prefix . 'subusers';
|
||||
|
||||
|
||||
$wpdb->insert(
|
||||
$table_name,
|
||||
array(
|
||||
@@ -690,11 +691,11 @@ function last_sticky_post() {
|
||||
if ( $last !== null){
|
||||
return $last;
|
||||
}
|
||||
|
||||
|
||||
$sticky_posts = array_reverse(get_option('sticky_posts'));
|
||||
|
||||
$published_sticky_posts = array();
|
||||
|
||||
|
||||
foreach ($sticky_posts as $post_id) {
|
||||
$post = get_post($post_id);
|
||||
if ($post->post_status == 'publish') {
|
||||
@@ -758,7 +759,7 @@ function agroxpert_send_smtp_email( $phpmailer ) {
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->Port = 465;
|
||||
$phpmailer->Username = 'news@mail.agroexpert.press';
|
||||
$phpmailer->Password = 'O6K!]aZDNJ';
|
||||
$phpmailer->Password = 'O6K!]aZDNJ';
|
||||
$phpmailer->SMTPSecure = 'ssl';
|
||||
$phpmailer->From = 'news@mail.agroexpert.press';
|
||||
$phpmailer->FromName = 'Агроэксперт';
|
||||
@@ -770,18 +771,18 @@ add_action( 'phpmailer_init', 'agroxpert_send_smtp_email' );
|
||||
|
||||
|
||||
function my_custom_mail_sent( $contact_form ){
|
||||
|
||||
|
||||
$log_file = WP_CONTENT_DIR . '/contact.log';
|
||||
|
||||
$form_id = $contact_form->id();
|
||||
$form_id = $contact_form->id();
|
||||
|
||||
//if ( $form_id == '19' ) {
|
||||
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
$posted_data = $submission->get_posted_data();
|
||||
|
||||
$mail = $posted_data['your-email'];
|
||||
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'subusers';
|
||||
$hash = md5('775+'.$mail);
|
||||
@@ -790,7 +791,7 @@ function my_custom_mail_sent( $contact_form ){
|
||||
$result = $wpdb->get_row($query);
|
||||
|
||||
if ( !$result ) { //аdd to table
|
||||
|
||||
|
||||
$result = $wpdb->insert(
|
||||
$table_name,
|
||||
array(
|
||||
@@ -806,10 +807,10 @@ function my_custom_mail_sent( $contact_form ){
|
||||
'%s'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
|
||||
$hash_link = home_url().'/subscript?id='.$hash;
|
||||
@@ -826,20 +827,20 @@ $hash_link.\n\n
|
||||
wp_mail($mail, $subject, $message, $headers);
|
||||
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
add_action('wpcf7_mail_sent', 'my_custom_mail_sent' );
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
if (!function_exists('view')){
|
||||
function view ($view, $data = array(), $layer = null){
|
||||
|
||||
|
||||
ob_start();
|
||||
|
||||
|
||||
if (is_array($data))
|
||||
extract($data);
|
||||
if ($layer !== null){
|
||||
@@ -848,9 +849,9 @@ add_action('wpcf7_mail_sent', 'my_custom_mail_sent' );
|
||||
}
|
||||
else
|
||||
require $view;
|
||||
|
||||
|
||||
return trim(ob_get_clean());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -860,7 +861,7 @@ function get_expression_en( $str = false ) {
|
||||
|
||||
#cache result
|
||||
static $res = null;
|
||||
|
||||
|
||||
|
||||
if ($res !== null) {
|
||||
return $res;
|
||||
@@ -878,13 +879,13 @@ function get_expression_en( $str = false ) {
|
||||
|
||||
// Добавляем ID родительской рубрики в начало массива подрубрик
|
||||
array_unshift($subcategories, $parent_cat_id);
|
||||
|
||||
|
||||
$res = $subcategories;
|
||||
|
||||
return $res;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -893,7 +894,7 @@ function get_expression_parts() {
|
||||
|
||||
#cache result
|
||||
static $res = null;
|
||||
|
||||
|
||||
|
||||
if ($res !== null) {
|
||||
return $res;
|
||||
@@ -901,7 +902,7 @@ function get_expression_parts() {
|
||||
|
||||
$subcategories_en = get_expression_en();
|
||||
$additional_excludes = [ '17', '20', '21', $parent_cat_id ];
|
||||
|
||||
|
||||
|
||||
$all_excludes = array_merge( $additional_excludes, $subcategories_en );
|
||||
$res = implode(',', $all_excludes);
|
||||
@@ -913,14 +914,14 @@ function get_expression_parts() {
|
||||
|
||||
|
||||
function get_priority_category_en($post_id = null) {
|
||||
|
||||
|
||||
if ($post_id === null) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
|
||||
|
||||
// Получаем массив категорий поста
|
||||
$categories = get_the_category($post_id);
|
||||
|
||||
|
||||
if (empty($categories)) {
|
||||
return null;
|
||||
}
|
||||
@@ -946,8 +947,8 @@ function get_priority_category_en($post_id = null) {
|
||||
|
||||
// рубрики английской версии
|
||||
function use_custom_template_for_en_subcategories($template) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (is_category()) {
|
||||
$category = get_queried_object();
|
||||
|
||||
@@ -956,7 +957,7 @@ function use_custom_template_for_en_subcategories($template) {
|
||||
if ($new_template) {
|
||||
return $new_template;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Проверяем, является ли текущая категория подрубрикой "EN"
|
||||
$parent_id = $category->parent;
|
||||
@@ -1002,11 +1003,11 @@ add_filter('template_include', 'use_custom_template_for_en_subcategories');
|
||||
'child_of' => $parent_category_id,
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
|
||||
// Массив ID всех подрубрик 740
|
||||
$subcategory_ids = wp_list_pluck($subcategories, 'term_id');
|
||||
$all_category_ids = array_merge(array($parent_category_id), $subcategory_ids);
|
||||
|
||||
|
||||
// Запрос для получения постов, которые имеют рубрику 740 или любую из ее подрубрик
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
@@ -1053,7 +1054,7 @@ add_filter('template_include', 'use_custom_template_for_en_subcategories');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
function add_custom_admin_menu() {
|
||||
add_menu_page(
|
||||
'Update Posts Categories', // Заголовок страницы
|
||||
@@ -1099,5 +1100,17 @@ function update_categories_callback() {
|
||||
<?php
|
||||
}
|
||||
|
||||
//скрываем рекламный аккаунт
|
||||
function change_author_name($author) {
|
||||
$original_author = 'Анна Купровская'; //рекламный аккаунт
|
||||
$new_author = 'agroexpert.press';
|
||||
|
||||
if ($author === $original_author) {
|
||||
echo $author;
|
||||
return $new_author;
|
||||
}
|
||||
|
||||
return $author;
|
||||
}
|
||||
add_filter('the_author', 'change_author_name');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user