add block-cache-manager.php
This commit is contained in:
122
functions.php
122
functions.php
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
//ini_set('display_errors', 1);
|
||||
//error_reporting(E_ERROR);
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ERROR);
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
require "clear-functions.php";
|
||||
require get_theme_file_path('clear-functions.php');
|
||||
require "dirty-functions.php";
|
||||
require "garbage-functions.php";
|
||||
require "block-cache-manager.php"; //кешируем долгоживущие блоки
|
||||
include "inc/get_cached_alm.php";
|
||||
|
||||
//TODO: Убрать все эти is_yn, is_zen и прочее и внутри плагинов регулировать вывод
|
||||
@@ -27,11 +28,16 @@ define( 'AUTOMATIC_UPDATER_DISABLED', true );
|
||||
// Отключаем только обновления ядра
|
||||
define( 'WP_AUTO_UPDATE_CORE', false );
|
||||
|
||||
//кеш блоков
|
||||
define('CACHED_TEMPLATE', trailingslashit( wp_upload_dir()['basedir'] ) . 'cached_template/');
|
||||
|
||||
// Отключаем обновления плагинов и тем
|
||||
add_filter( 'auto_update_plugin', '__return_false' );
|
||||
add_filter( 'auto_update_theme', '__return_false' );
|
||||
|
||||
|
||||
|
||||
|
||||
//debug
|
||||
|
||||
/**
|
||||
@@ -600,7 +606,26 @@ add_filter("the_content", function($content){
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Исправляет битые ссылки с одним слэшем после https:/ и добавляет домен.
|
||||
*
|
||||
* @param string $url Битая ссылка.
|
||||
* @param string $domain Домен (без слэша в конце, например "example.com").
|
||||
* @return string Исправленная ссылка.
|
||||
*/
|
||||
function fix_broken_url($url, $domain) {
|
||||
// Удаляем лишние пробелы
|
||||
$url = trim($url);
|
||||
|
||||
// Если ссылка начинается с https:/ и нет второго слэша — исправляем
|
||||
if (preg_match('#^https:/([^/].*)#i', $url, $matches)) {
|
||||
// Добавляем правильный https:// и домен
|
||||
return 'https://' . $domain . '/' . ltrim($matches[1], '/');
|
||||
}
|
||||
|
||||
// Если ссылка уже правильная, возвращаем как есть
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -998,7 +1023,27 @@ add_action('admin_enqueue_scripts', 'admin_style');
|
||||
add_action('wp_enqueue_scripts', 'admin_style');
|
||||
|
||||
|
||||
//дополнительные стили и скрипты
|
||||
add_action('wp_enqueue_scripts', function() {
|
||||
|
||||
wp_enqueue_script( //добавляем корректор времени
|
||||
'moscow-date',
|
||||
get_template_directory_uri() . '/assets/js/moscow-date.js',
|
||||
array(), // зависимости
|
||||
filemtime(get_template_directory() . '/assets/js/moscow-date.js'), // версия
|
||||
true // в футере
|
||||
);
|
||||
|
||||
// Добавляем стиль
|
||||
wp_enqueue_style(
|
||||
'profile-style', // уникальный идентификатор
|
||||
get_template_directory_uri() . '/assets/css/profile-style.css', // путь к файлу
|
||||
array(), // зависимости
|
||||
filemtime(get_template_directory() . '/assets/css/profile-style.css') // версия
|
||||
);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -2069,8 +2114,8 @@ function custom_field_html($field){
|
||||
<input
|
||||
type="checkbox"
|
||||
value="'.$field['value'].'"
|
||||
name="' . $field['id'] . ' "
|
||||
' . checked((bool)$value, true) . '
|
||||
name="' . $field['id'] . '"
|
||||
' . checked((bool)$value, true, false) . '
|
||||
/>
|
||||
' . _e($field['label']);
|
||||
break;
|
||||
@@ -2263,6 +2308,30 @@ remove_action( 'wp_head', 'feed_links', 2 );
|
||||
remove_action( 'wp_head', 'rsd_link' );
|
||||
|
||||
|
||||
//делаем opengraph для постов без фото
|
||||
add_action('wp_head', function() {
|
||||
|
||||
if (!is_singular()) return;
|
||||
|
||||
$post_id = get_the_ID();
|
||||
$default_image = 'https://cdn.profile.ru/wp-content/uploads/2023/07/profile_lazyload_hq.jpg'; // Заглушка в папке темы
|
||||
|
||||
$og_image = esc_url($default_image);
|
||||
|
||||
if (!has_post_thumbnail($post_id) or !show_thumbnail($post_id)) {
|
||||
|
||||
echo '<meta property="og:image" content="' . $og_image . '" />' . "\n";
|
||||
echo '<meta property="og:image:width" content="1200" />' . "\n";
|
||||
echo '<meta property="og:image:height" content="630" />' . "\n";
|
||||
echo '<meta name="twitter:image" content="' . $og_image . '" />';
|
||||
|
||||
//} else {
|
||||
// $og_image = get_the_post_thumbnail_url($post_id, 'large');
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
//Добавили к ссылкам nofollow
|
||||
@@ -2962,11 +3031,21 @@ function send_telegram($post) {
|
||||
$bot_id = "1108783670:AAGm7_vdXQAte25OGUa5gWJNXhy5-v6d_hU";
|
||||
$post_id = (is_object($post_id)) ? $post_id->ID : $post_id;
|
||||
|
||||
// Получаем и проверяем ссылку
|
||||
$curr_url = get_permalink($post_id);
|
||||
if (empty($curr_url)) {
|
||||
error_log('Telegram bot: Empty permalink for post ID ' . $post_id);
|
||||
return;
|
||||
}
|
||||
|
||||
$curr_url = fix_broken_url($curr_url, 'profile.ru'); //корректируем ссылку с ошиюбками
|
||||
|
||||
|
||||
if(has_tag(103565, $post_id)){
|
||||
$chat_id = "-1001241573514";//идентификатор канала profile_lifestyle
|
||||
|
||||
$text = '<a href="' . get_the_permalink($post_id) . '?utm_from=telegram">' . get_the_title($post_id) . '</a>';
|
||||
|
||||
$text = '<a href="' . $curr_url . '?utm_from=telegram">' . get_the_title($post_id) . '</a>';
|
||||
$text = str_replace('admin.', '', $text);
|
||||
$request = "https://api.telegram.org/bot" . $bot_id . "/sendMessage?chat_id=" . $chat_id . "&parse_mode=HTML&text=" . urlencode($text);
|
||||
|
||||
@@ -2976,6 +3055,8 @@ function send_telegram($post) {
|
||||
curl_setopt($ch, CURLOPT_URL, $request);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
|
||||
|
||||
}else{
|
||||
if(
|
||||
(((bool)filter_input(INPUT_POST,'_send_telegram'))
|
||||
@@ -2985,7 +3066,7 @@ function send_telegram($post) {
|
||||
|
||||
$chat_id = "-1001365682276";//идентификатор канала profile_news
|
||||
|
||||
$text = '<a href="'.get_the_permalink($post_id).'?utm_from=telegram">'.get_the_title($post_id).'</a>';
|
||||
$text = '<a href="'.$curr_url.'?utm_from=telegram">'.get_the_title($post_id).'</a>';
|
||||
$text = str_replace('admin.', '', $text);
|
||||
$request = "https://api.telegram.org/bot".$bot_id."/sendMessage?chat_id=".$chat_id."&parse_mode=HTML&text=".urlencode($text);
|
||||
|
||||
@@ -6129,8 +6210,17 @@ add_filter( 'ep_post_sync_kill', 'my_ep_stop_sync', 10, 3 );*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
add_action('wp_insert_post', 'news_telegram_log', 10, 1 );
|
||||
|
||||
//хук для запланированных
|
||||
add_action('transition_post_status', function($new_status, $old_status, $post) {
|
||||
if ($new_status == 'publish' && $old_status == 'future') {
|
||||
news_telegram_log($post);
|
||||
}
|
||||
}, 10, 3);
|
||||
|
||||
function news_telegram_log($post){
|
||||
|
||||
$post = get_post($post);
|
||||
@@ -6147,15 +6237,20 @@ function news_telegram_log($post){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(wp_get_post_categories($post_id)[0] == 104862){
|
||||
return;
|
||||
}
|
||||
|
||||
// Получаем и проверяем ссылку
|
||||
$curr_link = get_permalink($post_id);
|
||||
if (empty($curr_link)) {
|
||||
error_log('Telegram bot: Empty permalink for post ID ' . $post_id);
|
||||
return;
|
||||
}
|
||||
|
||||
$curr_link = fix_broken_url($curr_link, 'profile.ru'); //корректируем ссылку с ошиюбками
|
||||
|
||||
$content = '<a href="'.get_the_permalink($post_id).'?utm_from=telegram">'.get_the_title($post_id).'</a>';
|
||||
$content = '<a href="'.$curr_link.'?utm_from=telegram">'.get_the_title($post_id).'</a>';
|
||||
$content = str_replace('admin.', '', $content);
|
||||
$request = "https://api.telegram.org/bot1184440628:AAE5N10dnzClx3Qce4v1mBD9ax1BsHo98Rs/sendMessage?chat_id=-1001588455134&parse_mode=HTML&text=".urlencode($content);
|
||||
|
||||
@@ -6207,6 +6302,13 @@ function show_thumbnail($id = false) : bool
|
||||
$id = get_the_ID();
|
||||
}
|
||||
|
||||
// НОВОЕ УСЛОВИЕ: Амнистия для постов, опубликованных после 1 августа 2025 года
|
||||
$amnestyDate = strtotime('2025-08-01');
|
||||
|
||||
if (get_the_date("U", $id) > $amnestyDate) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$days = ((get_post_meta($id,'_hide_thumbnail_countdown'))[0]);
|
||||
|
||||
if ( $days == NULL ){
|
||||
|
||||
Reference in New Issue
Block a user