Opal-Estate-Pro/inc/message/functions.php

80 lines
2.5 KiB
PHP
Raw Normal View History

2020-05-28 09:33:18 +02:00
<?php
function opalestate_get_message_by_user( $args = [] ) {
return [
'items' => OpalEstate_User_Message::get_instance()->get_list( $args ),
'total' => OpalEstate_User_Message::get_instance()->get_total( $args ),
];
}
function opalestate_get_member_email_data( $post_id ) {
$type = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'author_type', true );
$receiver_id = 0;
switch ( $type ) {
case 'agent':
$agent_id = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'agent', true );
if ( ! $agent_id ) {
$post = get_post( $post_id );
$user = get_user_by( 'id', $post->post_author );
$email = $user->data->user_email;
$name = $user->data->display_name;
$receiver_id = $post->post_author;
} else {
$user_id = get_post_meta( $agent_id, OPALESTATE_AGENT_PREFIX . 'user_id', true );
if ( $user_id ) {
$post = get_post( $post_id );
$user = get_user_by( 'id', $user_id );
$email = $user->data->user_email;
$name = $user->data->display_name;
$receiver_id = $post->post_author;
} else {
$post = get_post( $agent_id );
$name = $post->post_title;
$email = get_post_meta( $agent_id, OPALESTATE_AGENT_PREFIX . 'email', true );
}
}
2019-09-10 06:27:33 +02:00
2020-05-28 09:33:18 +02:00
break;
case 'agency':
$agency_id = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'agency', true );
if ( ! $agency_id ) {
$post = get_post( $post_id );
$user = get_user_by( 'id', $post->post_author );
$email = $user->data->user_email;
$name = $user->data->display_name;
2019-09-10 06:27:33 +02:00
$receiver_id = $post->post_author;
2020-05-28 09:33:18 +02:00
} else {
$user_id = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'user_id', true );
if ( $user_id ) {
$post = get_post( $post_id );
$user = get_user_by( 'id', $user_id );
$email = $user->data->user_email;
$name = $user->data->display_name;
$receiver_id = $post->post_author;
} else {
$post = get_post( $agency_id );
$name = $post->post_title;
$email = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'email', true );
}
}
2019-09-10 06:27:33 +02:00
2020-05-28 09:33:18 +02:00
break;
default:
$post = get_post( $post_id );
$user = get_user_by( 'id', $post->post_author );
$email = $user->data->user_email;
$name = $user->data->display_name;
$receiver_id = $post->post_author;
break;
}
2019-09-10 06:27:33 +02:00
2020-05-28 09:33:18 +02:00
return [
'receiver_email' => $email,
'receiver_name' => $name,
'receiver_id' => $receiver_id,
];
}