Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/build/js/admin/multi-directory-builder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/build/js/admin/settings-manager.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/js/admin-multi-directory-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10024,8 +10024,8 @@ var EVENT_TEMPLATE_MAP = {
body: "email_tmpl_listing_contact_email"
}
};
var ADMIN_EVENTS = [["order_created", "Order created", "A new order has been placed"], ["order_completed", "Order completed", "An order has been fulfilled"], ["payment_received", "Payment received", "A payment has been confirmed"], ["listing_submitted", "New listing submitted", "A listing is waiting for review"], ["listing_published", "Listing approved or published", "A listing has gone live"], ["listing_edited", "Listing edited", "A listing was updated by its owner"], ["listing_deleted", "Listing deleted", "A listing has been removed"], ["listing_renewed", "Listing renewed", "A listing plan has been renewed"], ["listing_contact_form", "Listing contact form", "A visitor messaged via a listing"], ["listing_review", "Listing review", "A new review has been posted"]];
var USER_EVENTS = [["listing_submitted", "Listing submitted", "Confirmation their listing was received"], ["listing_published", "Listing approved or published", "Their listing is now live"], ["listing_rejected", "Listing rejected", "Their listing was not approved"], ["listing_edited", "Listing edited", "Confirmation their edit was saved"], ["listing_deleted", "Listing deleted", "Their listing has been removed"], ["listing_to_expire", "Listing nearly expired", "Their listing expires soon"], ["listing_expired", "Listing expired", "Their listing plan has ended"], ["remind_to_renew", "Remind to renew", "Renewal reminder after expiry"], ["listing_renewed", "Listing renewed", "Confirmation their listing was renewed"], ["order_created", "Order created", "Confirmation their order was placed"], ["order_completed", "Order completed", "Their order has been fulfilled"], ["payment_received", "Payment received", "Confirmation of a successful payment"], ["listing_contact_form", "Listing contact form", "A visitor messaged via their listing"], ["listing_review", "Listing review", "Someone reviewed their listing"]];
var ADMIN_EVENTS = [["order_created", "Order created", "A new order has been placed"], ["order_completed", "Order completed", "An order has been fulfilled"], ["listing_submitted", "New listing submitted", "A listing is waiting for review"], ["listing_published", "Listing approved or published", "A listing has gone live"], ["listing_edited", "Listing edited", "A listing was updated by its owner"], ["listing_deleted", "Listing deleted", "A listing has been removed"], ["listing_renewed", "Listing renewed", "A listing plan has been renewed"], ["listing_contact_form", "Listing contact form", "A visitor messaged via a listing"], ["listing_review", "Listing review", "A new review has been posted"]];
var USER_EVENTS = [["listing_submitted", "Listing submitted", "Confirmation their listing was received"], ["listing_published", "Listing approved or published", "Their listing is now live"], ["listing_rejected", "Listing rejected", "Their listing was not approved"], ["listing_edited", "Listing edited", "Confirmation their edit was saved"], ["listing_deleted", "Listing deleted", "Their listing has been removed"], ["listing_to_expire", "Listing nearly expired", "Their listing expires soon"], ["listing_expired", "Listing expired", "Their listing plan has ended"], ["remind_to_renew", "Remind to renew", "Renewal reminder after expiry"], ["listing_renewed", "Listing renewed", "Confirmation their listing was renewed"], ["listing_contact_form", "Listing contact form", "A visitor messaged via their listing"], ["listing_review", "Listing review", "Someone reviewed their listing"]];
var ACCOUNT_EVENTS = [["registration_confirmation", "Registration confirmation", "Welcome email sent after a new account is created", {
subject: "email_sub_registration_confirmation",
body: "email_tmpl_registration_confirmation"
Expand Down
4 changes: 2 additions & 2 deletions assets/js/admin-settings-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12614,8 +12614,8 @@ var EVENT_TEMPLATE_MAP = {
body: "email_tmpl_listing_contact_email"
}
};
var ADMIN_EVENTS = [["order_created", "Order created", "A new order has been placed"], ["order_completed", "Order completed", "An order has been fulfilled"], ["payment_received", "Payment received", "A payment has been confirmed"], ["listing_submitted", "New listing submitted", "A listing is waiting for review"], ["listing_published", "Listing approved or published", "A listing has gone live"], ["listing_edited", "Listing edited", "A listing was updated by its owner"], ["listing_deleted", "Listing deleted", "A listing has been removed"], ["listing_renewed", "Listing renewed", "A listing plan has been renewed"], ["listing_contact_form", "Listing contact form", "A visitor messaged via a listing"], ["listing_review", "Listing review", "A new review has been posted"]];
var USER_EVENTS = [["listing_submitted", "Listing submitted", "Confirmation their listing was received"], ["listing_published", "Listing approved or published", "Their listing is now live"], ["listing_rejected", "Listing rejected", "Their listing was not approved"], ["listing_edited", "Listing edited", "Confirmation their edit was saved"], ["listing_deleted", "Listing deleted", "Their listing has been removed"], ["listing_to_expire", "Listing nearly expired", "Their listing expires soon"], ["listing_expired", "Listing expired", "Their listing plan has ended"], ["remind_to_renew", "Remind to renew", "Renewal reminder after expiry"], ["listing_renewed", "Listing renewed", "Confirmation their listing was renewed"], ["order_created", "Order created", "Confirmation their order was placed"], ["order_completed", "Order completed", "Their order has been fulfilled"], ["payment_received", "Payment received", "Confirmation of a successful payment"], ["listing_contact_form", "Listing contact form", "A visitor messaged via their listing"], ["listing_review", "Listing review", "Someone reviewed their listing"]];
var ADMIN_EVENTS = [["order_created", "Order created", "A new order has been placed"], ["order_completed", "Order completed", "An order has been fulfilled"], ["listing_submitted", "New listing submitted", "A listing is waiting for review"], ["listing_published", "Listing approved or published", "A listing has gone live"], ["listing_edited", "Listing edited", "A listing was updated by its owner"], ["listing_deleted", "Listing deleted", "A listing has been removed"], ["listing_renewed", "Listing renewed", "A listing plan has been renewed"], ["listing_contact_form", "Listing contact form", "A visitor messaged via a listing"], ["listing_review", "Listing review", "A new review has been posted"]];
var USER_EVENTS = [["listing_submitted", "Listing submitted", "Confirmation their listing was received"], ["listing_published", "Listing approved or published", "Their listing is now live"], ["listing_rejected", "Listing rejected", "Their listing was not approved"], ["listing_edited", "Listing edited", "Confirmation their edit was saved"], ["listing_deleted", "Listing deleted", "Their listing has been removed"], ["listing_to_expire", "Listing nearly expired", "Their listing expires soon"], ["listing_expired", "Listing expired", "Their listing plan has ended"], ["remind_to_renew", "Remind to renew", "Renewal reminder after expiry"], ["listing_renewed", "Listing renewed", "Confirmation their listing was renewed"], ["listing_contact_form", "Listing contact form", "A visitor messaged via their listing"], ["listing_review", "Listing review", "Someone reviewed their listing"]];
var ACCOUNT_EVENTS = [["registration_confirmation", "Registration confirmation", "Welcome email sent after a new account is created", {
subject: "email_sub_registration_confirmation",
body: "email_tmpl_registration_confirmation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
class="cptm-input-toggle"
:class="{ active: eventIsEnabled(event, 'email') }"
:aria-pressed="eventIsEnabled(event, 'email') ? 'true' : 'false'"
@click="toggleEvent(event.emailFieldKey, event.value)"
@click="toggleEmailEvent(event)"
></button>
<span v-else class="cptm-notification-events__unavailable">-</span>
</td>
Expand Down Expand Up @@ -317,7 +317,6 @@ const EVENT_TEMPLATE_MAP = {
const ADMIN_EVENTS = [
["order_created", "Order created", "A new order has been placed"],
["order_completed", "Order completed", "An order has been fulfilled"],
["payment_received", "Payment received", "A payment has been confirmed"],
["listing_submitted", "New listing submitted", "A listing is waiting for review"],
["listing_published", "Listing approved or published", "A listing has gone live"],
["listing_edited", "Listing edited", "A listing was updated by its owner"],
Expand All @@ -337,13 +336,12 @@ const USER_EVENTS = [
["listing_expired", "Listing expired", "Their listing plan has ended"],
["remind_to_renew", "Remind to renew", "Renewal reminder after expiry"],
["listing_renewed", "Listing renewed", "Confirmation their listing was renewed"],
["order_created", "Order created", "Confirmation their order was placed"],
["order_completed", "Order completed", "Their order has been fulfilled"],
["payment_received", "Payment received", "Confirmation of a successful payment"],
["listing_contact_form", "Listing contact form", "A visitor messaged via their listing"],
["listing_review", "Listing review", "Someone reviewed their listing"],
];

const ORDER_EMAIL_EVENTS = ["order_created", "order_completed"];

const ACCOUNT_EVENTS = [
[
"registration_confirmation",
Expand Down Expand Up @@ -826,6 +824,7 @@ export default {
buildChannelEvents(eventDefinitions, emailFieldKey, webPushFieldKey, recipient) {
const emailValues = this.optionValues(emailFieldKey);
const webPushValues = this.optionValues(webPushFieldKey);
const ownerEmailValues = this.optionValues("notify_user");
const availableValues = [...new Set([...emailValues, ...webPushValues])];

return eventDefinitions
Expand All @@ -838,6 +837,12 @@ export default {
key: `${emailFieldKey}-${value}`,
value,
emailFieldKey: hasEmail ? emailFieldKey : "",
secondaryEmailFieldKey:
emailFieldKey === "notify_admin" &&
ORDER_EMAIL_EVENTS.includes(value) &&
ownerEmailValues.includes(value)
? "notify_user"
: "",
webPushFieldKey: hasWebPush ? webPushFieldKey : "",
label,
description,
Expand Down Expand Up @@ -893,6 +898,10 @@ export default {
keys.push(event.emailFieldKey);
}

if (event.secondaryEmailFieldKey) {
keys.push(event.secondaryEmailFieldKey);
}

if (event.webPushFieldKey) {
keys.push(event.webPushFieldKey);
}
Expand Down Expand Up @@ -921,14 +930,21 @@ export default {
return false;
}

const fieldKey =
channel === "webPush" ? event.webPushFieldKey : event.emailFieldKey;
if (channel === "webPush") {
return event.webPushFieldKey
? this.valueForField(event.webPushFieldKey).includes(event.value)
: false;
}

if (!fieldKey) {
const fieldKeys = this.emailFieldKeysForEvent(event);

if (!fieldKeys.length) {
return false;
}

return this.valueForField(fieldKey).includes(event.value);
return fieldKeys.every((fieldKey) =>
this.valueForField(fieldKey).includes(event.value)
);
},

eventIsDisplayedEnabled(event, channel) {
Expand Down Expand Up @@ -973,6 +989,42 @@ export default {
});
},

emailFieldKeysForEvent(event) {
if (!event) {
return [];
}

return [...new Set([event.emailFieldKey, event.secondaryEmailFieldKey])]
.filter(Boolean);
},

toggleEmailEvent(event) {
const fieldKeys = this.emailFieldKeysForEvent(event);

if (!fieldKeys.length) {
return;
}

const shouldEnable = !this.eventIsEnabled(event, "email");

fieldKeys.forEach((fieldKey) => {
let nextValue = [...this.valueForField(fieldKey)];

if (shouldEnable) {
if (!nextValue.includes(event.value)) {
nextValue.push(event.value);
}
} else {
nextValue = nextValue.filter((item) => item !== event.value);
}

this.$emit("update-field", {
fieldKey,
value: nextValue,
});
});
},

toggleWebPushEvent(event) {
if (this.webPushSwitchIsDisabled(event)) {
return;
Expand Down
16 changes: 1 addition & 15 deletions includes/classes/class-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,6 @@ public function get_email_headers( $data = [] ) {
* @return bool Whether the message was sent successfully or not.
*/
public function notify_owner_order_created( $order_id, $listing_id, $offline = false ) {

$gateway = get_post_meta( $order_id, '_payment_gateway', true );

if ( 'bank_transfer' !== $gateway ) {
return false;
}

if ( get_directorist_option( 'disable_email_notification' ) ) {
return false;
}
Expand Down Expand Up @@ -1043,13 +1036,6 @@ public function notify_admin_become_author( $user_id ) {
* @return bool Whether the email was sent successfully or not.
*/
public function notify_admin_order_created( $order_id, $listing_id ) {

$gateway = get_post_meta( $order_id, '_payment_gateway', true );

if ( 'bank_transfer' !== $gateway ) {
return false;
}

/*@todo; think if it is better to assign disabled_email_notification to the class prop*/
if ( get_directorist_option( 'disable_email_notification' ) ) {
return false; // vail if email notification is off
Expand Down Expand Up @@ -1324,4 +1310,4 @@ public function send_user_confirmation_email( Wp_User $user ) {
return $this->send_mail( $user->user_email, $subject, $body, $this->get_email_headers() );
}
} // ends class
endif;
endif;
6 changes: 0 additions & 6 deletions includes/classes/class-settings-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5611,10 +5611,6 @@ private function default_notifiable_events() {
'value' => 'listing_edited',
'label' => __( 'Listing Edited', 'directorist' ),
],
[
'value' => 'payment_received',
'label' => __( 'Payment Received', 'directorist' ),
],
[
'value' => 'listing_deleted',
'label' => __( 'Listing Deleted', 'directorist' ),
Expand Down Expand Up @@ -5665,7 +5661,6 @@ public function default_events_to_notify_user() {
'atbdp_default_events_to_notify_user', [
'order_created',
'listing_submitted',
'payment_received',
'listing_published',
'listing_rejected',
'listing_to_expire',
Expand Down Expand Up @@ -5719,7 +5714,6 @@ public function default_events_to_notify_admin() {
'order_created',
'order_completed',
'listing_submitted',
'payment_received',
'listing_published',
'listing_deleted',
'listing_contact_form',
Expand Down
42 changes: 39 additions & 3 deletions includes/directorist-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,48 @@ function directorist_get_admin_notifiable_events() {
return (array) get_directorist_option( 'notify_admin', [] );
}

function directorist_is_order_notifiable_event( $event ) {
return in_array( $event, [ 'order_created', 'order_completed' ], true );
}

function directorist_is_owner_notifiable_event( $event ) {
return in_array( $event, directorist_get_owner_notifiable_events(), true );
$owner_events = directorist_get_owner_notifiable_events();

if (
in_array( $event, $owner_events, true )
|| ( 'order_completed' === $event && in_array( 'payment_received', $owner_events, true ) )
) {
return true;
}

if ( ! directorist_is_order_notifiable_event( $event ) ) {
return false;
}

$admin_events = directorist_get_admin_notifiable_events();

return in_array( $event, $admin_events, true )
|| ( 'order_completed' === $event && in_array( 'payment_received', $admin_events, true ) );
}

function directorist_is_admin_notifiable_event( $event ) {
return in_array( $event, directorist_get_admin_notifiable_events(), true );
$admin_events = directorist_get_admin_notifiable_events();

if (
in_array( $event, $admin_events, true )
|| ( 'order_completed' === $event && in_array( 'payment_received', $admin_events, true ) )
) {
return true;
}

if ( ! directorist_is_order_notifiable_event( $event ) ) {
return false;
}

$owner_events = directorist_get_owner_notifiable_events();

return in_array( $event, $owner_events, true )
|| ( 'order_completed' === $event && in_array( 'payment_received', $owner_events, true ) );
}

function directorist_get_user_types() {
Expand All @@ -62,4 +98,4 @@ function directorist_get_user_types() {
);

return apply_filters( 'directorist_get_user_types', $user_types );
}
}
31 changes: 31 additions & 0 deletions includes/model/ListingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ public function add_listing_category_custom_field_template( $field_data, $listin

$field_data['value'] = $value;
$field_data['form'] = $this;
$field_data = $this->apply_listing_type_field_defaults( $field_data );

$args = [
'listing_form' => $this,
Expand Down Expand Up @@ -856,6 +857,7 @@ public function field_template( $field_data ) {
$field_data['value'] = $value;
$field_data['form'] = $this;
$field_data = apply_filters( 'directorist_form_field_data', $field_data );
$field_data = $this->apply_listing_type_field_defaults( $field_data );

// Extract and prepare conditional logic data for frontend
// This ensures conditional_logic_data is available in templates
Expand Down Expand Up @@ -898,6 +900,35 @@ public function field_template( $field_data ) {
}
}

protected function apply_listing_type_field_defaults( array $field_data ): array {
if ( ! $this->is_listing_type_field( $field_data ) ) {
return $field_data;
}

if ( ! isset( $field_data['value'] ) ) {
$field_data['value'] = '';
}

if ( empty( $field_data['general_label'] ) ) {
$field_data['general_label'] = __( 'General', 'directorist' );
}

if ( empty( $field_data['featured_label'] ) ) {
$field_data['featured_label'] = __( 'Featured', 'directorist' );
}

return $field_data;
}

protected function is_listing_type_field( array $field_data ): bool {
$field_key = ! empty( $field_data['field_key'] ) ? (string) $field_data['field_key'] : '';
$widget_name = ! empty( $field_data['widget_name'] ) ? (string) $field_data['widget_name'] : '';
$widget_key = ! empty( $field_data['widget_key'] ) ? (string) $field_data['widget_key'] : '';

return 'listing_type' === $field_key
|| in_array( 'listing-type', [ $widget_name, $widget_key ], true );
}

protected function get_field_value( $listing_id, $field_data ) {
$value = null;

Expand Down
Loading