Helper->get_setting( 'enable_review' );
if ( empty( $enable_review ) ) {
return; // Don't display reviews if review system is disabled
}
// Check if current post is one of our dynamic post types
$dynamic_post_types = adqs_get_directory_post_types();
$is_dynamic_post_type = false;
foreach ( $dynamic_post_types as $post_type ) {
if ( is_singular( $post_type ) ) {
$is_dynamic_post_type = true;
break;
}
}
if ( ! $is_dynamic_post_type ) {
return;
}
/*
Write Review */
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || adqs_get_parent_reviews_count( get_the_ID() ) ) {
comments_template();
}
}
/**
* Output single listing Related Listing.
*/
function adqs_single_listing_related() {
global $post;
$post_id = ! empty( $post->ID ) ? $post->ID : 0;
$post_type = get_post_type( $post_id );
$directory_type = adqs_get_directory_id_by_post_type( $post_type );
$category = '';
$location = '';
$tags = '';
// Get dynamic taxonomies for this post type
$category_taxonomy = adqs_get_taxonomy_for_post_type( $post_type, 'categories' );
$location_taxonomy = adqs_get_taxonomy_for_post_type( $post_type, 'locations' );
$tags_taxonomy = adqs_get_taxonomy_for_post_type( $post_type, 'tags' );
// 1) Try categories
if ( ! empty( $category_taxonomy ) && taxonomy_exists( $category_taxonomy ) ) {
$category_terms = get_the_terms( $post_id, $category_taxonomy );
if ( ! empty( $category_terms ) && ! is_wp_error( $category_terms ) ) {
$category = join( ',', wp_list_pluck( $category_terms, 'slug' ) );
}
}
// 2) If no categories, try locations
if ( empty( $category ) && ! empty( $location_taxonomy ) && taxonomy_exists( $location_taxonomy ) ) {
$location_terms = get_the_terms( $post_id, $location_taxonomy );
if ( ! empty( $location_terms ) && ! is_wp_error( $location_terms ) ) {
$location = join( ',', wp_list_pluck( $location_terms, 'slug' ) );
}
}
// 3) If neither categories nor locations, try tags
if ( empty( $category ) && empty( $location ) && ! empty( $tags_taxonomy ) && taxonomy_exists( $tags_taxonomy ) ) {
$tags_terms = get_the_terms( $post_id, $tags_taxonomy );
if ( ! empty( $tags_terms ) && ! is_wp_error( $tags_terms ) ) {
$tags = join( ',', wp_list_pluck( $tags_terms, 'slug' ) );
}
}
$per_page = adqs_get_setting_option( 'related_listing_per_page' );
if ( empty( $per_page ) ) {
return;
}
$enable_carousel = adqs_get_setting_option( 'enable_related_listing_carousel' );
$pagination_type = ! empty( $enable_carousel ) ? 'carousel' : 'pagination';
$view_type = adqs_get_setting_option( 'related_listing_view_type' );
echo '
';
}
/**
* Listing meta fields.
*/
function adqs_single_listing_fileds_elements() {
global $post;
$post_id = ! empty( $post->ID ) ? $post->ID : 0;
$Helper = AD()->Helper;
$fields_data = adqs_single_page_fields_render( $post->ID );
$dir = 'single-listing/fields-elements';
if ( ! empty( $fields_data ) ) :
foreach ( $fields_data as $indx => $section ) :
$sectiontitle = $section['sectiontitle'] ?? '';
$sectionId = isset( $section['id'] ) ? $section['id'] : '';
$section_index = $indx + 1;
?>
0 ) {
$user_name = '';
$user_email = '';
$user = get_user_by( 'ID', $user_id );
if ( $user ) {
// Retrieve the user's email and username
$user_email = $user->user_email;
$user_name = $user->user_login;
}
$user = new EmailSender();
$user->send_mail(
'new_user_reg',
'admin',
[
'user_email' => $user_email,
'user_name' => $user_name,
]
);
}
}
function adqs_mail_to_user( $user_id, $reset_link = '' ) {
if ( $user_id > 0 ) {
$user_name = '';
$user = get_user_by( 'ID', $user_id );
if ( $user ) {
// Retrieve the user's email and username
$user_name = $user->user_login;
$user_email = $user->user_email;
}
$user = new EmailSender();
$user->send_mail(
'new_user_reg',
'user',
[
'user_email' => $user_email,
'user_name' => $user_name,
'reset_url' => $reset_link,
]
);
}
}
function get_author_info_by_id( $post_id, $column ) {
// Get the email of the author
$author_id = get_post_field( 'post_author', $post_id );
// Get the email of the author
$author_column = get_the_author_meta( $column, $author_id );
return $author_column;
}
function adqs_new_listing_mail_admin( $list_id ) {
$title = get_the_title( $list_id );
$submitted_by = get_author_info_by_id( $list_id, 'user_login' );
$user_email = get_author_info_by_id( $list_id, 'user_email' );
$user = new EmailSender();
$user->send_mail(
'new_listing_sub',
'admin',
[
'title' => $title,
'submitted_by' => $submitted_by,
'user_email' => $user_email,
]
);
}
function adqs_new_listing_mail_user( $list_id ) {
$title = get_the_title( $list_id );
$submitted_by = get_author_info_by_id( $list_id, 'user_login' );
$user_email = get_author_info_by_id( $list_id, 'user_email' );
$user = new EmailSender();
$user->send_mail(
'new_listing_sub',
'user',
[
'title' => $title,
'submitted_by' => $submitted_by,
'user_email' => $user_email,
]
);
}
function adqs_new_user_account( $reset_link, $message, $guest_email ) {
$user = new EmailSender();
$user->send_mail(
'new_user_account',
'user',
[
'reset_link' => $reset_link,
'message' => $message,
'guest_email' => $guest_email,
]
);
}
function adqs_updated_listing_mail( $post_ID, $post_after, $post_before ) {
// Check if post type is one of our dynamic post types
$dynamic_post_types = adqs_get_directory_post_types();
if ( ! in_array( get_post_type( $post_ID ), $dynamic_post_types ) ) {
return;
}
// Allow notifications for Never Expire transitions (no suppression)
$title = get_the_title( $post_ID );
$user_name = get_author_info_by_id( $post_ID, 'user_login' );
$user = new EmailSender();
if ( $post_after->post_status === 'publish' && $post_before->post_status !== 'publish' ) {
$user_email = get_author_info_by_id( $post_ID, 'user_email' );
$user->send_mail(
'listing_is_approved',
'user',
[
'title' => $title,
'user_name' => $user_name,
'user_email' => $user_email,
]
);
}
$updated_by = get_post_meta( $post_ID, '_edit_last', true );
$updated_by_email = get_the_author_meta( 'user_email', $updated_by, );
$user->send_mail(
'new_listing_up',
'admin',
[
'title' => $title,
'updated_by' => $updated_by_email,
]
);
}
function adqs_post_status_change_mail( $new_status, $old_status, $post ) {
// Check if post type is one of our dynamic post types
$dynamic_post_types = adqs_get_directory_post_types();
if ( ! in_array( get_post_type( $post->ID ), $dynamic_post_types ) ) {
return;
}
// Allow notifications for Never Expire transitions (no suppression)
if ( $new_status === 'publish' && $old_status !== 'publish' ) {
$title = get_the_title( $post->ID );
$user_name = get_author_info_by_id( $post->ID, 'user_login' );
$user = new EmailSender();
$user_email = get_author_info_by_id( $post->ID, 'user_email' );
$user->send_mail(
'listing_is_approved',
'user',
[
'title' => $title,
'user_name' => $user_name,
'user_email' => $user_email,
]
);
}
}
function adqs_wc_order_mail_admin( $id, $post_obj ) {
// Check if post type is one of our dynamic post types
$dynamic_post_types = adqs_get_directory_post_types();
if ( ! in_array( get_post_type( $post->ID ?? 0 ), $dynamic_post_types ) ) {
return;
}
if ( ( $new_status ?? '' ) === 'publish' && ( $old_status ?? '' ) !== 'publish' ) {
$title = get_the_title( $post->ID ?? '' );
$user_name = get_author_info_by_id( $post->ID ?? 0, 'user_login' );
$user = new EmailSender();
$user_email = get_author_info_by_id( $post->ID ?? 0, 'user_email' );
$user->send_mail(
'listing_is_approved',
'user',
[
'title' => $title,
'user_name' => $user_name,
'user_email' => $user_email,
]
);
}
}
function adqs_wc_order_mail_user( $id, $post_obj ) {
// Check if post type is one of our dynamic post types
$dynamic_post_types = adqs_get_directory_post_types();
if ( ! in_array( get_post_type( $post->ID ?? 0 ), $dynamic_post_types ) ) {
return;
}
if ( ( $new_status ?? '' ) === 'publish' && ( $old_status ?? '' ) !== 'publish' ) {
$title = get_the_title( $post->ID ?? 0 );
$user_name = get_author_info_by_id( $post->ID ?? 0, 'user_login' );
$user = new EmailSender();
$user_email = get_author_info_by_id( $post->ID ?? 0, 'user_email' );
$user->send_mail(
'listing_is_approved',
'user',
[
'title' => $title,
'user_name' => $user_name,
'user_email' => $user_email,
]
);
}
}
/**
* Send expiry warning email for packages or individual listings
*
* @param string $getdata Expiry date or data
* @param int $customerid Customer/User ID (0 for guest)
* @param string|int $order_id Order ID or listing URL
* @param string|null $guest_email Guest email (if applicable)
*/
function adqs_send_mail_user_expiry_package( $getdata, $customerid, $order_id, $guest_email = null ) {
$email_sender = new EmailSender();
// Handle guest users
if ( $customerid === 0 && ! empty( $guest_email ) ) {
$email_sender->send_mail(
'listing_about_expire',
'user',
[
'user_email' => $guest_email,
'user_name' => 'Guest User',
'expiry_date' => $getdata,
'order_id' => $order_id,
]
);
return;
}
// Handle logged-in users
$user = get_userdata( $customerid );
if ( $user ) {
$user_email = $user->user_email;
$user_name = $user->display_name ? $user->display_name : $user->user_login;
$email_sender->send_mail(
'listing_about_expire',
'user',
[
'user_email' => $user_email,
'user_name' => $user_name,
'expiry_date' => $getdata,
'order_id' => $order_id,
]
);
}
}
/**
* Send expired email when listing actually expires
*
* @param int $post_id The post ID that expired
* @param string $expiry_date The expiry date
*/
function adqs_send_listing_expired_email( $post_id, $expiry_date ) {
// Check if email trigger is enabled
$user_triggers = adqs_get_setting_option( 'adqs_user_emails_triggers' );
if ( empty( $user_triggers ) || ! is_array( $user_triggers ) || ! in_array( 'listing_expired', $user_triggers ) ) {
return;
}
$email_sender = new EmailSender();
// Get listing details
$post = get_post( $post_id );
if ( ! $post ) {
return;
}
$listing_title = get_the_title( $post_id );
$listing_url = get_permalink( $post_id );
// Check if guest listing
$is_guest_listing = get_post_meta( $post_id, '_is_guest_listing', true );
if ( $is_guest_listing === 'yes' ) {
// For guest listings
$guest_email = get_post_meta( $post_id, '_guest_email', true );
if ( ! empty( $guest_email ) ) {
$email_sender->send_mail(
'listing_expired',
'user',
[
'user_email' => $guest_email,
'user_name' => 'Guest User',
'listing_title' => $listing_title,
'expiry_date' => $expiry_date,
'listing_url' => $listing_url,
]
);
}
} else {
// For logged-in users
$author_id = $post->post_author;
$user = get_userdata( $author_id );
if ( $user ) {
$email_sender->send_mail(
'listing_expired',
'user',
[
'user_email' => $user->user_email,
'user_name' => $user->display_name ? $user->display_name : $user->user_login,
'listing_title' => $listing_title,
'expiry_date' => $expiry_date,
'listing_url' => $listing_url,
]
);
}
}
}
add_action( 'adqs_listing_expired', 'adqs_send_listing_expired_email', 10, 2 );
function adqs_order_change_status_mail_to_user( $order_id, $customer_id, $order_url = '', $status = '' ) {
$customer_data = get_userdata( $customer_id );
if ( ! $customer_data ) {
return;
}
$customer_name = $customer_data->user_login;
$user_email = $customer_data->user_email;
$email_sender = new EmailSender();
$email_data = [
'order_id' => $order_id,
'customer_name' => $customer_name,
'user_email' => $user_email,
'order_url' => $order_url,
'customer_id' => $customer_id,
];
$email_sender->send_mail( "order_{$status}", 'user', $email_data );
}
function adqs_order_created_mail_to_both( $order_id, $customer_id, $order_url = '' ) {
$customer_data = get_userdata( $customer_id );
if ( ! $customer_data ) {
return;
}
$customer_name = $customer_data->user_login;
$user_email = $customer_data->user_email;
$email_sender = new EmailSender();
$email_data = [
'order_id' => $order_id,
'customer_name' => $customer_name,
'user_email' => $user_email,
'order_url' => $order_url,
'customer_id' => $customer_id,
];
$email_sender->send_mail( 'order_created', 'admin', $email_data );
$email_sender->send_mail( 'order_created', 'user', $email_data );
}
/**
* Sends order completion emails to both admin and user.
*
* @param int $order_id The ID of the completed order.
* @param int $customer_id The ID of the customer who completed the order.
* @param string $order_url Optional. The URL of the order (default empty).
*/
function adqs_order_completed_mail_to_both( $order_id, $customer_id, $order_url = '' ) {
// Retrieve customer data using get_userdata
$customer_data = get_userdata( $customer_id );
// Ensure the customer exists
if ( ! $customer_data ) {
return;
}
$customer_name = $customer_data->user_login;
$user_email = $customer_data->user_email;
// Initialize the EmailSender object
$email_sender = new EmailSender();
// Prepare common email data
$email_data = [
'order_id' => $order_id,
'customer_name' => $customer_name,
'user_email' => $user_email,
'order_url' => $order_url,
];
// Send email to admin
$email_sender->send_mail( 'order_completed', 'admin', $email_data );
// Send email to user
$email_sender->send_mail( 'order_completed', 'user', $email_data );
}
function adqs_doc_submit_mail_to_admin( $user_id ) {
$user = get_userdata( $user_id );
if ( $user ) {
$user_email = $user->user_email;
$user_name = $user->user_login;
$email_sender = new EmailSender();
$email_sender->send_mail( 'document_submitted', 'admin', [ 'user_name' => $user_name ] );
}
}
function adqs_doc_verify_mail_to_user( $user_id ) {
$user = get_userdata( $user_id );
if ( $user ) {
$user_email = $user->user_email;
$user_name = $user->user_login;
$email_sender = new EmailSender();
$email_sender->send_mail(
'document_verified',
'user',
[
'user_name' => $user_name,
'user_email' => $user_email,
]
);
}
}
function adqs_doc_reject_mail_to_user( $user_id ) {
$user = get_userdata( $user_id );
if ( $user ) {
$user_email = $user->user_email;
$user_name = $user->user_login;
$email_sender = new EmailSender();
$email_sender->send_mail(
'document_rejected',
'user',
[
'user_name' => $user_name,
'user_email' => $user_email,
]
);
}
}
/**
* Display listing status badges (Expired, Pending, Draft, etc.)
* Shows badges based on post_status
*
* @param int $post_id Post ID
* @return void
*/
function adqs_show_listing_status_badges( $post_id ) {
if ( empty( $post_id ) ) {
return;
}
$post_status = get_post_status( $post_id );
// Display Expired badge
if ( 'expired' === $post_status ) {
echo '' . esc_html__( 'Expired', 'adirectory' ) . '';
}
// Display Pending badge
if ( 'pending' === $post_status ) {
echo '' . esc_html__( 'Pending', 'adirectory' ) . '';
}
// Display Draft badge
if ( 'draft' === $post_status ) {
echo '' . esc_html__( 'Draft', 'adirectory' ) . '';
}
}
add_action( 'template_redirect', 'adqs_before_frontend_add_listing' );
function adqs_before_frontend_add_listing() {
$post_id = isset( $_GET['postid'] ) ? absint( $_GET['postid'] ) : 0;
if ( ! $post_id || current_user_can( 'manage_options' ) ) {
return;
}
$author_id = get_post_field( 'post_author', $post_id );
// Redirect if expired (non-admin) OR current user not author
if ( $author_id != get_current_user_id() ) {
wp_redirect( esc_url( adqs_get_permalink_by_key( 'adqs_user_dashboard' ) ) );
exit;
}
}
/**
* Remove protocol from URL
*
* @param string $value The URL value
* @param int $post_id The post ID
* @param string $meta_key The meta key
* @return string The URL value
*/
function adqs_remove_display_listing_url_protocol( $value, $post_id, $meta_key ) {
if ( empty( $value ) || is_admin() || ! empty( $_GET['adqs_listing_type'] ) || ! empty( $_GET['postid'] ) ) {
return $value;
}
if ( ( '_website' === $meta_key ) || ( strpos( $meta_key, '_url_' ) !== false ) ) {
return adqs_remove_http_protocol_from_url( $value );
}
return $value;
}