diff --git a/app/Http/Controllers/CheckoutController.php b/app/Http/Controllers/CheckoutController.php index ecd00f3239..78771a342e 100644 --- a/app/Http/Controllers/CheckoutController.php +++ b/app/Http/Controllers/CheckoutController.php @@ -80,7 +80,8 @@ public function checkout( Validator $validator, WP_REST_Request $request ): arra } // Update the order status to paid - $repository->update( ( new DTO )->set_id( $dto->get_id() )->set_status( Status::PAID ) ); + $dto->set_id( $dto->get_id() )->set_status( Status::PAID ); + $repository->update( $dto ); do_action( 'directorist_before_redirect_checkout', $dto, $checkout_type, $request ); diff --git a/assets/js/admin-builder-archive.js b/assets/js/admin-builder-archive.js index 8442fae1e9..d5acda56df 100644 --- a/assets/js/admin-builder-archive.js +++ b/assets/js/admin-builder-archive.js @@ -1,187 +1,6 @@ /******/ (function() { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ "./assets/src/js/admin/components/delete-directory-modal.js": -/*!******************************************************************!*\ - !*** ./assets/src/js/admin/components/delete-directory-modal.js ***! - \******************************************************************/ -/***/ (function() { - -window.addEventListener('load', function () { - var $ = jQuery; - - // Open Delete Modal - $('.atbdp-directory-delete-link-action').on('click', function (e) { - e.preventDefault(); - var delete_link = $(this).data('delete-link'); - $('.atbdp-directory-delete-link').prop('href', delete_link); - }); - - // Delete Action - $('.atbdp-directory-delete-link').on('click', function (e) { - // e.preventDefault(); - $(this).prepend(' '); - $('.atbdp-directory-delete-cancel-link').removeClass('cptm-modal-toggle'); - $('.atbdp-directory-delete-cancel-link').addClass('atbdp-disabled'); - }); -}); - -/***/ }), - -/***/ "./assets/src/js/admin/components/directory-migration-modal.js": -/*!*********************************************************************!*\ - !*** ./assets/src/js/admin/components/directory-migration-modal.js ***! - \*********************************************************************/ -/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { - -window.addEventListener('load', function () { - var $ = jQuery; - var axios = (__webpack_require__(/*! axios */ "./node_modules/axios/index.js")["default"]); - - // Migration Link - $('.atbdp-directory-migration-link').on('click', function (e) { - e.preventDefault(); - var self = this; - $('.cptm-directory-migration-form').find('.cptm-comfirmation-text').html('Please wait...'); - $('.atbdp-directory-migration-cencel-link').remove(); - $(this).html(' Migrating'); - $(this).addClass('atbdp-disabled'); - var form_data = new FormData(); - form_data.append('action', 'directorist_force_migrate'); - - // Response Success Callback - var responseSuccessCallback = function responseSuccessCallback(response) { - var _response$data; - // console.log( { response } ); - - if (response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.success) { - var _response$data$messag, _response$data2; - var msg = (_response$data$messag = response === null || response === void 0 || (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.message) !== null && _response$data$messag !== void 0 ? _response$data$messag : 'Migration Successful'; - var alert_content = "\n
\n
\n \n
\n\n
".concat(msg, "
\n
\n "); - $('.cptm-directory-migration-form').find('.cptm-comfirmation-text').html(alert_content); - $(self).remove(); - location.reload(); - return; - } - responseFaildCallback(response); - }; - - // Response Error Callback - var responseFaildCallback = function responseFaildCallback(response) { - var _response$data$messag2, _response$data3; - // console.log( { response } ); - - var msg = (_response$data$messag2 = response === null || response === void 0 || (_response$data3 = response.data) === null || _response$data3 === void 0 ? void 0 : _response$data3.message) !== null && _response$data$messag2 !== void 0 ? _response$data$messag2 : 'Something went wrong please try again'; - var alert_content = "\n
\n
\n \n
\n\n
".concat(msg, "
\n
\n "); - $('.cptm-directory-migration-form').find('.cptm-comfirmation-text').html(alert_content); - $(self).remove(); - }; - - // Send Request - axios.post(directorist_admin.ajax_url, form_data).then(function (response) { - responseSuccessCallback(response); - }).catch(function (response) { - responseFaildCallback(response); - }); - }); -}); - -/***/ }), - -/***/ "./assets/src/js/admin/components/import-directory-modal.js": -/*!******************************************************************!*\ - !*** ./assets/src/js/admin/components/import-directory-modal.js ***! - \******************************************************************/ -/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { - -function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } -function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } -function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } -window.addEventListener('load', function () { - var axios = (__webpack_require__(/*! axios */ "./node_modules/axios/index.js")["default"]); - var $ = jQuery; - - // cptm-import-directory-form - var term_id = 0; - $('.cptm-import-directory-form').on('submit', function (e) { - e.preventDefault(); - var form_feedback = $(this).find('.cptm-form-group-feedback'); - var modal_content = $('.cptm-import-directory-modal').find('.cptm-modal-content'); - var modal_alert = $('.cptm-import-directory-modal-alert'); - var form_data = new FormData(); - form_data.append('action', 'save_imported_post_type_data'); - form_data.append('directorist_nonce', directorist_admin.directorist_nonce); - if (Number.isInteger(term_id) && term_id > 0) { - form_data.append('term_id', term_id); - } - var form_fields = $(this).find('.cptm-form-field'); - var general_fields = ['text', 'number']; - $(this).find('button[type=submit] .cptm-loading-icon').removeClass('cptm-d-none'); - var _iterator = _createForOfIteratorHelper(form_fields), - _step; - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var field = _step.value; - if (!field.name.length) { - continue; - } - - // General fields - if (general_fields.includes(field.type)) { - form_data.append(field.name, $(field).val()); - } - - // Media fields - if ('file' === field.type) { - form_data.append(field.name, field.files[0]); - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - var self = this; - form_feedback.html(''); - axios.post(directorist_admin.ajax_url, form_data).then(function (response) { - // console.log( { response } ); - $(self).find('button[type=submit] .cptm-loading-icon').addClass('cptm-d-none'); - - // Store term ID if exist - if (response.data.term_id && Number.isInteger(response.data.term_id) && response.data.term_id > 0) { - term_id = response.data.term_id; - // console.log( 'Term ID has been updated' ); - } - - // Show status log - if (response.data && response.data.status.status_log) { - var status_log = response.data.status.status_log; - for (var status in status_log) { - var alert = '
' + status_log[status].message + '
'; - form_feedback.append(alert); - } - } - - // Reload the page if success - if (response.data && response.data.status && response.data.status.success) { - // console.log( 'reloading...' ); - - modal_content.addClass('cptm-d-none'); - modal_alert.removeClass('cptm-d-none'); - $(self).trigger('reset'); - location.reload(); - } - }).catch(function (error) { - console.log({ - error: error - }); - $(self).find('button[type=submit] .cptm-loading-icon').addClass('cptm-d-none'); - }); - }); -}); - -/***/ }), - /***/ "./node_modules/axios/index.js": /*!*************************************!*\ !*** ./node_modules/axios/index.js ***! @@ -2232,6 +2051,187 @@ module.exports = { }; +/***/ }), + +/***/ "./assets/src/js/admin/components/delete-directory-modal.js": +/*!******************************************************************!*\ + !*** ./assets/src/js/admin/components/delete-directory-modal.js ***! + \******************************************************************/ +/***/ (function() { + +window.addEventListener('load', function () { + var $ = jQuery; + + // Open Delete Modal + $('.atbdp-directory-delete-link-action').on('click', function (e) { + e.preventDefault(); + var delete_link = $(this).data('delete-link'); + $('.atbdp-directory-delete-link').prop('href', delete_link); + }); + + // Delete Action + $('.atbdp-directory-delete-link').on('click', function (e) { + // e.preventDefault(); + $(this).prepend(' '); + $('.atbdp-directory-delete-cancel-link').removeClass('cptm-modal-toggle'); + $('.atbdp-directory-delete-cancel-link').addClass('atbdp-disabled'); + }); +}); + +/***/ }), + +/***/ "./assets/src/js/admin/components/directory-migration-modal.js": +/*!*********************************************************************!*\ + !*** ./assets/src/js/admin/components/directory-migration-modal.js ***! + \*********************************************************************/ +/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { + +window.addEventListener('load', function () { + var $ = jQuery; + var axios = (__webpack_require__(/*! axios */ "./node_modules/axios/index.js")["default"]); + + // Migration Link + $('.atbdp-directory-migration-link').on('click', function (e) { + e.preventDefault(); + var self = this; + $('.cptm-directory-migration-form').find('.cptm-comfirmation-text').html('Please wait...'); + $('.atbdp-directory-migration-cencel-link').remove(); + $(this).html(' Migrating'); + $(this).addClass('atbdp-disabled'); + var form_data = new FormData(); + form_data.append('action', 'directorist_force_migrate'); + + // Response Success Callback + var responseSuccessCallback = function responseSuccessCallback(response) { + var _response$data; + // console.log( { response } ); + + if (response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.success) { + var _response$data$messag, _response$data2; + var msg = (_response$data$messag = response === null || response === void 0 || (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.message) !== null && _response$data$messag !== void 0 ? _response$data$messag : 'Migration Successful'; + var alert_content = "\n
\n
\n \n
\n\n
".concat(msg, "
\n
\n "); + $('.cptm-directory-migration-form').find('.cptm-comfirmation-text').html(alert_content); + $(self).remove(); + location.reload(); + return; + } + responseFaildCallback(response); + }; + + // Response Error Callback + var responseFaildCallback = function responseFaildCallback(response) { + var _response$data$messag2, _response$data3; + // console.log( { response } ); + + var msg = (_response$data$messag2 = response === null || response === void 0 || (_response$data3 = response.data) === null || _response$data3 === void 0 ? void 0 : _response$data3.message) !== null && _response$data$messag2 !== void 0 ? _response$data$messag2 : 'Something went wrong please try again'; + var alert_content = "\n
\n
\n \n
\n\n
".concat(msg, "
\n
\n "); + $('.cptm-directory-migration-form').find('.cptm-comfirmation-text').html(alert_content); + $(self).remove(); + }; + + // Send Request + axios.post(directorist_admin.ajax_url, form_data).then(function (response) { + responseSuccessCallback(response); + }).catch(function (response) { + responseFaildCallback(response); + }); + }); +}); + +/***/ }), + +/***/ "./assets/src/js/admin/components/import-directory-modal.js": +/*!******************************************************************!*\ + !*** ./assets/src/js/admin/components/import-directory-modal.js ***! + \******************************************************************/ +/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { + +function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } +function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } +function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } +window.addEventListener('load', function () { + var axios = (__webpack_require__(/*! axios */ "./node_modules/axios/index.js")["default"]); + var $ = jQuery; + + // cptm-import-directory-form + var term_id = 0; + $('.cptm-import-directory-form').on('submit', function (e) { + e.preventDefault(); + var form_feedback = $(this).find('.cptm-form-group-feedback'); + var modal_content = $('.cptm-import-directory-modal').find('.cptm-modal-content'); + var modal_alert = $('.cptm-import-directory-modal-alert'); + var form_data = new FormData(); + form_data.append('action', 'save_imported_post_type_data'); + form_data.append('directorist_nonce', directorist_admin.directorist_nonce); + if (Number.isInteger(term_id) && term_id > 0) { + form_data.append('term_id', term_id); + } + var form_fields = $(this).find('.cptm-form-field'); + var general_fields = ['text', 'number']; + $(this).find('button[type=submit] .cptm-loading-icon').removeClass('cptm-d-none'); + var _iterator = _createForOfIteratorHelper(form_fields), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var field = _step.value; + if (!field.name.length) { + continue; + } + + // General fields + if (general_fields.includes(field.type)) { + form_data.append(field.name, $(field).val()); + } + + // Media fields + if ('file' === field.type) { + form_data.append(field.name, field.files[0]); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + var self = this; + form_feedback.html(''); + axios.post(directorist_admin.ajax_url, form_data).then(function (response) { + // console.log( { response } ); + $(self).find('button[type=submit] .cptm-loading-icon').addClass('cptm-d-none'); + + // Store term ID if exist + if (response.data.term_id && Number.isInteger(response.data.term_id) && response.data.term_id > 0) { + term_id = response.data.term_id; + // console.log( 'Term ID has been updated' ); + } + + // Show status log + if (response.data && response.data.status.status_log) { + var status_log = response.data.status.status_log; + for (var status in status_log) { + var alert = '
' + status_log[status].message + '
'; + form_feedback.append(alert); + } + } + + // Reload the page if success + if (response.data && response.data.status && response.data.status.success) { + // console.log( 'reloading...' ); + + modal_content.addClass('cptm-d-none'); + modal_alert.removeClass('cptm-d-none'); + $(self).trigger('reset'); + location.reload(); + } + }).catch(function (error) { + console.log({ + error: error + }); + $(self).find('button[type=submit] .cptm-loading-icon').addClass('cptm-d-none'); + }); + }); +}); + /***/ }), /***/ "./node_modules/axios/package.json": diff --git a/assets/src/js/public/checkout.js b/assets/src/js/public/checkout.js index 4e8579a074..1e3b886af8 100644 --- a/assets/src/js/public/checkout.js +++ b/assets/src/js/public/checkout.js @@ -77,15 +77,15 @@ return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); } - function get_error_message( error ) { + function get_error_message(error) { let message = ''; - if ( error.message ) { + if (error.message) { message = error.message; - } else if ( error.messages ) { - const messages = Object.values( error.messages ); + } else if (error.messages) { + const messages = Object.values(error.messages); - if ( messages.length > 0 ) { + if (messages.length > 0) { message = messages[0][0]; } } @@ -116,15 +116,15 @@ data: data, }); - if ( response.redirect_url ) { + if (response.redirect_url) { window.location.href = response.redirect_url; } } catch (error) { - const message = get_error_message( error ); + const message = get_error_message(error); + + alert(message); + console.log(error); - alert( message ); - console.log( error ); - // Reset loading state on error submitBtn.prop('disabled', false); btnText.text(originalText); diff --git a/assets/src/js/public/components/dashboard/dashboardListing.js b/assets/src/js/public/components/dashboard/dashboardListing.js index 07477fd3cf..438c097dea 100644 --- a/assets/src/js/public/components/dashboard/dashboardListing.js +++ b/assets/src/js/public/components/dashboard/dashboardListing.js @@ -117,15 +117,20 @@ } else if (task == 'unfeature') { swal( { - title: directorist.listing_unfeature_title || 'Unfeature Listing', - text: directorist.listing_unfeature_text || 'Are you sure you want to unfeature this listing?', + title: + directorist.listing_unfeature_title || + 'Unfeature Listing', + text: + directorist.listing_unfeature_text || + 'Are you sure you want to unfeature this listing?', type: 'warning', cancelButtonText: directorist.review_cancel_btn_text || 'Cancel', showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: - directorist.listing_unfeature_confirm_text || 'Yes, Unfeature', + directorist.listing_unfeature_confirm_text || + 'Yes, Unfeature', showLoaderOnConfirm: true, closeOnConfirm: false, }, @@ -139,7 +144,9 @@ postid ); swal({ - title: directorist.listing_unfeatured || 'Listing Unfeatured', + title: + directorist.listing_unfeatured || + 'Listing Unfeatured', type: 'success', timer: 200, showConfirmButton: false, diff --git a/includes/helper-functions.php b/includes/helper-functions.php index 0d4ef32b20..ec71f94bcc 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -4774,3 +4774,38 @@ function directorist_renewal_token_hash( $listing_id, $user_id ) { $token_str = 'cB0XtpVzGb180dgPi3hADW-' . $listing_id . '::' . $user_id; return wp_hash( $token_str, 'nonce' ); } + +function directorist_submission_form_fields_raw( int $directory_type_id ): array { + return get_term_meta( $directory_type_id, 'submission_form_fields', true ); +} + +function directorist_submission_form_fields( int $directory_type_id, array $data = [] ): array { + $data['directory_type_id'] = $directory_type_id; + return apply_filters( 'directorist_submission_form_fields', directorist_submission_form_fields_raw( $directory_type_id ), $data ); +} + +function directorist_single_listing_header( int $directory_type_id, array $data = [] ): array { + $data['directory_type_id'] = $directory_type_id; + return apply_filters( 'directorist_single_listing_header', get_term_meta( $directory_type_id, 'single_listing_header', true ), $data ); +} + +function directorist_single_listings_contents( int $directory_type_id, array $data = [] ): array { + $data['directory_type_id'] = $directory_type_id; + return apply_filters( 'directorist_single_listings_contents', get_term_meta( $directory_type_id, 'single_listings_contents', true ), $data ); +} + +function directorist_listing_archive_fields( int $directory_type_id, array $data = [] ): array { + $card_fields = get_term_meta( $directory_type_id, 'listings_card_grid_view', true ); + $list_fields = get_term_meta( $directory_type_id, 'listings_card_list_view', true ); + + $data['directory_type_id'] = $directory_type_id; + + return apply_filters( + 'directorist_listing_archive_fields', + [ + 'card_fields' => ! empty( $card_fields ) && is_array( $card_fields ) ? $card_fields : [], + 'list_fields' => ! empty( $list_fields ) && is_array( $list_fields ) ? $list_fields : [], + ], + $data + ); +} diff --git a/includes/model/ListingForm.php b/includes/model/ListingForm.php index af0b712b83..ad583a8ceb 100644 --- a/includes/model/ListingForm.php +++ b/includes/model/ListingForm.php @@ -778,6 +778,13 @@ protected function set_directory() { return $this->current_listing_type; } + public function get_listing_owner_id(): int { + if ( $this->add_listing_id ) { + return (int) get_post_field( 'post_author', $this->add_listing_id ); + } + return get_current_user_id(); + } + public function build_form_data( $type ) { $form_data = []; @@ -785,7 +792,13 @@ public function build_form_data( $type ) { return $form_data; } - $submission_form_fields = get_term_meta( $type, 'submission_form_fields', true ); + $submission_form_fields = directorist_submission_form_fields( + (int) $type, + [ + 'listing_id' => $this->add_listing_id, + 'listing_owner_id' => $this->get_listing_owner_id(), + ] + ); if ( ! empty( $submission_form_fields['groups'] ) ) { foreach ( $submission_form_fields['groups'] as $group ) { diff --git a/includes/model/Listings.php b/includes/model/Listings.php index 4bfd87a4b9..7d25bba8e5 100644 --- a/includes/model/Listings.php +++ b/includes/model/Listings.php @@ -507,16 +507,12 @@ public function set_loop_data() { $u_pro_pic = ! empty( $u_pro_pic ) ? wp_get_attachment_image_src( $u_pro_pic, 'thumbnail' ) : ''; $bdbh = get_post_meta( $id, '_bdbh', true ); - $listing_type = $this->current_listing_type; - $card_fields = get_term_meta( $listing_type, 'listings_card_grid_view', true ); - $list_fields = get_term_meta( $listing_type, 'listings_card_list_view', true ); $get_directory_type = get_term_by( 'id', $this->current_listing_type, ATBDP_TYPE ); $directory_type = ! empty( $get_directory_type ) ? $get_directory_type->slug : ''; + $this->loop = [ 'id' => $id, - 'card_fields' => $card_fields, - 'list_fields' => $list_fields, 'permalink' => get_permalink( $id ), 'title' => get_the_title(), 'cats' => get_the_terms( $id, ATBDP_CATEGORY ), @@ -541,6 +537,10 @@ public function set_loop_data() { 'avatar_img' => get_avatar( $author_id, apply_filters( 'atbdp_avatar_size', 32 ), '', $author_display_name ), 'review' => $this->get_review_data(), ]; + + $archive_fields = directorist_listing_archive_fields( $listing_type, [ 'author_id' => $author_id, ] ); + + $this->loop = array_merge( $this->loop, $archive_fields ); } public function get_review_data() { @@ -1811,12 +1811,12 @@ function loop_get_the_thumbnail( $class = '' ) { $listing_prv_img = directorist_get_listing_preview_image( $id ); $listing_img = directorist_get_listing_gallery_images( $id ); - - $thumbnail_img_id = array_filter( array_merge( (array) $listing_prv_img, (array) $listing_img ) ); $link_start = '
'; $link_end = '
'; + $thumbnail_img_id = apply_filters( 'directorist_listing_archive_thumbnails', $thumbnail_img_id, $id ); + if ( empty( $thumbnail_img_id ) ) { $thumbnail_img_id = $default_image_src; $image_alt = esc_html( get_the_title( $id ) ); @@ -1832,7 +1832,7 @@ function loop_get_the_thumbnail( $class = '' ) { return is_numeric( $value ); } ); - + $image_count = count( $thumbnail_img_id ); if ( 1 === (int) $image_count ) { diff --git a/includes/model/SingleListing.php b/includes/model/SingleListing.php index da8a0a5bf6..5605f0329d 100644 --- a/includes/model/SingleListing.php +++ b/includes/model/SingleListing.php @@ -39,9 +39,9 @@ class Directorist_Single_Listing { private function __construct( $listing_id = 0 ) { if ( $listing_id && is_int( $listing_id ) ) { - $this->id = $listing_id; + $this->id = (int) $listing_id; } else { - $this->id = get_the_ID(); + $this->id = (int) get_the_ID(); } $this->prepare_data(); @@ -64,10 +64,10 @@ public function get_directory_type_id() { } public function prepare_data() { - $this->author_id = get_post_field( 'post_author', $this->id ); + $this->author_id = (int) get_post_field( 'post_author', $this->id ); $this->post = get_post( $this->id ); - $this->type = $this->get_directory_type_id(); - $this->header_data = get_term_meta( $this->type, 'single_listing_header', true ); + $this->type = (int) $this->get_directory_type_id(); + $this->header_data = directorist_single_listing_header( $this->type, [ 'listing_id' => $this->id, 'listing_owner_id' => $this->author_id, 'directory_type_id' => $this->type ] ); $this->content_data = $this->build_content_data(); $this->fm_plan = get_post_meta( $this->id, '_fm_plans', true ); $this->price_range = get_post_meta( $this->id, '_price_range', true ); @@ -77,8 +77,14 @@ public function prepare_data() { public function build_content_data() { $content_data = []; - $single_fields = get_term_meta( $this->type, 'single_listings_contents', true ); - $submission_form_fields = get_term_meta( $this->type, 'submission_form_fields', true ); + $single_fields = directorist_single_listings_contents( + $this->type, + [ + 'listing_id' => (int) $this->id, + 'listing_owner_id' => (int) $this->author_id, + ] + ); + $submission_form_fields = directorist_submission_form_fields_raw( $this->type ); if ( ! empty( $single_fields['fields'] ) ) { foreach ( $single_fields['fields'] as $key => $value ) { @@ -616,6 +622,8 @@ public function get_slider_data( $data = null ) { array_unshift( $data['images'], $preview_img ); } + $data['images'] = apply_filters( 'directorist_single_listing_thumbnails', $data['images'], $listing_id ); + if ( count( $data['images'] ) < 1 ) { $data['images'][] = [ 'alt' => $listing_title, @@ -629,7 +637,6 @@ public function get_slider_data( $data = null ) { } public function slider_template() { - $slider = $this->listing_header( 'slider', 'slider-placeholder' ); if ( ! $slider ) { @@ -640,7 +647,6 @@ public function slider_template() { } public function slider_field_template( $slider = null ) { - $args = [ 'listing' => $this, 'has_slider' => true, @@ -1037,23 +1043,22 @@ public function listing_header( $key = '', $group = '', $subgroup = '' ) { } public function header_template() { - + $display_title = $this->listing_header( 'title', 'listing-title-placeholder' ); $args = [ - 'listing' => $this, - 'use_listing_title' => true, - 'section_title' => '', - 'section_icon' => '', - 'display_title' => $display_title, - 'display_tagline' => ! empty( $display_title['enable_tagline'] ) ? $display_title['enable_tagline'] : false, - 'display_content' => false, + 'listing' => $this, + 'use_listing_title' => true, + 'section_title' => '', + 'section_icon' => '', + 'display_title' => $display_title, + 'display_tagline' => ! empty( $display_title['enable_tagline'] ) ? $display_title['enable_tagline'] : false, + 'display_content' => false, ]; return Helper::get_template( 'single/header', $args ); } public function render_shortcode_single_listing() { - if ( ! is_singular( ATBDP_POST_TYPE ) ) { return; } diff --git a/templates/listing-form/fields/image_upload.php b/templates/listing-form/fields/image_upload.php index b5c2877253..247412f2b9 100644 --- a/templates/listing-form/fields/image_upload.php +++ b/templates/listing-form/fields/image_upload.php @@ -22,13 +22,18 @@ $accepted_mime_types_upper = array_map( 'strtoupper', $accepted_mime_types ); $accepted_mime_types = array_merge( $accepted_mime_types, $accepted_mime_types_upper ); -$img_upload_data = [ - 'type' => join( ', ', $accepted_mime_types ), - 'max_num_of_img' => $limit, - 'max_total_img_size' => $max_total_file_size_kb, - 'is_required' => $required, - 'max_size_per_img' => $max_file_size_kb, -]; +$img_upload_data = apply_filters( + 'directorist_image_upload_config', + [ + 'type' => join( ', ', $accepted_mime_types ), + 'max_num_of_img' => $limit, + 'max_total_img_size' => $max_total_file_size_kb, + 'is_required' => $required, + 'max_size_per_img' => $max_file_size_kb, + ], + $listing_form, + $data +); $img_upload_data = json_encode( $img_upload_data ); ?>