--- a/classified-listing/app/Controllers/Admin/Meta/AddTermMetaField.php
+++ b/classified-listing/app/Controllers/Admin/Meta/AddTermMetaField.php
@@ -2,6 +2,7 @@
namespace RtclControllersAdminMeta;
+use RtclHelpersCache;
use RtclHelpersFunctions;
use RtclResourcesOptions;
@@ -26,6 +27,10 @@
add_action( 'edited_' . rtcl()->location, [ __CLASS__, 'save_taxonomy_custom_meta' ], 10, 2 );
add_action( 'create_' . rtcl()->location, [ __CLASS__, 'save_taxonomy_custom_meta' ], 10, 2 );
+ add_action( 'created_term', [ Cache::class, 'clear_cache_on_term_change'], 10, 3 );
+ add_action( 'edited_term', [ Cache::class, 'clear_cache_on_term_change'], 10, 3 );
+ add_action( 'delete_term', [ Cache::class, 'clear_cache_on_term_change'], 10, 3 );
+
add_filter( 'manage_' . rtcl()->category . '_custom_column', [
$this,
'add_taxonomy_order_column_value',
--- a/classified-listing/app/Controllers/Admin/ScriptLoader.php
+++ b/classified-listing/app/Controllers/Admin/ScriptLoader.php
@@ -678,6 +678,7 @@
'rtcl_location' => get_query_var( 'rtcl_location' ),
'rtcl_location_base' => $location_base,
'user_login_alert_message' => esc_html__( 'Sorry, you need to login first.', 'classified-listing' ),
+ 'is_user_logged_in' => is_user_logged_in(),
/* translators: Image pending count */
'upload_limit_alert_message' => esc_html__( 'Sorry, you have only %d images pending.', 'classified-listing' ),
'delete_label' => esc_html__( 'Delete Permanently', 'classified-listing' ),
--- a/classified-listing/app/Controllers/Ajax/Checkout.php
+++ b/classified-listing/app/Controllers/Ajax/Checkout.php
@@ -39,8 +39,8 @@
'listing_id' => 0,
'pricing_id' => $pricing_id,
'payment_method' => $payment_method,
- ]
- )
+ ],
+ ),
);
$pricing = rtcl()->factory->get_pricing( $checkout_data['pricing_id'] );
$gateway = Functions::get_payment_gateway( $checkout_data['payment_method'] );
@@ -68,11 +68,11 @@
$multiple_tax = self::get_tax_amount( $country, $state, $pricing_price );
if ( Functions::is_enable_multiple_tax() ) {
foreach ( $multiple_tax as $single_tax ) {
- $tax_amount = $tax_amount + $single_tax['amount'];
+ $tax_amount = $tax_amount + $single_tax['raw_amount'];
}
} else {
$single_tax = current( $multiple_tax );
- $tax_amount = $single_tax['amount'];
+ $tax_amount = $single_tax['raw_amount'];
}
$total_price = $pricing_price + $tax_amount;
}
@@ -147,7 +147,6 @@
do_action( 'rtcl_checkout_process_error', $order, $payment_process_data );
}
} catch ( Exception $e ) {
-
}
} else {
Functions::add_notice( esc_html__( 'Error to create payment.', 'classified-listing' ), 'error' );
@@ -168,7 +167,7 @@
'success' => $success,
'redirect_url' => $redirect_url,
'gateway_id' => $gateway_id,
- ]
+ ],
);
wp_send_json( apply_filters( 'rtcl_checkout_process_ajax_response_args', $res_data ) );
}
@@ -193,18 +192,17 @@
$error = false;
$multiple_tax = self::get_tax_amount( $country, $state, $price );
-
} else {
$message = __( 'Session expired.', 'classified-listing' );
}
if ( Functions::is_enable_multiple_tax() ) {
foreach ( $multiple_tax as $single_tax ) {
- $tax_amount = $tax_amount + $single_tax['amount'];
+ $tax_amount = $tax_amount + $single_tax['raw_amount'];
}
} else {
$single_tax = current( $multiple_tax );
- $tax_amount = $single_tax['amount'];
+ $tax_amount = $single_tax['raw_amount'];
}
$total_amount = $price + $tax_amount;
@@ -218,7 +216,7 @@
'pricing_price' => Functions::get_payment_formatted_price( $price ),
'tax_amount' => Functions::get_payment_formatted_price( $tax_amount ),
'total_amount' => Functions::get_payment_formatted_price( $total_amount ),
- ]
+ ],
);
}
@@ -262,8 +260,8 @@
WHERE country = %s
AND country_state = ''
ORDER BY tax_rate_priority DESC",
- $country
- )
+ $country,
+ ),
);
if ( empty( $results ) ) {
@@ -284,8 +282,9 @@
$tax_amount = ( $tax_rate * $pricing_price ) / 100;
$multiple_tax[] = [
- 'label' => $row->tax_rate_name,
- 'amount' => Functions::get_payment_formatted_price( $tax_amount ),
+ 'label' => $row->tax_rate_name,
+ 'amount' => Functions::get_payment_formatted_price( $tax_amount ),
+ 'raw_amount' => $tax_amount,
];
}
}
--- a/classified-listing/app/Controllers/Ajax/FormBuilderAjax.php
+++ b/classified-listing/app/Controllers/Ajax/FormBuilderAjax.php
@@ -38,7 +38,7 @@
add_action( 'wp_ajax_rtcl_update_listing', [ $this, 'update_listing' ] );
add_action( 'wp_ajax_rtcl_fb_write_with_ai', [ $this, 'write_with_ai' ] );
- if ( !is_user_logged_in() && Functions::is_enable_post_for_unregister() ) {
+ if ( ! is_user_logged_in() && Functions::is_enable_post_for_unregister() ) {
add_action( 'wp_ajax_nopriv_rtcl_get_terms', [ $this, 'get_terms_callback' ] );
add_action( 'wp_ajax_nopriv_rtcl_fb_get_category', [ $this, 'get_category' ] );
add_action( 'wp_ajax_nopriv_rtcl_fb_get_location', [ $this, 'get_location' ] );
@@ -46,7 +46,7 @@
add_action( 'wp_ajax_nopriv_rtcl_fb_gallery_image_upload', [ $this, 'gallery_image_upload' ] );
add_action( 'wp_ajax_nopriv_rtcl_fb_gallery_image_update_as_feature', [
$this,
- 'gallery_image_update_as_feature'
+ 'gallery_image_update_as_feature',
] );
add_action( 'wp_ajax_nopriv_rtcl_fb_gallery_image_delete', [ $this, 'gallery_image_delete' ] );
add_action( 'wp_ajax_nopriv_rtcl_fb_file_upload', [ $this, 'file_upload' ] );
@@ -58,7 +58,6 @@
add_action( 'wp_ajax_nopriv_rtcl_fb_get_tags', [ $this, 'get_tags' ] );
}
-
}
/**
@@ -67,46 +66,46 @@
public static function update_listing(): void {
Functions::clear_notices();// Clear previous notice
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( 'Session error !!', 'classified-listing' ) );
return;
}
- $isAdminEnd = !empty( $_POST['isAdminEnd'] );
+ $isAdminEnd = ! empty( $_POST['isAdminEnd'] );
$postingType = 'new';
- $listing_id = !empty( $_POST['listingId'] ) ? absint( $_POST['listingId'] ) : 0;
- $listing = null;
- if ( ( $listing_id && ( !( $listing = rtcl()->factory->get_listing( $listing_id ) ) || ( $isAdminEnd && !current_user_can( 'edit_rtcl_listing', $listing_id ) ) || ( !$isAdminEnd && !Functions::current_user_can( 'edit_' . rtcl()->post_type, $listing_id ) ) ) ) || ( !is_user_logged_in() && !Functions::is_enable_post_for_unregister() ) ) {
+ $listing_id = ! empty( $_POST['listingId'] ) ? absint( $_POST['listingId'] ) : 0;
+ $listing = null;
+ if ( ( $listing_id && ( ! ( $listing = rtcl()->factory->get_listing( $listing_id ) ) || ( $isAdminEnd && ! current_user_can( 'edit_rtcl_listing', $listing_id ) ) || ( ! $isAdminEnd && ! Functions::current_user_can( 'edit_' . rtcl()->post_type, $listing_id ) ) ) ) || ( ! is_user_logged_in() && ! Functions::is_enable_post_for_unregister() ) ) {
wp_send_json_error( apply_filters( 'rtcl_fb_not_found_error_message', __( 'You do not have sufficient permissions to access this page.', 'classified-listing' ), $_REQUEST, 'permission_error' ) );
return;
}
- if ( !$listing || $listing->get_status() === 'rtcl-temp' ) {
- $form_id = !empty( $_POST['formId'] ) ? absint( $_POST['formId'] ) : 0;
+ if ( ! $listing || $listing->get_status() === 'rtcl-temp' ) {
+ $form_id = ! empty( $_POST['formId'] ) ? absint( $_POST['formId'] ) : 0;
} else {
$form_id = absint( get_post_meta( $listing_id, '_rtcl_form_id', true ) );
}
- if ( ( $isAdminEnd || ( $listing && !$form_id ) ) && !empty( $_POST['formId'] ) ) {
+ if ( ( $isAdminEnd || ( $listing && ! $form_id ) ) && ! empty( $_POST['formId'] ) ) {
$form_id = absint( $_POST['formId'] );
}
- if ( empty( $form_id ) || !$form = Form::query()->find( $form_id ) ) {
+ if ( empty( $form_id ) || ! $form = Form::query()->find( $form_id ) ) {
wp_send_json_error( apply_filters( 'rtcl_fb_not_found_error_message', esc_html__( 'Form not found !!', 'classified-listing' ) ), $_REQUEST );
return;
}
- if ( !empty( $_POST['formData'] ) ) {
+ if ( ! empty( $_POST['formData'] ) ) {
parse_str( $_POST['formData'], $formData );
} else {
$formData = [];
}
$sections = $form->sections;
- $fields = $form->fields;
+ $fields = $form->fields;
if ( empty( $sections ) || empty( $fields ) ) {
wp_send_json_error( apply_filters( 'rtcl_error_update_listing', __( 'Missing form field', 'classified-listing' ) ) );
@@ -114,7 +113,7 @@
}
$errors = FBHelper::formDataValidation( $formData, $form, $listing );
- if ( !empty( $errors ) ) {
+ if ( ! empty( $errors ) ) {
wp_send_json_error( apply_filters( 'rtcl_error_validation_update_listing', [ 'errors' => $errors ], $formData, $sections ) );
return;
@@ -131,9 +130,9 @@
}
// Data prepare
- $user_id = get_current_user_id();
+ $user_id = get_current_user_id();
$post_for_unregister = Functions::is_enable_post_for_unregister();
- if ( !is_user_logged_in() && $post_for_unregister ) {
+ if ( ! is_user_logged_in() && $post_for_unregister ) {
if ( empty( $formData['email'] ) ) {
wp_send_json_error( apply_filters( 'rtcl_error_update_listing', [ 'missing_required_email' => __( 'Missing required email to register user', 'classified-listing' ) ] ) );
@@ -153,12 +152,12 @@
}
}
- $metaData = [];
- $taxonomy = [
+ $metaData = [];
+ $taxonomy = [
'category' => [],
- 'location' => []
+ 'location' => [],
];
- $post_arg = [];
+ $post_arg = [];
$new_listing_status = Functions::get_option_item( 'rtcl_general_settings', 'new_listing_status', 'pending' );
if ( $listing ) {
if ( ( $listing->get_listing()->post_author > 0 && ( ( 'rtcl-temp' === $listing->get_listing()->post_status && $listing->get_listing()->post_author === get_current_user_id() ) || $listing->get_listing()->post_author == absint( apply_filters( 'rtcl_listing_post_user_id', get_current_user_id() ) ) ) ) || ( $listing->get_listing()->post_author == 0 && $post_for_unregister ) ) {
@@ -166,7 +165,7 @@
$post_arg['post_status'] = $new_listing_status;
$post_arg['post_author'] = $user_id;
} else {
- $postingType = 'update';
+ $postingType = 'update';
$status_after_edit = Functions::get_option_item( 'rtcl_general_settings', 'edited_listing_status' );
if ( 'publish' === $listing->get_listing()->post_status && $status_after_edit && $listing->get_listing()->post_status !== $status_after_edit ) {
$post_arg['post_status'] = $status_after_edit;
@@ -182,127 +181,138 @@
$post_arg = [
'post_status' => $new_listing_status,
'post_author' => $user_id,
- 'post_type' => rtcl()->post_type
+ 'post_type' => rtcl()->post_type,
];
}
-
+
foreach ( $fields as $fieldId => $field ) {
- $name = !empty( $field['name'] ) ? $field['name'] : '';
- $element = $field['element'];
- $rawValue = $formData[$name] ?? '';
+ $name = ! empty( $field['name'] ) ? $field['name'] : '';
+ $element = $field['element'];
+ $rawValue = $formData[ $name ] ?? '';
if ( isset( $field['preset'] ) && 1 == $field['preset'] ) {
if ( 'title' === $element ) {
- if ( !$isAdminEnd ) {
+ if ( ! $isAdminEnd ) {
$post_arg['post_title'] = FBHelper::sanitizeFieldValue( $rawValue, $field );
}
} elseif ( 'description' === $element ) {
- if ( !$isAdminEnd ) {
+ if ( ! $isAdminEnd ) {
$post_arg['post_content'] = FBHelper::sanitizeFieldValue( $rawValue, $field );
}
} elseif ( 'listing_type' === $element ) {
$metaData[] = [
'name' => 'ad_type',
'field' => $field,
- 'value' => $rawValue
+ 'value' => $rawValue,
];
} elseif ( 'excerpt' === $element ) {
$post_arg['post_excerpt'] = FBHelper::sanitizeFieldValue( $rawValue, $field );
} elseif ( 'category' === $element ) {
$taxonomy['category'] = is_array( $rawValue ) ? array_filter( array_map( function ( $tag ) {
- return !empty( $tag['term_id'] ) ? absint( $tag['term_id'] ) : '';
+ return ! empty( $tag['term_id'] ) ? absint( $tag['term_id'] ) : '';
}, $rawValue ) ) : [];
} elseif ( 'location' === $element ) {
$taxonomy['location'] = is_array( $rawValue ) ? array_filter( array_map( function ( $tag ) {
- return !empty( $tag['term_id'] ) ? absint( $tag['term_id'] ) : '';
+ return ! empty( $tag['term_id'] ) ? absint( $tag['term_id'] ) : '';
}, $rawValue ) ) : [];
} elseif ( 'tag' === $element ) {
$taxonomy['tag'] = is_array( $rawValue ) ? array_filter( array_map( function ( $tag ) {
- return !empty( $tag['term_id'] ) ? absint( $tag['term_id'] ) : '';
+ return ! empty( $tag['term_id'] ) ? absint( $tag['term_id'] ) : '';
}, $rawValue ) ) : [];
} elseif ( 'zipcode' === $element ) {
$metaData[] = [
'name' => 'zipcode',
'field' => $field,
- 'value' => Functions::sanitize( $rawValue )
+ 'value' => Functions::sanitize( $rawValue ),
];
} elseif ( 'view_count' === $element ) {
$metaData[] = [
'name' => '_views',
'field' => $field,
- 'value' => Functions::sanitize( $rawValue )
+ 'value' => Functions::sanitize( $rawValue ),
];
} elseif ( 'address' === $element ) {
$metaData[] = [
'name' => 'address',
'field' => $field,
- 'value' => FBHelper::sanitizeFieldValue( $rawValue, $field )
+ 'value' => FBHelper::sanitizeFieldValue( $rawValue, $field ),
];
} elseif ( 'geo_location' === $element ) {
+ $mapData = $formData['map'] ?? [];
$metaData[] = [
'name' => '_rtcl_geo_address',
'field' => $field,
- 'value' => Functions::sanitize( $rawValue )
+ 'value' => Functions::sanitize( $rawValue ),
+ ];
+ $metaData[] = [
+ 'name' => 'latitude',
+ 'field' => $field,
+ 'value' => isset( $mapData['latitude'] ) ? Functions::sanitize( $mapData['latitude'] ) : '',
+ ];
+ $metaData[] = [
+ 'name' => 'longitude',
+ 'field' => $field,
+ 'value' => isset( $mapData['longitude'] ) ? Functions::sanitize( $mapData['longitude'] ) : '',
];
} elseif ( 'phone' === $element ) {
$metaData[] = [
'name' => 'phone',
'field' => $field,
- 'value' => Functions::sanitize( $rawValue )
+ 'value' => Functions::sanitize( $rawValue ),
];
} elseif ( 'whatsapp' === $element ) {
$metaData[] = [
'name' => '_rtcl_whatsapp_number',
'field' => $field,
- 'value' => Functions::sanitize( $rawValue )
+ 'value' => Functions::sanitize( $rawValue ),
];
} elseif ( 'email' === $element ) {
$metaData[] = [
'name' => 'email',
'field' => $field,
- 'value' => Functions::sanitize( $rawValue, 'email' )
+ 'value' => Functions::sanitize( $rawValue, 'email' ),
];
} elseif ( 'website' === $element ) {
$metaData[] = [
'name' => 'website',
'field' => $field,
- 'value' => FBHelper::sanitizeFieldValue( $rawValue, $field )
+ 'value' => FBHelper::sanitizeFieldValue( $rawValue, $field ),
];
} elseif ( 'social_profiles' === $element ) {
$metaData[] = [
'name' => '_rtcl_social_profiles',
'field' => $field,
- 'value' => FBHelper::sanitizeFieldValue( $rawValue, $field )
+ 'value' => FBHelper::sanitizeFieldValue( $rawValue, $field ),
];
} elseif ( 'pricing' === $element ) {
- $pricing = $formData[$name];
- if ( !empty( $field['options'] ) && in_array( 'pricing_type', $field['options'] ) && isset( $pricing['pricing_type'] ) ) {
+ $pricing = $formData[ $name ];
+ if ( ! empty( $field['options'] ) && in_array( 'pricing_type', $field['options'] ) && isset( $pricing['pricing_type'] ) ) {
$pricing_type = in_array( $pricing['pricing_type'], array_keys( Options::get_listing_pricing_types() ) ) ? $pricing['pricing_type'] : 'price';
- $metaData[] = [
+ $metaData[] = [
'name' => '_rtcl_listing_pricing',
'field' => $field,
- 'value' => Functions::sanitize( $pricing_type )
+ 'value' => Functions::sanitize( $pricing_type ),
];
if ( 'range' === $pricing_type && isset( $pricing['max_price'] ) ) {
$metaData[] = [
'name' => '_rtcl_max_price',
'field' => $field,
- 'value' => Functions::format_decimal( $pricing['max_price'] )
+ 'value' => Functions::format_decimal( $pricing['max_price'] ),
];
}
}
- if ( !empty( $field['options'] ) && in_array( 'price_type', $field['options'] ) && isset( $pricing['price_type'] ) ) {
+ if ( ! empty( $field['options'] ) && in_array( 'price_type', $field['options'] ) && isset( $pricing['price_type'] ) ) {
$metaData[] = [
'name' => 'price_type',
'field' => $field,
- 'value' => Functions::sanitize( $pricing['price_type'] )
+ 'value' => Functions::sanitize( $pricing['price_type'] ),
];
}
- if ( !empty( $field['options'] ) && in_array( 'price_unit', $field['options'] ) && isset( $pricing['price_unit'] ) ) {
+ if ( ! empty( $field['options'] ) && in_array( 'price_unit', $field['options'] ) && isset( $pricing['price_unit'] ) ) {
$metaData[] = [
'name' => '_rtcl_price_unit',
'field' => $field,
- 'value' => Functions::sanitize( $pricing['price_unit'] )
+ 'value' => Functions::sanitize( $pricing['price_unit'] ),
];
}
@@ -310,70 +320,70 @@
$metaData[] = [
'name' => 'price',
'field' => $field,
- 'value' => Functions::format_decimal( $pricing['price'] )
+ 'value' => Functions::format_decimal( $pricing['price'] ),
];
}
} elseif ( 'map' === $element ) {
- $mapData = $formData[$name];
+ $mapData = $formData[ $name ];
$metaData[] = [
'name' => 'latitude',
'field' => $field,
- 'value' => isset( $mapData['latitude'] ) ? Functions::sanitize( $mapData['latitude'] ) : ''
+ 'value' => isset( $mapData['latitude'] ) ? Functions::sanitize( $mapData['latitude'] ) : '',
];
$metaData[] = [
'name' => 'longitude',
'field' => $field,
- 'value' => isset( $mapData['longitude'] ) ? Functions::sanitize( $mapData['longitude'] ) : ''
+ 'value' => isset( $mapData['longitude'] ) ? Functions::sanitize( $mapData['longitude'] ) : '',
];
$metaData[] = [
'name' => 'hide_map',
'field' => $field,
- 'value' => !empty( $mapData['hide_map'] ) ? 1 : null
+ 'value' => ! empty( $mapData['hide_map'] ) ? 1 : null,
];
} elseif ( 'terms_and_condition' === $element ) {
- if ( isset( $formData[$name] ) ) {
+ if ( isset( $formData[ $name ] ) ) {
$metaData[] = [
'name' => 'rtcl_agree',
'field' => $field,
- 'value' => !empty( $formData[$name] ) ? 1 : null
+ 'value' => ! empty( $formData[ $name ] ) ? 1 : null,
];
}
} elseif ( 'business_hours' === $element ) {
- $bshValues = FBHelper::sanitizeFieldValue( $rawValue, $field );
+ $bshValues = FBHelper::sanitizeFieldValue( $rawValue, $field );
$metaData[] = [
'name' => '_rtcl_bhs',
'field' => $field,
- 'value' => $bshValues
+ 'value' => $bshValues,
];
} elseif ( 'video_urls' === $element ) {
- $videoUrls = FBHelper::sanitizeFieldValue( $rawValue, $field );
+ $videoUrls = FBHelper::sanitizeFieldValue( $rawValue, $field );
$metaData[] = [
'name' => '_rtcl_video_urls',
'field' => $field,
- 'value' => $videoUrls
+ 'value' => $videoUrls,
];
} else {
$sanitizedValue = FBHelper::sanitizeFieldValue( $rawValue, $field, $listing );
- $metaData[] = [
+ $metaData[] = [
'name' => $name,
'field' => $field,
- 'value' => $sanitizedValue
+ 'value' => $sanitizedValue,
];
}
} else {
if ( 'file' !== $element ) {
- $sanitizedValue = FBHelper::sanitizeFieldValue( $rawValue, $field, $listing );
- $metaData[$name] = [
+ $sanitizedValue = FBHelper::sanitizeFieldValue( $rawValue, $field, $listing );
+ $metaData[ $name ] = [
'name' => $name,
'field' => $field,
- 'value' => $sanitizedValue
+ 'value' => $sanitizedValue,
];
}
}
}
if ( $listing ) {
- if ( 'rtcl-temp' === $listing->get_listing()->post_status && !empty( $post_arg['post_title'] ) ) {
+ if ( 'rtcl-temp' === $listing->get_listing()->post_status && ! empty( $post_arg['post_title'] ) ) {
$post_arg['post_name'] = $post_arg['post_title'];
}
$listingUpdate = wp_update_post( apply_filters( 'rtcl_listing_save_update_args', $post_arg, $postingType ) );
@@ -383,7 +393,6 @@
return;
}
} else {
-
$listing_id = wp_insert_post( apply_filters( 'rtcl_listing_save_update_args', $post_arg, $postingType ) );
if ( is_wp_error( $listing_id ) ) {
wp_send_json_error( apply_filters( 'rtcl_error_update_listing', [ 'wp_insert_post_error' => $listing_id->get_error_message() ] ) );
@@ -392,37 +401,37 @@
}
}
- $listing = rtcl()->factory->get_listing( $listing_id );
+ $listing = rtcl()->factory->get_listing( $listing_id );
$listing_id = $listing->get_id();
$metaData[] = [
'name' => '_rtcl_form_id',
- 'value' => $form_id
+ 'value' => $form_id,
];
- if ( !empty( $taxonomy['category'] ) && ( $isAdminEnd || $postingType === 'new' || ( $listing && $postingType === 'update' && empty( $listing->get_categories() ) ) ) ) {
+ if ( ! empty( $taxonomy['category'] ) && ( $isAdminEnd || $postingType === 'new' || ( $listing && $postingType === 'update' && empty( $listing->get_categories() ) ) ) ) {
wp_set_object_terms( $listing_id, $taxonomy['category'], rtcl()->category );
}
- if ( !empty( $taxonomy['location'] ) ) {
+ if ( ! empty( $taxonomy['location'] ) ) {
wp_set_object_terms( $listing_id, $taxonomy['location'], rtcl()->location );
}
- wp_set_object_terms( $listing_id, !empty( $taxonomy['tag'] ) ? $taxonomy['tag'] : null, rtcl()->tag );
+ wp_set_object_terms( $listing_id, ! empty( $taxonomy['tag'] ) ? $taxonomy['tag'] : null, rtcl()->tag );
$metaData = apply_filters( 'rtcl_fb_metadata_fields_before_save', $metaData, $postingType );
/* meta data */
- if ( !empty( $metaData ) ) {
+ if ( ! empty( $metaData ) ) {
foreach ( $metaData as $metaItem ) {
- if ( !empty( $metaItem['name'] ) ) {
+ if ( ! empty( $metaItem['name'] ) ) {
$metaItemName = $metaItem['name'];
- if ( !$isAdminEnd && ( $postingType === 'update' && 'ad_type' === $metaItemName && $listing->get_ad_type() ) ) {
+ if ( ! $isAdminEnd && ( $postingType === 'update' && 'ad_type' === $metaItemName && $listing->get_ad_type() ) ) {
continue;
}
$metaItemValue = $metaItem['value'];
- if ( !empty( $metaItem['field'] ) ) {
+ if ( ! empty( $metaItem['field'] ) ) {
if ( $metaItem['field']['element'] === 'date' ) {
- if ( is_array( $metaItemValue ) && !empty( $metaItemValue ) ) {
+ if ( is_array( $metaItemValue ) && ! empty( $metaItemValue ) ) {
foreach ( $metaItemValue as $key => $v ) {
update_post_meta( $listing_id, $metaItemName . '_' . $key, $v );
}
@@ -431,7 +440,7 @@
}
} elseif ( $metaItem['field']['element'] === 'checkbox' ) {
delete_post_meta( $listing_id, $metaItemName );
- if ( is_array( $metaItemValue ) && !empty( $metaItemValue ) ) {
+ if ( is_array( $metaItemValue ) && ! empty( $metaItemValue ) ) {
foreach ( $metaItemValue as $val ) {
if ( $val ) {
add_post_meta( $listing_id, $metaItemName, $val );
@@ -439,7 +448,7 @@
}
}
} elseif ( $metaItem['field']['element'] === 'social_profiles' ) {
- if ( !empty( $metaItemValue ) ) {
+ if ( ! empty( $metaItemValue ) ) {
update_post_meta( $listing->get_id(), '_rtcl_social_profiles', $metaItemValue );
} else {
delete_post_meta( $listing->get_id(), '_rtcl_social_profiles' );
@@ -461,7 +470,7 @@
if ( $postingType == 'new' ) {
update_post_meta( $listing_id, '_views', 0 );
$current_user_id = get_current_user_id();
- $ads = absint( get_user_meta( $current_user_id, '_rtcl_ads', true ) );
+ $ads = absint( get_user_meta( $current_user_id, '_rtcl_ads', true ) );
update_user_meta( $current_user_id, '_rtcl_ads', $ads + 1 );
if ( 'publish' === $new_listing_status ) {
Functions::add_default_expiry_date( $listing_id );
@@ -477,7 +486,7 @@
do_action( 'rtcl_listing_form_after_save_or_update', $listing, $postingType, end( $taxonomy['category'] ), $new_listing_status, [
'data' => $_REQUEST,
- 'files' => $_FILES
+ 'files' => $_FILES,
] );
$errorMessage = Functions::get_notices( 'error' );
@@ -500,30 +509,29 @@
$postingType,
$listing_id,
true,
- $message
- )
+ $message,
+ ),
] ) );
-
}
public function gallery_image_delete() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( "Session error !!", "classified-listing" ) );
return;
}
$listing_id = absint( Functions::request( "listingId" ) );
- $listing = rtcl()->factory->get_listing( $listing_id );
+ $listing = rtcl()->factory->get_listing( $listing_id );
- if ( $listing && !Functions::current_user_can( 'edit_' . rtcl()->post_type, $listing_id ) ) {
+ if ( $listing && ! Functions::current_user_can( 'edit_' . rtcl()->post_type, $listing_id ) ) {
wp_send_json_error( apply_filters( 'rtcl_fb_not_found_error_message', __( 'You do not have sufficient permissions to access this page.', 'classified-listing' ), $_REQUEST, 'permission_error' ) );
return;
}
$attach_id = isset( $_POST["attach_id"] ) ? absint( $_POST["attach_id"] ) : 0;
- $attach = get_post( $attach_id );
- if ( !$attach ) {
+ $attach = get_post( $attach_id );
+ if ( ! $attach ) {
wp_send_json_error( __( "Attachment does not exist.", "classified-listing" ) );
return;
@@ -540,7 +548,7 @@
$featureImageRemoved = true;
}
- if ( !wp_delete_attachment( $attach_id ) ) {
+ if ( ! wp_delete_attachment( $attach_id ) ) {
wp_send_json_error( __( "File could not be deleted.", "classified-listing" ) );
return;
@@ -551,41 +559,40 @@
'post_parent' => $listing->get_id(),
'fields' => 'ids',
'post_type' => 'attachment',
- 'posts_per_page' => -1,
+ 'posts_per_page' => - 1,
'post_status' => 'inherit',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
- 'relation' => 'OR',
- [
- 'key' => '_rtcl_attachment_type',
- 'value' => 'image',
- 'compare' => '='
- ],
- [
- 'key' => '_rtcl_attachment_type',
- 'compare' => 'NOT EXISTS'
- ]
- ]
+ 'relation' => 'OR',
+ [
+ 'key' => '_rtcl_attachment_type',
+ 'value' => 'image',
+ 'compare' => '=',
+ ],
+ [
+ 'key' => '_rtcl_attachment_type',
+ 'compare' => 'NOT EXISTS',
+ ],
+ ],
] );
- if ( !empty( $attachmentIds ) ) {
+ if ( ! empty( $attachmentIds ) ) {
set_post_thumbnail( $listing_id, $attachmentIds[0] );
}
}
wp_send_json_success();
-
}
public function gallery_image_update_as_feature() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( "Session error !!", "classified-listing" ) );
return;
}
$attach_id = isset( $_POST["attach_id"] ) ? absint( $_POST["attach_id"] ) : 0;
- $attach = get_post( $attach_id );
- if ( !$attach ) {
+ $attach = get_post( $attach_id );
+ if ( ! $attach ) {
wp_send_json_error( __( "Attachment does not exist.", "classified-listing" ) );
return;
@@ -603,29 +610,28 @@
wp_send_json_error( __( "File is already as featured.", "classified-listing" ) );
}
- if ( !set_post_thumbnail( $listingId, $attach_id ) ) {
+ if ( ! set_post_thumbnail( $listingId, $attach_id ) ) {
wp_send_json_error( __( "Error while making feature.", "classified-listing" ) );
}
wp_send_json_success( __( "Image successfully featured.", "classified-listing" ) );
-
}
public function gallery_image_update_order() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( "Session error !!", "classified-listing" ) );
return;
}
$listingId = intval( Functions::request( "listingId" ) );
- if ( ( !$listingId || !$listing = rtcl()->factory->get_listing( $listingId ) || !Functions::current_user_can( 'edit_' . rtcl()->post_type, $listingId ) ) || ( !is_user_logged_in() && !Functions::is_enable_post_for_unregister() ) ) {
+ if ( ( ! $listingId || ! $listing = rtcl()->factory->get_listing( $listingId ) || ! Functions::current_user_can( 'edit_' . rtcl()->post_type, $listingId ) ) || ( ! is_user_logged_in() && ! Functions::is_enable_post_for_unregister() ) ) {
wp_send_json_error( __( 'You do not have sufficient permissions to set.', 'classified-listing' ) );
return;
}
- $attachmentIds = !empty( $_POST["attachmentIds"] ) && is_array( $_POST["attachmentIds"] ) ? array_filter( array_map( 'absint', $_POST["attachmentIds"] ) ) : [];
+ $attachmentIds = ! empty( $_POST["attachmentIds"] ) && is_array( $_POST["attachmentIds"] ) ? array_filter( array_map( 'absint', $_POST["attachmentIds"] ) ) : [];
if ( empty( $attachmentIds ) ) {
wp_send_json_error( __( "Attachment ids not exist.", "classified-listing" ) );
@@ -634,7 +640,7 @@
foreach ( $attachmentIds as $index => $attachment_id ) {
wp_update_post( [
'ID' => $attachment_id,
- 'menu_order' => $index
+ 'menu_order' => $index,
] );
}
wp_send_json_success();
@@ -642,16 +648,16 @@
public function gallery_image_upload() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
- wp_send_json_error( esc_html__( "Session error !!", "classified-listing" ) );
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
+ wp_send_json_error( esc_html__( "Unauthorized access!", "classified-listing" ) );
+ }
- return;
+ if ( ! is_user_logged_in() ) {
+ wp_send_json_error( __( 'Registration required to upload listing image.', 'classified-listing' ) );
}
if ( empty( $_FILES['image'] ) ) {
wp_send_json_error( esc_html__( "Given file is empty to upload.", "classified-listing" ) );
-
- return;
}
Filters::beforeUpload();
@@ -664,8 +670,6 @@
if ( isset( $status['error'] ) ) {
Filters::afterUpload();
wp_send_json_error( $status['error'] );
-
- return;
}
// $filename should be the path to a file in the upload directory.
@@ -686,8 +690,8 @@
'post_content' => '',
'post_status' => 'inherit',
'meta_input' => [
- '_rtcl_attachment_type' => 'image'
- ]
+ '_rtcl_attachment_type' => 'image',
+ ],
];
// Create post if does not exist
@@ -701,7 +705,7 @@
'post_status' => Functions::get_temp_listing_status(),
'post_author' => wp_get_current_user()->ID,
'post_type' => rtcl()->post_type,
- 'comments_status' => 'closed'
+ 'comments_status' => 'closed',
] ) );
remove_filter( "post_type_link", "__return_empty_string" );
@@ -710,42 +714,42 @@
'post_parent' => $parent_post_id,
'fields' => 'ids',
'post_type' => 'attachment',
- 'posts_per_page' => -1,
+ 'posts_per_page' => - 1,
'post_status' => 'inherit',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
- 'relation' => 'OR',
- [
- 'key' => '_rtcl_attachment_type',
- 'value' => 'image',
- 'compare' => '='
- ],
- [
- 'key' => '_rtcl_attachment_type',
- 'compare' => 'NOT EXISTS'
- ]
- ]
+ 'relation' => 'OR',
+ [
+ 'key' => '_rtcl_attachment_type',
+ 'value' => 'image',
+ 'compare' => '=',
+ ],
+ [
+ 'key' => '_rtcl_attachment_type',
+ 'compare' => 'NOT EXISTS',
+ ],
+ ],
] );
}
// Insert the attachment.
$attach_id = wp_insert_attachment( $attachment, $filename, $parent_post_id );
- if ( !is_wp_error( $attach_id ) ) {
+ if ( ! is_wp_error( $attach_id ) ) {
wp_update_attachment_metadata( $attach_id, Functions::generate_attachment_metadata( $attach_id, $filename, Functions::get_image_sizes() ) );
- if ( !has_post_thumbnail( $parent_post_id ) ) {
+ if ( ! has_post_thumbnail( $parent_post_id ) ) {
set_post_thumbnail( $parent_post_id, $attach_id );
}
}
Filters::afterUpload();
- if ( !empty( $oldAttachmentIds ) ) {
+ if ( ! empty( $oldAttachmentIds ) ) {
$oldAttachmentIds[] = $attach_id;
foreach ( $oldAttachmentIds as $index => $attachment_id ) {
wp_update_post( [
'ID' => $attachment_id,
- 'menu_order' => $index
+ 'menu_order' => $index,
] );
}
}
@@ -753,15 +757,15 @@
}
public function get_attachment_details() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( 'Session error !!', 'classified-listing' ) );
return;
}
$attachment_id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
- $attachment = get_post( $attachment_id );
- if ( !$attachment ) {
+ $attachment = get_post( $attachment_id );
+ if ( ! $attachment ) {
wp_send_json_error( __( 'Attachment does not exist.', 'classified-listing' ) );
return;
@@ -775,29 +779,29 @@
return;
}
- if ( !Functions::current_user_can( 'edit_rtcl_listing', $listingId ) ) {
+ if ( ! Functions::current_user_can( 'edit_rtcl_listing', $listingId ) ) {
wp_send_json_error( __( 'Unauthorized access', 'classified-listing' ) );
return;
}
$attachmentUrl = wp_get_attachment_url( $attachment->ID );
- $file = $attachment->to_array();
- $file['guid'] = $attachmentUrl;
- $file['meta'] = wp_get_attachment_metadata( $attachment->ID );
+ $file = $attachment->to_array();
+ $file['guid'] = $attachmentUrl;
+ $file['meta'] = wp_get_attachment_metadata( $attachment->ID );
wp_send_json_success( $file );
}
public function update_attachment_details() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( 'Session error !!', 'classified-listing' ) );
return;
}
$attachment_id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
- $attachment = get_post( $attachment_id );
- if ( !$attachment ) {
+ $attachment = get_post( $attachment_id );
+ if ( ! $attachment ) {
wp_send_json_error( __( 'Attachment does not exist.', 'classified-listing' ) );
return;
@@ -811,7 +815,7 @@
return;
}
- if ( !Functions::current_user_can( 'edit_rtcl_listing', $listingId ) ) {
+ if ( ! Functions::current_user_can( 'edit_rtcl_listing', $listingId ) ) {
wp_send_json_error( __( 'Unauthorized access', 'classified-listing' ) );
return;
@@ -819,8 +823,8 @@
$updatedId = wp_update_post( [
'ID' => $attachment->ID,
- 'post_excerpt' => !empty( $_POST['data']['caption'] ) ? trim( sanitize_text_field( $_POST['data']['caption'] ) ) : '',
- 'post_content' => !empty( $_POST['data']['content'] ) ? trim( sanitize_text_field( $_POST['data']['content'] ) ) : '',
+ 'post_excerpt' => ! empty( $_POST['data']['caption'] ) ? trim( sanitize_text_field( $_POST['data']['caption'] ) ) : '',
+ 'post_content' => ! empty( $_POST['data']['content'] ) ? trim( sanitize_text_field( $_POST['data']['content'] ) ) : '',
] );
if ( is_wp_error( $updatedId ) ) {
@@ -828,13 +832,13 @@
return;
}
- $attachment = get_post( $updatedId, ARRAY_A );
+ $attachment = get_post( $updatedId, ARRAY_A );
$attachment['meta'] = wp_get_attachment_metadata( $updatedId );
wp_send_json_success( $attachment );
}
public function file_upload() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( 'Session error !!', 'classified-listing' ) );
return;
@@ -846,7 +850,7 @@
return;
}
- $form_id = !empty( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
+ $form_id = ! empty( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
if ( empty( $form_id ) ) {
wp_send_json_error( esc_html__( 'From id is empty to upload.', 'classified-listing' ) );
@@ -854,10 +858,10 @@
}
$repeater_uuid = Functions::request( 'repeater_uuid' );
- $field_uuid = Functions::request( 'field_uuid' );
+ $field_uuid = Functions::request( 'field_uuid' );
$repeaterIndex = Functions::request( 'repeater_index' );
- $repeater = null;
- $field = null;
+ $repeater = null;
+ $field = null;
if ( $repeater_uuid ) {
if ( empty( $repeater_uuid ) || empty( $field_uuid ) ) {
wp_send_json_error( esc_html__( 'Field id is empty to upload.', 'classified-listing' ) );
@@ -872,9 +876,9 @@
return;
}
- if ( !empty( $repeater['fields'] ) ) {
+ if ( ! empty( $repeater['fields'] ) ) {
foreach ( $repeater['fields'] as $_field ) {
- if ( !empty( $_field['uuid'] ) && $_field['uuid'] === $field_uuid ) {
+ if ( ! empty( $_field['uuid'] ) && $_field['uuid'] === $field_uuid ) {
$field = $_field;
break;
}
@@ -889,7 +893,6 @@
}
}
} else {
-
if ( empty( $field_uuid ) ) {
wp_send_json_error( esc_html__( 'Field id is empty to upload.', 'classified-listing' ) );
@@ -905,7 +908,7 @@
return;
}
- $fileMetaKey = !empty( $field['name'] ) ? $field['name'] : null;
+ $fileMetaKey = ! empty( $field['name'] ) ? $field['name'] : null;
if ( empty( $fileMetaKey ) ) {
wp_send_json_error( esc_html__( 'Field name is empty.', 'classified-listing' ) );
@@ -918,9 +921,9 @@
if ( $listing_id ) {
if ( $repeater ) {
$repeaterValue = get_post_meta( $listing_id, $repeater['name'], true );
- $repeaterValue = !is_array( $repeaterValue ) || empty( $repeaterValue ) ? [] : $repeaterValue;
- if ( !empty( $repeaterValue[$repeaterIndex][$fileMetaKey] ) && is_array( $repeaterValue[$repeaterIndex][$fileMetaKey] ) ) {
- $attachment_ids = array_map( 'absint', $repeaterValue[$repeaterIndex][$fileMetaKey] );
+ $repeaterValue = ! is_array( $repeaterValue ) || empty( $repeaterValue ) ? [] : $repeaterValue;
+ if ( ! empty( $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] ) && is_array( $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] ) ) {
+ $attachment_ids = array_map( 'absint', $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] );
} else {
$attachment_ids = [];
}
@@ -928,28 +931,28 @@
$attachment_ids = get_post_meta( $listing_id, $fileMetaKey, true );
}
- $attachment_ids = !empty( $attachment_ids ) && is_array( $attachment_ids ) ? $attachment_ids : [];
- if ( !empty( $attachment_ids ) ) {
+ $attachment_ids = ! empty( $attachment_ids ) && is_array( $attachment_ids ) ? $attachment_ids : [];
+ if ( ! empty( $attachment_ids ) ) {
$check_attachment_ids = get_children( [
'fields' => 'ids',
'post_parent' => $listing_id,
'post_type' => 'attachment',
'post__in' => $attachment_ids,
'orderby' => 'post__in',
- 'posts_per_page' => -1,
+ 'posts_per_page' => - 1,
'post_status' => 'inherit',
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
- [
- 'key' => '_rtcl_attachment_type',
- 'value' => 'file',
- 'compare' => '='
- ]
- ]
+ [
+ 'key' => '_rtcl_attachment_type',
+ 'value' => 'file',
+ 'compare' => '=',
+ ],
+ ],
] );
if ( $attachment_ids !== $check_attachment_ids ) {
if ( $repeater ) {
- if ( !empty( $repeaterValue ) && is_array( $repeaterValue ) ) {
- $repeaterValue[$repeaterIndex][$fileMetaKey] = $check_attachment_ids;
+ if ( ! empty( $repeaterValue ) && is_array( $repeaterValue ) ) {
+ $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] = $check_attachment_ids;
update_post_meta( $listing_id, $repeater['name'], $repeaterValue );
}
} else {
@@ -962,10 +965,10 @@
$attachment_ids = [];
}
- if ( !empty( $field['validation']['max_file_count']['value'] ) ) {
+ if ( ! empty( $field['validation']['max_file_count']['value'] ) ) {
$maxFileCount = absint( $field['validation']['max_file_count']['value'] );
if ( $maxFileCount && count( $attachment_ids ) >= $maxFileCount ) {
- $message = !empty( $field['validation']['max_file_count']['message'] ) ? str_replace( '{value}', $maxFileCount, $field['validation']['max_file_count']['message'] ) : esc_html__( 'Your file upload limit is over.', 'classified-listing' );
+ $message = ! empty( $field['validation']['max_file_count']['message'] ) ? str_replace( '{value}', $maxFileCount, $field['validation']['max_file_count']['message'] ) : esc_html__( 'Your file upload limit is over.', 'classified-listing' );
wp_send_json_error( $message );
return;
@@ -1006,13 +1009,12 @@
'post_status' => 'inherit',
'comments_status' => 'closed',
'meta_input' => [
- '_rtcl_attachment_type' => 'file'
- ]
+ '_rtcl_attachment_type' => 'file',
+ ],
];
// Create post if does not exist
if ( $listing_id < 1 ) {
-
add_filter( 'post_type_link', '__return_empty_string' );
$listing_id = wp_insert_post( apply_filters( 'rtcl_insert_temp_post_for_file', [
@@ -1021,7 +1023,7 @@
'post_status' => Functions::get_temp_listing_status(),
'post_author' => wp_get_current_user()->ID,
'post_type' => rtcl()->post_type,
- 'comments_status' => 'closed'
+ 'comments_status' => 'closed',
] ) );
remove_filter( 'post_type_link', '__return_empty_string' );
@@ -1029,13 +1031,13 @@
// Insert the attachment.
$attach_id = wp_insert_attachment( $attachment, $filename, $listing_id );
- if ( !is_wp_error( $attach_id ) ) {
+ if ( ! is_wp_error( $attach_id ) ) {
wp_update_attachment_metadata( $attach_id, Functions::generate_attachment_metadata( $attach_id, $filename, Functions::get_default_image_sizes() ) );
}
$attachment_ids[] = $attach_id;
if ( $repeater ) {
- $repeaterValue[$repeaterIndex][$fileMetaKey] = $attachment_ids;
+ $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] = $attachment_ids;
update_post_meta( $listing_id, $repeater['name'], $repeaterValue );
} else {
update_post_meta( $listing_id, $fileMetaKey, $attachment_ids );
@@ -1047,23 +1049,23 @@
}
public function file_delete() {
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( 'Session error !!', 'classified-listing' ) );
return;
}
- $form_id = !empty( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
+ $form_id = ! empty( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
if ( empty( $form_id ) ) {
wp_send_json_error( esc_html__( 'From id is empty to delete.', 'classified-listing' ) );
return;
}
$repeater_uuid = Functions::request( 'repeater_uuid' );
- $field_uuid = Functions::request( 'field_uuid' );
+ $field_uuid = Functions::request( 'field_uuid' );
$repeaterIndex = Functions::request( 'repeater_index' );
- $repeater = null;
- $field = null;
+ $repeater = null;
+ $field = null;
if ( $repeater_uuid ) {
if ( empty( $repeater_uuid ) || empty( $field_uuid ) ) {
@@ -1079,9 +1081,9 @@
return;
}
- if ( !empty( $repeater['fields'] ) ) {
+ if ( ! empty( $repeater['fields'] ) ) {
foreach ( $repeater['fields'] as $_field ) {
- if ( !empty( $_field['uuid'] ) && $_field['uuid'] === $field_uuid ) {
+ if ( ! empty( $_field['uuid'] ) && $_field['uuid'] === $field_uuid ) {
$field = $_field;
break;
}
@@ -1111,7 +1113,7 @@
return;
}
- $fileMetaKey = !empty( $field['name'] ) ? $field['name'] : null;
+ $fileMetaKey = ! empty( $field['name'] ) ? $field['name'] : null;
if ( empty( $fileMetaKey ) ) {
wp_send_json_error( esc_html__( 'Field name is empty.', 'classified-listing' ) );
@@ -1120,16 +1122,16 @@
}
$attach_id = isset( $_POST['attach_id'] ) ? absint( $_POST['attach_id'] ) : 0;
- $attach = get_post( $attach_id );
- if ( !$attach ) {
+ $attach = get_post( $attach_id );
+ if ( ! $attach ) {
wp_send_json_error( __( 'Attachment does not exist.', 'classified-listing' ) );
return;
}
$listing_id = absint( Functions::request( "listingId" ) );
- $listing = rtcl()->factory->get_listing( $listing_id );
+ $listing = rtcl()->factory->get_listing( $listing_id );
- if ( $listing && !Functions::current_user_can( 'edit_' . rtcl()->post_type, $listing_id ) ) {
+ if ( $listing && ! Functions::current_user_can( 'edit_' . rtcl()->post_type, $listing_id ) ) {
wp_send_json_error( apply_filters( 'rtcl_fb_not_found_error_message', __( 'You do not have sufficient permissions to access this page.', 'classified-listing' ), $_REQUEST, 'permission_error' ) );
return;
@@ -1143,37 +1145,37 @@
if ( $repeater ) {
$repeaterValue = get_post_meta( $listing_id, $repeater['name'], true );
- $repeaterValue = !is_array( $repeaterValue ) || empty( $repeaterValue ) ? [] : $repeaterValue;
- if ( !empty( $repeaterValue[$repeaterIndex][$fileMetaKey] ) && is_array( $repeaterValue[$repeaterIndex][$fileMetaKey] ) ) {
- $attachment_ids = array_map( 'absint', $repeaterValue[$repeaterIndex][$fileMetaKey] );
+ $repeaterValue = ! is_array( $repeaterValue ) || empty( $repeaterValue ) ? [] : $repeaterValue;
+ if ( ! empty( $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] ) && is_array( $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] ) ) {
+ $attachment_ids = array_map( 'absint', $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] );
} else {
$attachment_ids = [];
}
} else {
$attachment_ids = get_post_meta( $listing_id, $fileMetaKey, true );
}
- $attachment_ids = !empty( $attachment_ids ) && is_array( $attachment_ids ) ? $attachment_ids : [];
- if ( !empty( $attachment_ids ) ) {
+ $attachment_ids = ! empty( $attachment_ids ) && is_array( $attachment_ids ) ? $attachment_ids : [];
+ if ( ! empty( $attachment_ids ) ) {
$check_attachment_ids = get_children( [
'fields' => 'ids',
'post_parent' => $listing_id,
'post_type' => 'attachment',
'post__in' => $attachment_ids,
'orderby' => 'post__in',
- 'posts_per_page' => -1,
+ 'posts_per_page' => - 1,
'post_status' => 'inherit',
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
- [
- 'key' => '_rtcl_attachment_type',
- 'value' => 'file',
- 'compare' => '='
- ]
- ]
+ [
+ 'key' => '_rtcl_attachment_type',
+ 'value' => 'file',
+ 'compare' => '=',
+ ],
+ ],
] );
if ( $attachment_ids !== $check_attachment_ids ) {
if ( $repeater ) {
- if ( !empty( $repeaterValue ) && is_array( $repeaterValue ) ) {
- $repeaterValue[$repeaterIndex][$fileMetaKey] = $check_attachment_ids;
+ if ( ! empty( $repeaterValue ) && is_array( $repeaterValue ) ) {
+ $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] = $check_attachment_ids;
update_post_meta( $listing_id, $repeater['name'], $repeaterValue );
}
} else {
@@ -1183,13 +1185,13 @@
}
}
- if ( empty( $attachment_ids ) || !in_array( $attach->ID, $attachment_ids ) ) {
+ if ( empty( $attachment_ids ) || ! in_array( $attach->ID, $attachment_ids ) ) {
wp_send_json_error( __( 'No file found to delete.', 'classified-listing' ) );
return;
}
- if ( !wp_delete_attachment( $attach_id ) ) {
+ if ( ! wp_delete_attachment( $attach_id ) ) {
wp_send_json_error( __( 'File could not be deleted.', 'classified-listing' ) );
return;
@@ -1198,12 +1200,12 @@
$attachment_ids = array_filter( $attachment_ids,
function ( $item_id ) use ( $attach ) {
return $item_id !== $attach->ID;
- }
+ },
);
if ( $repeater ) {
- if ( !empty( $repeaterValue ) && is_array( $repeaterValue ) ) {
- $repeaterValue[$repeaterIndex][$fileMetaKey] = $attachment_ids;
+ if ( ! empty( $repeaterValue ) && is_array( $repeaterValue ) ) {
+ $repeaterValue[ $repeaterIndex ][ $fileMetaKey ] = $attachment_ids;
update_post_meta( $listing_id, $repeater['name'], $repeaterValue );
}
} else {
@@ -1214,62 +1216,60 @@
}
public function get_category(): void {
-
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( 'Session error !!', 'classified-listing' ) );
return;
}
- $parent_id = !empty( $_POST['parentId'] ) ? absint( $_POST['parentId'] ) : 0;
- $excludeIds = !empty( $_POST['exclude'] ) && is_array( $_POST['exclude'] ) ? array_map( 'absint', $_POST['exclude'] ) : [];
- $includeIds = !empty( $_POST['include'] ) && is_array( $_POST['include'] ) ? array_map( 'absint', $_POST['include'] ) : [];
+ $parent_id = ! empty( $_POST['parentId'] ) ? absint( $_POST['parentId'] ) : 0;
+ $excludeIds = ! empty( $_POST['exclude'] ) && is_array( $_POST['exclude'] ) ? array_map( 'absint', $_POST['exclude'] ) : [];
+ $includeIds = ! empty( $_POST['include'] ) && is_array( $_POST['include'] ) ? array_map( 'absint', $_POST['include'] ) : [];
$listingType = Functions::request( 'listingType' );
- $data = [];
- if ( !empty( $listingType ) ) {
+ $data = [];
+ if ( ! empty( $listingType ) ) {
$data['type'] = $listingType;
}
- if ( !empty( $excludeIds ) ) {
+ if ( ! empty( $excludeIds ) ) {
$data['exclude'] = $excludeIds;
}
- if ( !empty( $includeIds ) ) {
+ if ( ! empty( $includeIds ) ) {
$data['include'] = $includeIds;
}
$categories = Functions::get_sub_terms( rtcl()->category, $parent_id, $data );
- $data = [
+ $data = [
'success' => true,
'message' => [],
- 'cat_id' => $parent_id
+ 'cat_id' => $parent_id,
];
- $response = apply_filters( 'rtcl_ajax_category_selection_before_post', $data );
- if ( empty( $response['success'] ) && !empty( $response['message'] ) ) {
+ $response = apply_filters( 'rtcl_ajax_category_selection_before_post', $data );
+ if ( empty( $response['success'] ) && ! empty( $response['message'] ) ) {
wp_send_json_error( $response['message'][0] );
return;
}
wp_send_json_success( [
- 'data' => $categories
+ 'data' => $categories,
] );
}
public function get_filtered_categories(): void {
-
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( "Session error !!", "classified-listing" ) );
return;
}
- $ids = !empty( $_POST['ids'] ) && is_array( $_POST['ids'] ) ? array_map( 'absint', $_POST['ids'] ) : [];
- $parentId = isset( $_POST['parentId'] ) ? ( $_POST['parentId'] == 0 ? 0 : absint( $_POST['parentId'] ) ) : '';
- $excludeIds = !empty( $_POST['excludeIds'] ) && is_array( $_POST['excludeIds'] ) ? array_map( 'absint', $_POST['excludeIds'] ) : [];
- $q = !empty( $_POST['q'] ) ? sanitize_text_field( $_POST['q'] ) : '';
- $orderby = strtolower( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_orderby', 'name' ) );
- $order = strtoupper( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_order', 'DESC' ) );
- $number = isset( $_POST['number'] ) ? absint( $_POST['number'] ) : false;
- $args = [
+ $ids = ! empty( $_POST['ids'] ) && is_array( $_POST['ids'] ) ? array_map( 'absint', $_POST['ids'] ) : [];
+ $parentId = isset( $_POST['parentId'] ) ? ( $_POST['parentId'] == 0 ? 0 : absint( $_POST['parentId'] ) ) : '';
+ $excludeIds = ! empty( $_POST['excludeIds'] ) && is_array( $_POST['excludeIds'] ) ? array_map( 'absint', $_POST['excludeIds'] ) : [];
+ $q = ! empty( $_POST['q'] ) ? sanitize_text_field( $_POST['q'] ) : '';
+ $orderby = strtolower( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_orderby', 'name' ) );
+ $order = strtoupper( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_order', 'DESC' ) );
+ $number = isset( $_POST['number'] ) ? absint( $_POST['number'] ) : false;
+ $args = [
'hide_empty' => false,
'orderby' => $orderby,
'order' => ( 'DESC' === $order ) ? 'DESC' : 'ASC',
@@ -1280,7 +1280,7 @@
'search' => $q,
'include' => $ids,
'exclude' => $excludeIds,
- 'number' => $number
+ 'number' => $number,
// phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
];
$listingType = Functions::request( 'listingType' );
@@ -1288,18 +1288,18 @@
$args['meta_query'] = [
[
'key' => '_rtcl_types',
- 'value' => $listingType
- ]
+ 'value' => $listingType,
+ ],
];
}
- $data = [];
+ $data = [];
$categories = get_terms( $args );
- if ( !is_wp_error( $categories ) && !empty( $categories ) ) {
+ if ( ! is_wp_error( $categories ) && ! empty( $categories ) ) {
foreach ( $categories as $term ) {
$image_id = get_term_meta( $term->term_id, '_rtcl_image', true );
if ( $image_id ) {
- $image_attributes = wp_get_attachment_image_src( (int)$image_id, 'medium' );
- if ( !empty( $image_attributes[0] ) ) {
+ $image_attributes = wp_get_attachment_image_src( (int) $image_id, 'medium' );
+ if ( ! empty( $image_attributes[0] ) ) {
$term->img_url = $image_attributes[0];
}
}
@@ -1311,40 +1311,39 @@
}
}
wp_send_json_success( [
- 'data' => $data
+ 'data' => $data,
] );
-
}
public function get_terms_callback() {
-
- if ( !wp_verify_nonce( isset( $_REQUEST[rtcl()->nonceId] ) ? $_REQUEST[rtcl()->nonceId] : null, rtcl()->nonceText ) ) {
+ if ( ! wp_verify_nonce( isset( $_REQUEST[ rtcl()->nonceId ] ) ? $_REQUEST[ rtcl()->nonceId ] : null, rtcl()->nonceText ) ) {
wp_send_json_error( esc_html__( "Session error !!", "classified-listing" ) );
return;
}
- $includeIds = !empty( $_POST['includeIds'] ) && is_array( $_POST['includeIds'] ) ? array_map( 'absint', $_POST['includeIds'] ) : [];
- if ( empty( $includeIds ) && !empty( $_POST['ids'] ) ) {
+ $includeIds = ! empty( $_POST['includeIds'] ) && is_array( $_POST['includeIds'] ) ? array_map( 'absint', $_POST['includeIds'] ) : [];
+ if ( empty( $includeIds ) && ! empty( $_POST['ids'] ) ) {
$includeIds = is_array( $_POST['ids'] ) ? array_map( 'absint', $_POST['ids'] ) : [];
}
- $parentId = isset( $_POST['parentId'] ) ? ( $_POST['parentId'] == 0 ? 0 : absint( $_POST['parentId'] ) ) : '';
- $excludeIds = !empty( $_POST['excludeIds'] ) && is_array( $_POST['excludeIds'] ) ? array_map( 'absint', $_POST['excludeIds'] ) : [];
- $q = !empty( $_POST['q'] ) ? sanitize_text_field( $_POST['q'] ) : '';
- $withHasChildren = !empty( $_POST['withHasChildren'] );
- $orderby = strtolower( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_orderby', 'name' ) );
- $order = strtoupper( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_order', 'DESC' ) );
- $taxonomy = isset( $_POST['taxonomy'] ) && in_array( $_POST['taxonomy'], [
+ $parentId = isset( $_POST['parentId'] ) ? ( $_POST['parentId'] == 0 ? 0 : absint( $_POST['parentId'] ) ) : '';
+ $excludeIds = ! empty( $_POST['excludeIds'] ) && is_array( $_POST['excludeIds'] ) ? array_map( 'absint', $_POST['excludeIds'] ) : [];
+ $q = ! empty( $_POST['q'] ) ? sanitize_text_field( $_POST['q'] ) : '';
+ $withHasChildren = ! empty( $_POST['withHasChildren'] );
+ $orderby = strtolower( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_orderby', 'name' ) );
+ $order = strtoupper( Functions::get_option_item( 'rtcl_archive_listing_settings', 'taxonomy_order', 'DESC' ) );
+ $taxonomy = isset( $_POST['taxonomy'] )
+ && in_array( $_POST['taxonomy'], [
rtcl()->tag,
rtcl()->category,
- rtcl()->location
+ rtcl()->location,
] ) ? $_POST['taxonomy'] : rtcl()->category;
- $number = isset( $_POST['number'] ) ? absint( $_POST['number'] ) : 0;
+ $number = isset( $_POST['number'] ) ? absint( $_POST['number'] ) : 0;
if ( $parentId === '' && $q ) {
- if ( !empty( $excludeIds ) ) {
+ if ( !