correct pinned post and add mail config

This commit is contained in:
argoexpert press
2024-04-12 21:14:24 +03:00
parent 6ab7d934a9
commit ce406b9c32
3 changed files with 90 additions and 29 deletions

View File

@@ -601,6 +601,94 @@ function custom_meta_tags() {
}
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
global $wpdb;
// Определяем таблицу в базе данных WordPress в зависимости от ID формы
$table_name = $wpdb->prefix . 'subusers';
$wpdb->insert(
$table_name,
array(
'mail' => $posted_data['your-email'],
'status' => 0,
'date' => current_time('mysql')
),
array(
'%s', // Формат для строкового поля
'%d', // Формат для цифрового поля
'%s' // Формат для поля с датой и временем
)
);
}
}
}
function last_sticky_post() {
//$pinned_post = get_field('pinned_post', 'options');
static $last = null; // array to pinned 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') {
//$published_sticky_posts[] = $post_id;
$last = $post;
break; // Выходим из цикла, так как нашли последний опубликованный закрепленный пост
}
}
return $last;
}
add_action( 'phpmailer_init', 'agroxpert_send_smtp_email' );
function agroxpert_send_smtp_email( PHPMailer $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'mail.vetandlife.ru';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 465;
$phpmailer->Username = 'news@mail.agroexpert.press';
$phpmailer->Password = 'O6K!]aZDNJ';
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->From = 'news@mail.agroexpert.press';
$phpmailer->FromName = 'Ветеринария и жизнь';
}
add_action('wpcf7_mail_sent', 'my_custom_mail_sent' );
@@ -669,17 +757,4 @@ $hash_link.\n\n
}
function agroxpert_send_smtp_email( PHPMailer $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'mail.vetandlife.ru';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 465;
$phpmailer->Username = 'news@mail.agroexpert.press';
$phpmailer->Password = 'O6K!]aZDNJ';
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->From = 'news@mail.agroexpert.press';
$phpmailer->FromName = 'Ветеринария и жизнь';
}
add_action( 'phpmailer_init', 'agroxpert_send_smtp_email' );

View File

@@ -1,12 +1,6 @@
<?php
$sticky_posts = get_option('sticky_posts');
// Получаем последний идентификатор прилепленного поста
$last_sticky_post_id = end($sticky_posts);
// Получаем объект поста по его идентификатору
$pinned_post = get_post($last_sticky_post_id);
$pinned_post = last_sticky_post();
if ($pinned_post):
$mainpost_id = $pinned_post->ID;

View File

@@ -1,14 +1,6 @@
<?php
// Получаем объект закрепленного поста из ACF поля 'pinned_post'
//$pinned_post = get_field('pinned_post', 'options');
$sticky_posts = get_option('sticky_posts');
// Получаем последний идентификатор прилепленного поста
$last_sticky_post_id = end($sticky_posts);
// Получаем объект поста по его идентификатору
$pinned_post = get_post($last_sticky_post_id);
$pinned_post = last_sticky_post();
if ($pinned_post) :