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