// Хуки для Contact Form 7
add_action('wpcf7_before_send_mail', 'wpp_limit_cf7_submissions');
add_filter('wpcf7_display_message', 'wpp_block_cf7_form_display', 10, 2);
function wpp_limit_cf7_submissions($contact_form) {
$form_id = $contact_form->id();
$user_ip = $_SERVER['REMOTE_ADDR'];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
// Создаем уникальный ключ для пользователя
$user_key = md5($user_ip . $user_agent);
$option_key = 'cf7_submission_' . $form_id . '_' . $user_key;
// Проверяем, отправлял ли пользователь форму за последние 24 часа
$last_submission = get_option($option_key);
$current_time = time();
if ($last_submission && ($current_time - $last_submission) < 86400) { // 24 часа
// Блокируем отправку
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$submission->add_status('aborted', 'Вы уже отправляли заявку. Пожалуйста, подождите 24 часа.');
}
return false;
}
// Записываем время отправки
update_option($option_key, $current_time, false);
return $contact_form;
}
function wpp_block_cf7_form_display($message, $status) {
if ($status === 'aborted') {
return 'Вы уже отправляли заявку. Пожалуйста, подождите 24 часа перед повторной отправкой.';
}
return $message;
}
function wpp_make_tags_hierarchical() {
$tag_args = get_taxonomy('post_tag');
$tag_args->hierarchical = true;
$tag_args->rewrite['hierarchical'] = true;
}
add_action('init', 'wpp_make_tags_hierarchical', 999);
$categories = get_categories(array(
'orderby' => 'count',
'order' => 'DESC',
'hide_empty' => true
));
$counts = wp_list_pluck($categories, 'count');
$max_count = max($counts);
$min_count = min($counts);
$count_range = ($max_count - $min_count) ? ($max_count - $min_count) : 1;
$normalized = ($category->count - $min_count) / $count_range;
$font_size = 14 + round($normalized * 10, 2);
if (!is_admin() && !defined('DOING_AJAX')) {
add_filter('send_auth_cookies', '__return_false');
function disable_frontend_cookies() {
return;
}
add_action('set_logged_in_cookie', 'disable_frontend_cookies');
add_action('set_security_cookie', 'disable_frontend_cookies');
add_action('set_remember_me_cookie', 'disable_frontend_cookies');
}
if ( ! function_exists( 'wpp_image_placeholder' ) ) :
/**
* Изображение заполнитель
*/
function wpp_image_placeholder( $image = null, $return = 'array', $size = 'thumbinail' ) {
if ( ! empty( $image ) ) {
$uploads = wp_upload_dir();
$file_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $image[0] );
} else {
$image = [];
}
if ( empty( $file_path ) || ! file_exists( $file_path ) ) {
$placeholder_image = get_option( 'wpp_placeholder_image', 0 );
if ( empty( $placeholder_image ) ) {
$image[0] = WPP_CORE_URL . 'components/assets/img/placeholder.jpg';
} else {
$image_opt = wp_get_attachment_image_src( $placeholder_image );
if ( ! empty( $image_opt ) ) {
$image[0] = $image_opt[0];
}
}
}
$img = 'array' === $return ? $image : $image[0];
return apply_filters( 'wpp_placeholder_img', $img, $return );
}
endif;
add_filter( 'wp_get_attachment_image_src', 'wpp_image_placeholder', 10 );
<!-- это -->
<img src="<?php echo $image; ?>" alt="" />
<!-- заменить на это -->
<img src="<?php echo bfi_thumb( $image, [ 'width' => 400, 'height' => 300 ] ); ?>" alt="" />