Current path: home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin/Handlers/
?? Go up: /home/webdevt/www/cryptoimpot.fr/wp-content/plugins/divi-contact-form-helper/app/Admin
<?php
namespace KS_PAC_DCFH\Admin\Handlers;
class User_Handler
{
private static $_instance;
public static function instance(): self
{
if (self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}
public static function get_user_emails($post_id): array
{
$post_excerpt = get_post_field('post_excerpt', $post_id);
$post_author = get_post_field('post_author', $post_id);
$emails = [];
if (is_serialized($post_excerpt)) {
$pattern = '/[a-z0-9_\-+.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
preg_match_all($pattern, $post_excerpt, $matches);
if (isset($matches[0])) {
foreach ($matches[0] as $match) {
$emails[$match] = __('Entry Email ', 'divi-contact-form-helper').'<'.$match.'>';
}
}
}
if ($post_author > 0) {
$user_data = get_user_by('ID', $post_author);
if (isset($user_data->data->user_email)) {
$emails[$user_data->data->user_email] = __('Profile Email ', 'divi-contact-form-helper').'<'.$user_data->data->user_email.'>';
}
}
return $emails;
}
public static function get_post_user_email($post_id)
{
$post_excerpt = get_post_field('post_excerpt', $post_id);
$post_author = get_post_field('post_author', $post_id);
if ($post_author > 0) {
$user_data = get_user_by('ID', $post_author);
if (isset($user_data->data->user_email)) {
return $user_data->data->user_email;
}
}
if (is_serialized($post_excerpt)) {
// $pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
$pattern = '/[a-z0-9_\-+.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
preg_match_all($pattern, $post_excerpt, $matches);
if (isset($matches[0])) {
$email = reset($matches[0]);
if (is_email(esc_html($email))) {
return $email;
}
}
}
return '';
}
public static function is_user_email_exist($post_id): bool
{
$post_meta = ks_pac_dcfh_post_meta()::get_contact_email_meta_value($post_id);
$post_author = get_post_field('post_author', $post_id);
if (!empty($post_meta)) {
return true;
}
if ($post_author > 0) {
$user_data = get_user_by('ID', $post_author);
if (isset($user_data->data->user_email)) {
return true;
}
}
return false;
}
public static function is_user_other_entry_exist($post_id, $user_email): bool
{
global $wpdb;
$result = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*)
FROM $wpdb->postmeta
WHERE meta_key = %s
AND meta_value LIKE %s
AND post_id != %d",
'_pwh_dcfh_contact_email',
$user_email,
$post_id
)
); // db call ok; no-cache ok
return $result > 0 && !is_wp_error($result);
}
}